俺是菜鸟,发帖不多.(这次我是真的经过思考才发滴)还希望前辈都耐心看完.看看我的思路多多帮助.今年大二,看了好几天书了,有个很着急的问题想问问大家,看了这个视频,挺好玩的.就想做一个时钟.http://v.youku.com/v_show/id_XMTYzMDExNjk2.html今天忙了一天了,时钟可以正常走动,可是我想调时间啊.就用定时中断每隔10ms查按键,把调时间放在中断中处理。调时流程图也能写出来,我把它们分成好几个子程序.这时问题出来了,我只要一加中断调时就会乱码。嵌套太多,我不会保护和参数传递了。纠结啊,一直忙到现在.下面是我的程序,参数该怎么传递,什么时候该保护啊,我脑子都混了.中断中我只加了一个调秒. 希望大家给我个意见(主要是参数传递,怎样把子程序连接起来),这次真的崩溃了.
RS BIT P2.0
RW BIT P2.1
E BIT P2.2
COM EQU 30H
DATE EQU 31H
SEC EQU 40H
MIN EQU 41H
HOUR EQU 42H
DAY EQU 43H
MONTH EQU 44H
YEAR EQU 45H
WEEK EQU 46H
SCLK BIT P1.0
RST BIT P1.2
IO BIT P1.1
KEY1 BIT P1.5 //切换时分秒年月日
KEY2 BIT P1.6 //时分秒年月日+键
KEY3 BIT P1.7 //时分秒年月日-键
ORG 0000H
AJMP MAIN
ORG 000BH
ORG 0030H
MAIN: MOV SP,#35H
MOV TMOD,#01H
MOV TH0,#0D8H
MOV TL0,#0F0H
MOV IE,#82H
SETB TR0
LCALL INIT_1602
SJXS: LCALL GET_1302
LCALL DISPLAY
AJMP SJXS
READ_1302:MOV R5,#8
CLR RST
CLR SCLK
SETB RST
RE1: RRC A
MOV IO,C
SETB SCLK
CLR SCLK
DJNZ R5,RE1
NOP
MOV R5,#8
RE2: MOV C,IO
RRC A
SETB SCLK
CLR SCLK
DJNZ R5,RE2
clr RST
RET
WRITE_1302:MOV R4,#2
WRIT2: MOV R5,#8
CLR RST
CLR SCLK
SETB RST
WRIT1: RRC A
MOV IO,C
SETB SCLK
CLR SCLK
DJNZ R5,WRIT1
MOV A,B
DJNZ R4,WRIT2
CLR RST
RET
SET_1302:MOV A,#8EH
LCALL WRITE_1302
MOV B,#00H
LCALL WRITE_1302
MOV A,#90H
LCALL WRITE_1302
MOV B,#0AAH
LCALL WRITE_1302
MOV A,#80H
LCALL WRITE_1302
MOV B,SEC
LCALL WRITE_1302
MOV A,#82H
LCALL WRITE_1302
MOV B,MIN
LCALL WRITE_1302
MOV A,#84H
LCALL WRITE_1302
MOV B,HOUR
LCALL WRITE_1302
MOV A,#86H
LCALL WRITE_1302
MOV B,DAY
LCALL WRITE_1302
MOV A,#88H
LCALL WRITE_1302
MOV B,MONTH
LCALL WRITE_1302
MOV A,#8AH
LCALL WRITE_1302
MOV B,WEEK
LCALL WRITE_1302
MOV A,#8CH
LCALL WRITE_1302
MOV B,YEAR
LCALL WRITE_1302
MOV A,#8FH
MOV B,#80H
LCALL WRITE_1302
RET
GET_1302: MOV A,#81H
LCALL READ_1302
MOV SEC,A
MOV A,#83H
LCALL READ_1302
MOV MIN,A
MOV A,#85H
LCALL READ_1302
MOV HOUR,A
MOV A,#87H
LCALL READ_1302
MOV DAY,A
MOV A,#89H
LCALL READ_1302
MOV MONTH,A
MOV A,#8BH
LCALL READ_1302
MOV WEEK,A
MOV A,#8DH
LCALL READ_1302
MOV YEAR,A
RET
DISPLAY:
MOV DPTR,#TABL
MOV R0,#YEAR
MOV COM,#80H
LCALL WRITE_1602_COM
MOV R2,#3
DS1: MOV A,@R0
ANL A,#0F0H
SWAP A
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
MOV A,@R0
ANL A,#0FH
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
CJNE R2,#1H,DS3
AJMP DS5
DS3: MOV DATE,#2FH
LCALL WRITE_1602_DATE
DS5: DEC R0
DJNZ R2,DS1
MOV DPTR,#TABL
MOV R0,#HOUR
MOV COM,#0C3H
LCALL WRITE_1602_COM
MOV R2,#3
DS2: MOV A,@R0
ANL A,#0F0H
SWAP A
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
MOV A,@R0
ANL A,#0FH
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
CJNE R2,#1H,DS4
AJMP DS6
DS4: MOV DATE,#3AH
LCALL WRITE_1602_DATE
DS6: DEC R0
DJNZ R2,DS2
MOV COM,#8AH //显示周
LCALL WRITE_1602_COM
MOV A,WEEK
ANL A,#0FH
MOV B,#3
MUL AB
MOV R2,A
MOV DPTR,#TABL1
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
INC DPTR
MOV A,R2
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
INC DPTR
MOV A,R2
MOVC A,@A+DPTR
MOV DATE,A
LCALL WRITE_1602_DATE
RET
TABL: DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H
TABL1: DB"000MONTUEWEDTHUFRISATSUN"
INIT_1602: mov com,#38h
lcall write_1602_COM
mov com,#0fh
lcall write_1602_COM
mov com,#06h
lcall write_1602_COM
mov com,#01h
lcall write_1602_COM
ret
WRITE_1602_COM:CLR RS
CLR RW
SETB E
MOV P0,COM
LCALL DELAY_2MS
CLR E
RET
WRITE_1602_DATE:SETB RS
CLR RW
SETB E
MOV P0,DATE
LCALL DELAY_2MS
CLR E
RET
DELAY_2MS: MOV R7,#5
M2: MOV R6,#250
M1: NOP
NOP
DJNZ R6,M1
DJNZ R7,M2
RET
/*DSZD: PUSH ACC
PUSH B
MOV IE,#00H
MOV A,#0FFH
MOV P1,A
MOV A,P1
CPL A
ANL A,#0E0H
JZ ZD1
LCALL DELAY_2MS
MOV A,#0FFH
MOV P1,A
MOV A,P1
CPL A
ANL A,#0E0H
JZ ZD1
JB KEY1,ZD1
MOV A,#8EH
MOV B,#00H
MOV A,#80H
MOV B,#80H
LCALL SET_1302
LCALL DISPLAY
ZD3: JB KEY2,ZD2
INC SEC
MOV A,SEC
CJNE A,#60H,ZD4
MOV SEC,#00H
ZD4: LCALL SET_1302
LCALL DISPLAY
ZD2: JB KEY3,ZD5
MOV A,SEC
JZ ZD6
DEC A
ZD6: LCALL SET_1302
LCALL DISPLAY
ZD5: JB KEY1,ZD3
ZD1: MOV A,#80H
MOV B,#00H
MOV A,#8FH
MOV B,#80H
LCALL SET_1302
MOV TH0,#0D8H
MOV TL0,#0F0H
MOV IE,#82H
POP B
POP ACC
RETI*/
END |