;------------------------------------------ ; ================================== ; == LCD 計時器控制(改良版) == ; == 2013/12/21 == ; == 蘇偉諺 4A037052 == ; ================================== ;------------------------------------------ ;===================主程式==================== ;-------------------定義參數----------------- LCD_ENABLE EQU P3.7 LCD_RS EQU P2.1 LCD_BUS EQU P0 SEC EQU 45H MIN EQU 46H HOUR EQU 47H ;-------------------初始化-------------------- ORG 00H JMP MAIN ORG 001BH JMP INTERRUPT MAIN: MOV SP,#5FH CALL DELAY1 MOV R2,#0 INC R2 MOV SEC,#0 MOV MIN,#0 MOV HOUR,#0 MOV R3,#0 CALL INITLCD;2ms ;----------在LCD第一行顯示HOR:MIN:SEC--------- MOV DPTR,#STR CALL PRTSTring;50u*11s ;--------------------------------------------- JMP $ ;----------定位游標於第二行第0字-------------- INTERRUPT: MOV TH1,#HIGH(65536-50000) MOV TL1,#LOW(65536-50000) INC R3 CJNE R3,#20,RETURN MOV R3,#0 MOV A,#2 MOV B,#0 CALL GOXY;50us ;----------------呼叫計時副程式--------------- CALL CLOCK ;---------------顯示時間於LCD----------------- MOV A,#20H CALL WRDR;50us MOV DPTR,#STR1 MOV B,HOUR CALL PRTIME;50u*2s CALL PRTBLANK MOV B,MIN CALL PRTIME;50u*2s CALL PRTBLANK MOV A,#':' MOV B,SEC CALL PRTIME RETURN: RETI ;-------------------字串寫入ROM--------------- STR: DB 'HOR:MIN:SEC','$' STR1: DB '0123456789' ;===================副程式==================== DELAY1: MOV TMOD,#00010001B MOV TH1,#HIGH(65536-50000) MOV TL1,#LOW(65536-50000) MOV IE,#10001000B SETB TR1 RET ;--------------------------------------------- PRTBLANK: MOV A,#':' CALL WRDR MOV A,#20H CALL WRDR RET ;-----------------印出時間-------------------- PRTIME: MOV A,B SWAP A ANL A,#00001111B MOVC A,@A+DPTR CALL WRDR MOV A,B ANL A,#00001111B MOVC A,@A+DPTR CALL WRDR RET ;-----------------計次時間-------------------- CLOCK: PUSH ACC MOV A,SEC ADD A,#1 DA A MOV SEC,A CJNE A,#60H,CKRET MOV SEC,#0 MOV A,MIN ADD A,#1 DA A MOV MIN,A CJNE A,#60H,CKRET MOV MIN,#0 MOV A,HOUR ADD A,#1 DA A MOV HOUR,A CJNE A,#24H,CKRET MOV HOUR,#0 CKRET: POP ACC RET ;-----------------游標定位-------------------- GOXY: ANL B,#00001111B CJNE A,#1,CHK1 MOV A,B ADD A,#10000000B;SETB A.7 ORL 10000000B CALL WRIR RET CHK1: MOV A,B ADD A,#11000000B CALL WRIR RET ;-----------------顯示字串-------------------- PRTSTring: PUSH ACC PRTLOOP: CLR A MOVC A,@A+DPTR CJNE A,#'$',NEXT JMP ENDPRT NEXT: CALL WRDR INC DPTR JMP PRTLOOP ENDPRT: POP ACC RET ;-----------------初始化LCD-------------------- INITLCD: MOV A,#38H CALL WRIR MOV A,#0DH CALL WRIR MOV A,#06H CALL WRIR MOV A,#01H CALL WRIR MOV R7,#40;清除需延遲2ms CALL DELAY RET ;-----------------延遲時間-------------------- DELAY: DLOOP: MOV TH0,#HIGH(65536-50) MOV TL0,#LOW(65536-50) SETB TR0 JNB TF0,$ CLR TR0 CLR TF0 DJNZ R7,DLOOP RET ;-----------------寫入指令-------------------- WRIR: SETB LCD_ENABLE CLR LCD_RS MOV LCD_BUS,A CLR LCD_ENABLE MOV R7,#1 CALL DELAY RET ;-----------------寫入資料-------------------- WRDR: SETB LCD_ENABLE SETB LCD_RS MOV LCD_BUS,A CLR LCD_ENABLE MOV R7,#1 CALL DELAY RET END
advertisement
2014年1月3日
89C51 顯示時鐘 Assembly
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言
文章有誤或有問題麻煩您留言告知! 謝謝您~~