/********************************************************
PROJECT NAME: DIGITAL TIMER *
DESCRIPTION: ADJUST THE TIME BY PRESS THE 4X4 KEYS *
HAB_RDWARE: 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
********************************************************/
PORT EQU P1 ;数据接口
B_WR EQU P2.0
B_RD EQU P2.1
B_CS EQU P2.2
B_FLAG BIT 00H
R_CONVER EQU 30H
R_TEMP EQU 31H
R_VALUEH EQU 32H ;高位
R_VALUEL EQU 33H
R_VALUEM EQU 34H ;低位
R_DISP0 EQU 35H
R_DISP1 EQU 36H
R_DISP2 EQU 37H
R_DISP3 EQU 38H
R_DATA1 EQU 39H ;要显示数据临时存放区
R_DS_COUNT EQU 3AH ;显示位选择
R_DEL0 EQU 3BH
R_DEL1 EQU 3CH
;--------------------------
ORG 0000H
AJMP L_MAIN
ORG 0003H
;lJMP F_INT0
RETI
ORG 000BH
lJMP F_TIMER0
ORG 0013H
RETI
ORG 001BH
RETI
/***************************
FUCTION:MAIN
PROGRAMER:ANDY
VER:A
****************************/
ORG 0040H
L_MAIN:
MOV TMOD,#11H
MOV TH0,#HIGH(65536-55536)
MOV TL0,#LOW(65536-55536)
SETB EA
SETB ET0
SETB TR0
;SETB EX0
SETB B_CS
SETB B_WR
SETB B_RD
MOV SP,#70H
MOV R0,#35H
CLR B_FLAG
MOV R_DATA1,#00H
MOV R_VALUEH,#00H
MOV R_VALUEM,#00H
MOV R_VALUEL,#00H
MOV R_DISP0,#00H
MOV R_DISP1,#00H
MOV R_DISP2,#00H
MOV R_DISP3,#00H
MOV R3,#0FFH
MOV R6,#4
MOV R0,#32H
L_LOOP: LCALL F_START
LCALL F_ADUST
LCALL F_DELAY
AJMP L_LOOP
/***************************
FUCTION:ADUST
****************************/
F_ADUST:
MOV A,R_CONVER
ANL A,#0F0H ;屏蔽低4位
SWAP A ;高低4位交换
MOV B,#2
MUL AB
MOV R7,A
MOV DPTR,#TAB_HIGHT
MOVC A,@A+DPTR ;查表得到百位
MOV R_VALUEH,A
MOV A,R7
INC A
MOVC A,@A+DPTR ;
MOV R_VALUEM,A
MOV A,R_CONVER
ANL A,#0FH
MOV DPTR,#TAB_LOW
MOVC A,@A+DPTR
ADD A,R_VALUEM
DA A
MOV R_VALUEL,A
MOV A,R_VALUEH
ADDC A,#00
MOV R_VALUEH,A
MOV A,R_VALUEL
ANL A,#0FH
MOV R_DISP0,A
MOV A,R_VALUEL
ANL A,#0F0H
SWAP A
MOV R_DISP1,A
MOV A,R_VALUEH
ANL A,#0FH
MOV R_DISP2,A
MOV A,R_VALUEH
ANL A,#0F0H
SWAP A
MOV R_DISP3,A
RET
;******************************
;FUNCUTION:START CONVERT
;
;
;******************************
F_START:
CLR B_CS ;启动
NOP
NOP
NOP
CLR B_WR
NOP
NOP
NOP
NOP
NOP
NOP
SETB B_WR
NOP
NOP
SETB B_CS
NOP
NOP
NOP
LCALL F_DELAY ;等待
LCALL F_DELAY
LCALL F_DELAY
LCALL F_DELAY
CLR B_CS ;读取转换后的数字量
NOP
NOP
NOP
CLR B_RD
NOP
NOP
NOP
NOP
NOP
NOP
MOV R_CONVER,PORT
MOV P3,R_CONVER
SETB B_RD
SETB B_CS
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,@R0 ;数据
ANL A,#0FH
MOV R_DATA1,A
INC R3 ;位
INC R0
MOV A,R3
ANL A,#0FH
SWAP A
ORL A,R_DATA1
MOV P0,A
DJNZ R6,TT1
MOV R3,#0FFH
MOV R6,#4
MOV R0,#35H
TT1: POP PSW
POP ACC
RETI
/***************************************
FUCTION:THE ADC SERVICE
****************************************/
/*F_INT0:
CLR B_CS
NOP
NOP
NOP
CLR B_RD
NOP
NOP
NOP
NOP
NOP
NOP
MOV R_CONVER,PORT
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
SETB B_RD
NOP
NOP
NOP
SETB B_CS
SETB B_FLAG
RETI
*/
;*****************************
;FUCITON:DELAY 20MS
;
;******************************
F_DELAY:
MOV R_DEL0,#200
L_CONTINU:
MOV R_DEL1,#248
DJNZ R_DEL1,$
DJNZ R_DEL0,L_CONTINU
RET
;******************************
;FUCTION:TABLEH & TABLEL
;
;******************************
TAB_LOW:
DB 00H, 02H, 04H, 06H, 08H
DB 10H, 12H, 14H, 16H, 18H
DB 20H, 22H, 24H, 28H, 30H
DB 32H
TAB_HIGHT:
DW 0000H, 0032H, 0064H, 0096H, 0128H
DW 0160H, 0192H, 0224H, 0256H, 0288H
DW 0320H, 0352H, 0384H, 0416H, 0448H
DW 0480H
END
文章评论(0条评论)
登录后参与讨论