/********************************************************
PROJECT NAME: DIGITAL TIMER *
DESCRIPTION: ADJUST THE TIME BY PRESS THE 4X4 KEYS *
HARDWARE: P0--Digitron&FLASH, P2--4X4KEYS
P3.2--LED SHOWS THE KEY IS PRESSING
P3.7--LED SHOWS THE KEY WAS RELEASE *
PROGRAMMER: andy *
DATA: 2009-06-16 21:50 *
COPYRIGHT: andy's design-hourse All Right Reserved. *
QQ: 68421963
********************************************************/
B_HASKEY BIT 00H
B_NEWKEY BIT 01H
B_DEBOUCE BIT 02H
FLASH BIT 03H ;每秒闪烁一次
B_PRESS BIT P3.2 ;按下键
B_FREE BIT P3.7 ;松开
PORT EQU P2 ;4X4矩阵键盘接口
R_KEY_VALUE EQU 30H
R_TEMP0 EQU 31H ;延时单元
R_TEMP1 EQU 32H
R_DATA1 EQU 33H ;要显示数据临时存放区
R_DS_COUNT EQU 34H ;显示位选择
MS_50 EQU 35H
SECOND EQU 36H ;秒
MINUT EQU 37H ;分
HOUR EQU 38H ;时
SEL_BIT EQU 39H ;位选
SECONDL EQU 40H ;秒低8位
SECONDH EQU 41H
MINUTL EQU 42H
MINUTH EQU 43H
HOURL EQU 44H
HOURH EQU 45H
FLASH_COUNT EQU 46H
ORG 0000H
AJMP L_MAIN
ORG 0003H
RETI
ORG 000BH
AJMP F_TIMER0
ORG 0013H
RETI
ORG 001BH
AJMP F_TIMER1
/***************************
FUCTION:MAIN
PROGRAMER:ANDY
VER:A
****************************/
ORG 0040H
L_MAIN:MOV TMOD,#11H
MOV TH0,#HIGH(65536-55536)
MOV TL0,#LOW(65536-55536)
MOV TH1,#HIGH(65536-45747)
MOV TL1,#LOW(65536-45747)
SETB EA
SETB ET0
SETB ET1
SETB TR1
SETB TR0
MOV SP,#70H
MOV R0,#40H
MOV FLASH_COUNT,#0
MOV MS_50,#0
MOV MINUT ,#0
MOV SECOND,#0
MOV HOUR,#0
MOV HOURH,#0
MOV HOURL,#0
MOV R_DATA1,#00H
MOV R_DS_COUNT,#6 ;记数,显示位控制
MOV R3,#0FFH
SETB FLASH
L_LOOP:
LCALL F_GETKEY ;按键检测
L_ADST:
AJMP L_LOOP
;******************************
;FUNCUTION:GET THE KEY'S VALUE
; AND CHANGE THE TIME
;
;
;******************************
F_GETKEY:
LCALL F_DELAY
LCALL F_DELAY
JB B_DEBOUCE,L_DEBOUCE ;DEBOUCE FLAG SERVICE
MOV PORT,#0F0H
MOV A,PORT
CJNE A,#0F0H,L_JUDGE0
JB B_HASKEY,L_RELEASE
AJMP L_NOKEY ;NO KEY
L_JUDGE0:JB B_HASKEY,L_OLDKEY
SETB B_DEBOUCE
LCALL F_DELAY
AA: RET
;*****************************
;
;FUNCUTION:GET THE KEY VALUE AND SET THE FLAG
;
;*****************************
L_DEBOUCE:LCALL F_KEYSCAN
CLR B_PRESS
SETB B_FREE
CLR B_DEBOUCE
SETB B_NEWKEY
SETB B_HASKEY
AJMP AA
;*****************************
;
;FUCTION:NOKEY
;
;*****************************
L_NOKEY:CLR B_NEWKEY
CLR B_DEBOUCE
CLR B_HASKEY
AJMP AA
;****************************
;FUCTION:OLDKEY
;****************************
L_OLDKEY:CLR B_NEWKEY
AJMP AA
;*****************************
;
;FUCTION:KEY RELEASE
;
;*****************************
L_RELEASE: CLR B_FREE
SETB B_PRESS
CLR B_NEWKEY
CLR B_DEBOUCE
CLR B_HASKEY
LCALL F_DELAY
AJMP AA
;**********************************
;
;FUNCTION:DETECT THE KEYS
;DESCRIB:THE KEY CONNECT TO P2 PORT
;**********************************
F_KEYSCAN:
MOV PORT,#0FH ;行检测
MOV A,PORT;#0EH;PORT;
CJNE A,#0FH,L_PRESS
AJMP KEY_SCAN_RET
L_PRESS: LCALL F_DELAY
MOV PORT,#0FH
MOV A,PORT;#0EH;PORT
CJNE A,#0FH,L_SCAN
AJMP KEY_SCAN_RET
L_SCAN: MOV R6,#0FFH
KEY_LOOP: INC R6
RRC A
JC KEY_LOOP
MOV PORT,#0F0H
MOV A,PORT;#0E0H;PORT
CJNE A,#0F0H,L_BOUCE
AJMP KEY_SCAN_RET
L_BOUCE: MOV PORT,#0F0H
MOV A,PORT;#0E0H;PORT
CJNE A,#0F0H,L_SCAN1
AJMP KEY_SCAN_RET
L_SCAN1:
MOV R7,#0FFH ;列检测
L_KEY_LOOP1:INC R7
RLC A
JC L_KEY_LOOP1
MOV A,R6
MOV B,#4H
MUL AB
ADD A,R7
MOV R7,A
CJNE R7,#0,L_CMP0
MOV A,MINUT
CJNE A,#59,L_INC_MIN
MOV MINUT,#0
AJMP L_CMP0
L_INC_MIN: INC MINUT
L_CMP0:CJNE R7,#1,L_CMP1 ;调整时间
MOV A,MINUT
CJNE A,#00,L_DEC_MIN
MOV MINUT,#59
AJMP L_CMP1
L_DEC_MIN:DEC MINUT
L_CMP1:CJNE R7,#2,L_CMP2
MOV A,HOUR
CJNE A,#23,L_INC_HOUR
MOV HOUR,#0
AJMP L_CMP2
L_INC_HOUR:INC HOUR
L_CMP2:CJNE R7,#3,L_CMP3
MOV A,HOUR
CJNE A,#0,L_DEC_HOUR
MOV HOUR,#23
AJMP L_CMP3
L_DEC_HOUR:DEC HOUR
KEY_SCAN_RET:RET
;*********************************************************
;FUCOTION :INTERRUPT FOR TIMER0.DISPLAY THE TIME NOW
;
;*********************************************************
F_TIMER0:PUSH ACC
PUSH PSW
CLR TR0
MOV TH0,#HIGH(65536-1000)
MOV TL0,#LOW(65536-1000)
SETB TR0
MOV A,SECOND
MOV B,#10
DIV AB
MOV SECONDH,A
MOV SECONDL,B
MOV A,MINUT
MOV B,#10
DIV AB
MOV MINUTH,A
MOV MINUTL,B
MOV A,HOUR
MOV B,#10
DIV AB
MOV HOURH,A
MOV HOURL,B
INC R3 ;采用138译码,接P0.4--p0.6位
MOV A,@R0 ;采用74LS47做LED数码管译码,接P0.0-P0.3
ANL A,#0FH
MOV R_DATA1,A
MOV A,R3
ANL A,#0FH
SWAP A
ORL A,R_DATA1
MOV C,FLASH ;显示闪烁,FLASH每半秒取反一次,低电平有效,接P0.7
MOV ACC.7,C
MOV P0,A
INC R0
DJNZ R_DS_COUNT,TT1
MOV R3,#0FFH
MOV R_DS_COUNT,#6
MOV R0,#40H
TT1: POP PSW
POP ACC
RETI
/***************************************
FUCTION:THE TIME COUNT
****************************************/
F_TIMER1: MOV TH1,#HIGH(65536-45747)
MOV TL1,#LOW(65536-45747)
PUSH ACC
PUSH PSW
CLR TR1
SETB TR1
INC MS_50
INC FLASH_COUNT
MOV A,FLASH_COUNT
CJNE A,#10,L_INC0
CPL FLASH ;闪动标志
MOV FLASH_COUNT,#0
L_INC0: MOV A,MS_50
CJNE A,#20,L_INC1
MOV MS_50,#0
INC SECOND
MOV A,SECOND
CJNE A,#60,L_INC1
MOV SECOND,#0
INC MINUT
MOV A,MINUT
CJNE A,#60,L_INC1
MOV MINUT,#0
INC HOUR
MOV A,HOUR
CJNE A,#24,L_INC1
MOV HOUR,#0
L_INC1:
POP PSW
POP ACC
RETI
;*****************************
;FUCITON:DELAY 20MS
;
;******************************
F_DELAY:
MOV R_TEMP0,#60
L_CONTINU:MOV R_TEMP1,#248
DJNZ R_TEMP1,$
DJNZ R_TEMP0,L_CONTINU
RET
END
用户1116257 2009-6-16 21:48
用户1078068 2009-6-12 21:51