基于HT48R50A的LED点阵+LCD显示程序

控制/MCU

1878人已加入

描述

 Function :   5X7 LED点阵+LCD显示示例程序   * 

; MICroProcessor : HT48R50A-1/28SKDIP-A      * 

HT48R50A



; Author:                      * 
; Crystal :       4MHz                       * 
; ******************************************** 

#INCLUDE                HT48R50A-1.INC 
LCD_DATA                EQU     PB 
LCD_DATA_CTRL           EQU     PBC 
LCD_CTRL                EQU     PC 
LCD_CTRL_CTRL           EQU     PCC 
E                       EQU     5 
RS                      EQU     3 
TIME_OUT                EQU     11H 
CLR_WDT                 EQU     22H 
EXE_HALT                EQU     33H 
CLR_WDT1_WDT2           EQU     44H 
;-------------------------------------------------------------------- 
DATA    .SECTION        AT 60H  ’DATA’ 
DELAY_COUNTER_1         DB      ?       ;[60H] 
DELAY_COUNTER_2         DB      ?       ;[61H] 
DELAY_COUNTER_3         DB      ?       ;[62H] 
DATA                    DB      ?       ;[63H] 
COUNTER                 DB      ?       ;[64H] 
WARM_RESET              DB      ?       ;[65H] 
DISPLAY_FLAG            DB      ?       ;[66H] 
;-------------------------------------------------------------------- 
CODE    .SECTION        AT 00H  ’CODE’ 
                ORG     00H 
                JMP     START 
START: 
                CLR     PAC 
                CLR     LCD_DATA_CTRL 
                CLR     LCD_CTRL_CTRL 
                CLR     LCD_DATA 
                CLR     LCD_CTRL 
;-------------------------------------------------------------------- 
                 MOV      A,07H       ; set watch dog time out 
                 MOV      WDTS,A      ; 2.6 sec 
                CLR     WDT         ; clear watch dog timer 
;-------------------------------------------------------------------- 
                 MOV      A,WARM_RESET 
                 MOV      DISPLAY_FLAG,A 
                SUB     A,TIME_OUT 
                SZ      ACC 
                JMP     CHK_CLR_WDT 
                JMP     GO_TIME_OUT 
CHK_CLR_WDT: 
                 MOV      A,WARM_RESET 
                 MOV      DISPLAY_FLAG,A 
                SUB     A,CLR_WDT 
                SZ      ACC 
                JMP     CHK_EXE_HALT 
                JMP     GO_CLR_WDT 
CHK_EXE_HALT: 
                 MOV      A,WARM_RESET 
                 MOV      DISPLAY_FLAG,A 
                SUB     A,EXE_HALT 
                SZ      ACC 
                JMP     CHK_CLR_WDT_12 
                JMP     GO_EXE_HALT 
CHK_CLR_WDT_12: 
                 MOV      A,WARM_RESET 
                 MOV      DISPLAY_FLAG,A 
                SUB     A,CLR_WDT1_WDT2 
                SZ      ACC 
                JMP     BEGIN 
                JMP     GO_CLR_WDT_12 
BEGIN: 
                CALL    LCD_RESET 
                CLR     WDT         ; clear watch dog timer 
;-------------------------------------------------------------------- 
GO_TIME_OUT: 
                 MOV      A,CLR_WDT 
                 MOV      WARM_RESET,A 
                 MOV      A,OFFSET LCD_MESSAGE_1 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
TIME_OUT_LOOP: 
                CALL    LED_DISPLAY 
                JMP     TIME_OUT_LOOP 
                RET 
;-------------------------------------------------------------------- 
GO_CLR_WDT: 
                 MOV      A,EXE_HALT 
                 MOV      WARM_RESET,A 
                 MOV      A,OFFSET LCD_MESSAGE_2 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
CLR_WDT_LOOP: 
                CALL    LED_DISPLAY 
                JMP     CLR_WDT_LOOP 
                RET 
;-------------------------------------------------------------------- 
GO_EXE_HALT: 
                 MOV      A,CLR_WDT1_WDT2 
                 MOV      WARM_RESET,A 
                 MOV      A,OFFSET LCD_MESSAGE_3 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
EXE_HALT_LOOP: 
                CALL    LED_DISPLAY 
                JMP     EXE_HALT_LOOP 
                RET 
;-------------------------------------------------------------------- 
GO_CLR_WDT_12: 
                 MOV      A,TIME_OUT 
                 MOV      WARM_RESET,A 
                 MOV      A,OFFSET LCD_MESSAGE_4 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
CLR_WDT_12_LOOP: 
                CALL    LED_DISPLAY 
                JMP     CLR_WDT_12_LOOP 
                RET 
;-------------------------------------------------------------------- 
LED_DISPLAY     PROC 
                SET     PA 
                CALL    DELAY 
                 MOV      A,OFFSET SEGMENT_DATA 
                 MOV      TBLP,A 
                 MOV      A,10H 
                 MOV      COUNTER,A 
DISPLAY_START: 
                TABRDL  DATA 
                 MOV      A,DATA 
                 MOV      PA,A 
                CALL    DELAY 
                INC     TBLP 

                 MOV      A,DISPLAY_FLAG 
                SUB     A,CLR_WDT 
                SZ      ACC 
                JMP     LED_CLR_WDT12 
                CLR     WDT 
                JMP     DISPLAY_END 
LED_CLR_WDT12: 
                 MOV      A,DISPLAY_FLAG 
                SUB     A,CLR_WDT1_WDT2 
                SZ      ACC 
                JMP     LED_EXE_HALT 
                CLR     WDT1 
                CLR     WDT2 
                JMP     DISPLAY_END 
LED_EXE_HALT: 
                 MOV      A,DISPLAY_FLAG 
                SUB     A,EXE_HALT 
                SZ      ACC 
                JMP     DISPLAY_END 
                HALT 
DISPLAY_END: 
                SDZ     COUNTER 
                JMP     DISPLAY_START 
                RET 
LED_DISPLAY     ENDP 
;-------------------------------------------------------------------- 
LCD_RESET       PROC 
                 MOV      A,30H       ; LCD reset , step 1 
                 MOV      LCD_DATA,A  ; 
                CALL    WRITE       ; 
                CALL    DELAY       ; LCD reset , step 2 
                 MOV      A,30H       ; LCD reset , step 3 
                 MOV      LCD_DATA,A  ; 
                CALL    WRITE       ; 
                CALL    DELAY       ; LCD reset , step 4 
                 MOV      A,30H       ; LCD reset , step 5 
                 MOV      LCD_DATA,A  ; 
                CALL    WRITE       ; 
                 MOV      A,38H       ; LCD setting , step 1 
                 MOV      LCD_DATA,A  ; function set 
                CALL    WRITE       ; 
                 MOV      A,06H       ; LCD setting , step 2 
                 MOV      LCD_DATA,A  ; entry mode set 
                CALL    WRITE       ; 
                 MOV      A,01H       ; LCD setting , step 3 
                 MOV      LCD_DATA,A  ; display clear 
                CALL    WRITE       ; 
                CALL    DELAY       ; 
                 MOV      A,0EH       ; LCD setting , step 4 
                 MOV      LCD_DATA,A  ; display turn on 
                CALL    WRITE       ; 
                RET 
LCD_RESET       ENDP 
;-------------------------------------------------------------------- 
LCD_DISPLAY     PROC 
                 MOV      A,01H       ; LCD setting , step 5 
                 MOV      LCD_DATA,A  ; display clear 
                CALL    WRITE       ; 
                CALL    DELAY       ; 
                 MOV      A,80H       ; LCD setting , setp 6 
                 MOV      LCD_DATA,A  ; DD RAM address setting 
                CALL    WRITE       ; address = 00h (first line) 
                SET     LCD_CTRL.RS ; LCD setting , step 7 
                 MOV      A,10H       ; write data to DD RAM 
                 MOV      COUNTER,A 
DISPLAY1: 
                TABRDL  DATA 
                 MOV      A,DATA 
                 MOV      LCD_DATA,A 
                CALL    WRITE 
                INC     TBLP 
                SDZ     COUNTER 
                JMP     DISPLAY1 
                CLR     LCD_CTRL.RS 
                 MOV      A,0C0H      ; LCD setting , step 8 
                 MOV      LCD_DATA,A  ; DD RAM address setting 
                CALL    WRITE       ; address = 40h (second line) 
                SET     LCD_CTRL.RS ; LCD setting , step 9 
                 MOV      A,10H       ; write data to DD RAM 
                 MOV      COUNTER,A 
DISPLAY2: 
                TABRDL  DATA 
                 MOV      A,DATA 
                 MOV      LCD_DATA,A 
                CALL    WRITE 
                INC     TBLP 
                SDZ     COUNTER 
                JMP     DISPLAY2 
                RET 
LCD_DISPLAY     ENDP 
;-------------------------------------------------------------------- 
WRITE           PROC 
                SET     LCD_CTRL.E 
                CLR     LCD_CTRL.E 
                 MOV      A,0FFH 
                 MOV      DELAY_COUNTER_1,A 
WAIT: 
                SDZ     DELAY_COUNTER_1 
                JMP     WAIT 
                RET 
WRITE           ENDP 
;-------------------------------------------------------------------- 
DELAY           PROC 
                 MOV      A,003H 
                 MOV      DELAY_COUNTER_1,A 
                 MOV      DELAY_COUNTER_2,A 
                 MOV      DELAY_COUNTER_3,A 
DELAY_WAIT: 
                SDZ     DELAY_COUNTER_3 
                JMP     DELAY_WAIT 
                SDZ     DELAY_COUNTER_2 
                JMP     DELAY_WAIT 
                SDZ     DELAY_COUNTER_1 
                JMP     DELAY_WAIT 
                RET 
DELAY           ENDP 
;-------------------------------------------------------------------- 
                ORG     0F00H 
LCD_MESSAGE_1:          ;[Now , watch dog ] 
                        ;[will be time out] 
                DC      4EH,6FH,77H,20H,2CH,20H,77H,61H 
                DC      74H,63H,68H,20H,64H,6FH,67H,20H 
                DC      77H,69H,6CH,6CH,20H,62H,65H,20H 
                DC      74H,69H,6DH,65H,20H,6FH,75H,74H 

LCD_MESSAGE_2:          ;[Without time out] 
                        ;[Because CLR WDT ] 
                DC      57H,69H,74H,68H,6FH,75H,74H,20H 
                DC      74H,69H,6DH,65H,20H,6FH,75H,74H 
                DC      42H,65H,63H,61H,75H,73H,65H,20H 
                DC      43H,4CH,52H,20H,57H,44H,54H,20H 

LCD_MESSAGE_3:          ;[Executing the   ] 
                        ;[HALT instruction] 
                DC      45H,78H,65H,63H,75H,74H,69H,6EH 
                DC      67H,20H,74H,68H,65H,20H,20H,20H 
                DC      48H,41H,4CH,54H,20H,69H,6EH,73H 
                DC      74H,72H,75H,63H,74H,69H,6FH,6EH 

LCD_MESSAGE_4:          ;[Without time out] 
                        ;[CLR WDT1 & WDT2 ] 
                DC      57H,69H,74H,68H,6FH,75H,74H,20H 
                DC      74H,69H,6DH,65H,20H,6FH,75H,74H 
                DC      43H,4CH,52H,20H,57H,44H,54H,31H 
                DC      20H,26H,20H,57H,44H,54H,32H,20H 

SEGMENT_DATA:   ;7 SEGMENT DISPLAY DATA (COMMON ANODE) 
                DC      081H,0CFH,092H,086H     ;0123 
                DC      0CCH,0A4H,0A0H,08FH     ;4567 
                DC      080H,084H,088H,0E0H     ;89AB 
                DC      0B1H,0C2H,0B0H,0B8H     ;CDEF 
;-------------------------------------------------------------------- 
                END 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分