基于LCD字符++KEY按键显示程序

基于LCD字符++KEY按键显示程序,第1张

 FuncTIon : LCD字符显示+KEY按键处理示例程序 * 

基于LCD字符++KEY按键显示程序,基于LCD字符++KEY按键显示程序,第2张



MICroProcessor : HT48R50A-1/28SKDIP-A      * 

; Author:                      * 
; Crystal :       4MHz                       * 
; ******************************************** 
#INCLUDE                HT48R50A-1.INC 
LCD_DATA                EQU     PC 
LCD_DATA_CTRL           EQU     PCC 
LCD_CTRL                EQU     PB 
LCD_CTRL_CTRL           EQU     PBC 
E                       EQU     1 
RS                      EQU     0 
;------------------------------------------------------------ 
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] 
;------------------------------------------------------------ 
CODE    .SECTION        AT 00H  ’CODE’ 
                ORG     00H 
                JMP     START 
                ORG     0CH 
                JMP     TIMER1 

                ORG     20H 
START: 
                 MOV      A,01111111B 
                 MOV      PAC,A 
                CALL    LCD_RESET 
                 MOV      A,OFFSET LCD_MESSAGE_1 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
                 MOV      A,09H 
                 MOV      INTC,A 
                 MOV      A,80H 
                 MOV      TMR1C,A 
FIRST_TIME: 
                 MOV      A,PA 
                AND     A,00010000B 
                SUB     A,00010000B 
                SZ      ACC 
                JMP     FIRST_TIME 
PRESS_ANY_KEY: 
                 MOV      A,OFFSET LCD_MESSAGE_2 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
ANY_KEY: 
                 MOV      A,PA 
                AND     A,00010000B 
                SUB     A,00010000B 
                SZ      ACC 
                JMP     ANY_KEY 
                 MOV      A,PA 
                AND     A,00001111B 
                 MOV      DATA,A 
                SUB     A,09H 
                SZ      ACC 
                JMP     NEXT_CHECK 
                JMP     START 
NEXT_CHECK: 
                 MOV      A,DATA 
                SUB     A,08H 
                SZ      ACC 
                JMP     PLAY_MONOTONY 
                JMP     PLAY_A_SONG 
PLAY_MONOTONY: 
                CALL    MONOTONY 
                JMP     ANY_KEY 
PLAY_A_SONG: 
                 MOV      A,OFFSET LCD_MESSAGE_3 
                 MOV      TBLP,A 
                CALL    LCD_DISPLAY 
                CLR     COUNTER 
PLAY_LOOP: 
                 MOV      A,OFFSET SONG_DATA 
                ADD     A,COUNTER 
                 MOV      TBLP,A 
                TABRDL  DATA 
                DEC     DATA 
                CALL    MONOTONY 
                INC     COUNTER 
                 MOV      A,COUNTER 
                SUB     A,4BH 
                SZ      ACC 
                JMP     PLAY_LOOP 
                JMP     PRESS_ANY_KEY 
                RET 
;------------------------------------------------------------ 
TIMER1: 
                CPL     PA 
                RETI 
;------------------------------------------------------------ 
MONOTONY        PROC 
                 MOV      A,OFFSET MUSIC_DATA 
                ADD     A,DATA 
                 MOV      TBLP,A 
                TABRDL  DATA 
                 MOV      A,DATA 
                 MOV      TMR1L,A 
                 MOV      A,TBLP 
                ADD     A,08H 
                 MOV      TBLP,A 
                TABRDL  DATA 
                 MOV      A,DATA 
                 MOV      TMR1H,A 
                SET     TMR1C.4 
                CALL    DELAY_LONG 
                CLR     TMR1C.4 
                RET 
MONOTONY        ENDP 
;------------------------------------------------------------ 
LCD_RESET       PROC 
                CLR     LCD_DATA_CTRL 
                CLR     LCD_CTRL_CTRL 
                CLR     LCD_DATA 
                CLR     LCD_CTRL 
                 MOV      A,00110011B     ;STEP 0 
                 MOV      DATA,A          ;LCD RESET 
                CALL    TRANSFER        ; 
                 MOV      A,00110010B     ;SETP 1 
                 MOV      DATA,A          ;FUNCTION SET 
                CALL    TRANSFER        ; 
                 MOV      A,00001100B     ;STEP 2 
                 MOV      DATA,A          ;DISPLAY TURN ON 
                CALL    TRANSFER        ; 
                 MOV      A,00000001B     ;STEP 3 
                 MOV      DATA,A          ;DISPLAY CLEAN 
                CALL    TRANSFER        ; 
                CALL    DELAY           ;DELAY SOME TIME 
                 MOV      A,00000110B     ;STEP 4 
                 MOV      DATA,A          ;ENTRY MODE SET 
                CALL    TRANSFER        ; 
                RET 
LCD_RESET       ENDP 
;------------------------------------------------------------ 
LCD_DISPLAY     PROC 
                 MOV      A,10000000B     ;STEP 1 
                 MOV      DATA,A          ;DD RAM ADDRESS SET 
                CALL    TRANSFER        ;FIRST LINE 
                 MOV      A,10H           ;STEP 2-1 
                 MOV      COUNTER,A       ;WRITE DATA TO DD RAM 
FIRST_LINE: 
                CLR     LCD_CTRL.RS 
                 MOV      A,00011100B     ;STEP 2-2 
                 MOV      DATA,A          ;DISPLAY/CURSOR 
                CALL    TRANSFER        ;SHIF
                SET     LCD_CTRL.RS 
                TABRDL  DATA 
                CALL    TRANSFER 
                CALL    DELAY 
                INC     TBLP 
                SDZ     COUNTER 
                JMP     FIRST_LINE 
                CLR     LCD_CTRL.RS 

                 MOV      A,11000000B     ;STEP 3 
                 MOV      DATA,A          ;DD RAM ADDRESS SET 
                CALL    TRANSFER        ;SECOND LINE 
                 MOV      A,10H           ;STEP 4-1 
                 MOV      COUNTER,A       ;WRITE DATA TO DD RAM 
SECOND_LINE: 
                CLR     LCD_CTRL.RS 
                 MOV      A,00011000B     ;STEP 4-2 
                 MOV      DATA,A          ;DISPLAY/CURSOR 
                CALL    TRANSFER        ;SHIFT 
                SET     LCD_CTRL.RS 
                TABRDL  DATA 
                CALL    TRANSFER 
                CALL    DELAY 
                INC     TBLP 
                SDZ     COUNTER 
                JMP     SECOND_LINE 
                CLR     LCD_CTRL.RS 
                RET 
LCD_DISPLAY     ENDP 
;------------------------------------------------------------ 
TRANSFER        PROC 
                SWAP    DATA 
                 MOV      A,DATA 
                 MOV      PC,A 
                CALL    WRITE 
                SWAP    DATA 
                 MOV      A,DATA 
                 MOV      PC,A 
                CALL    WRITE 
                RET 
TRANSFER        ENDP 
;------------------------------------------------------------ 
WRITE           PROC 
                SET     LCD_CTRL.E 
                CLR     LCD_CTRL.E 
                 MOV      A,0FFH 
                 MOV      DELAY_COUNTER_1,A 
WRITE_WAIT: 
                SDZ     DELAY_COUNTER_1 
                JMP     WRITE_WAIT 
                RET 
WRITE           ENDP 
;------------------------------------------------------------ 
DELAY           PROC 
                 MOV      A,0A0H 
                 MOV      DELAY_COUNTER_1,A 
                 MOV      DELAY_COUNTER_2,A 
DELAY_WAIT: 
                SDZ     DELAY_COUNTER_2 
                JMP     DELAY_WAIT 
                SDZ     DELAY_COUNTER_1 
                JMP     DELAY_WAIT 
                RET 
DELAY           ENDP 
;------------------------------------------------------------ 
DELAY_LONG      PROC 
                 MOV      A,003H 
                 MOV      DELAY_COUNTER_1,A 
                 MOV      DELAY_COUNTER_2,A 
                 MOV      DELAY_COUNTER_3,A 
DELAY_LONG_WAIT: 
                SDZ     DELAY_COUNTER_3 
                JMP     DELAY_LONG_WAIT 
                SDZ     DELAY_COUNTER_2 
                JMP     DELAY_LONG_WAIT 
                SDZ     DELAY_COUNTER_1 
                JMP     DELAY_LONG_WAIT 
                RET 
DELAY_LONG      ENDP 
;------------------------------------------------------------ 
                ORG     0F00H 
LCD_MESSAGE_1:          ;[LCD 4 BITS DATA ] 
                        ;[TRANSFER TEST OK] 
                DC      4CH,43H,44H,20H,34H,20H,42H,49H 
                DC      54H,53H,20H,44H,41H,54H,41H,20H 
                DC      54H,52H,41H,4EH,53H,46H,45H,52H 
                DC      20H,54H,45H,53H,54H,20H,4FH,4BH 
LCD_MESSAGE_2:          ;[   MINI PIANO   ] 
                        ;[ PRESS ANY KEY! ] 
                DC      20H,20H,20H,4DH,49H,4EH,49H,20H 
                DC      50H,49H,41H,4EH,4FH,20H,20H,20H 
                DC      20H,50H,52H,45H,53H,53H,20H,41H 
                DC      4EH,59H,20H,4BH,45H,59H,21H,20H 
LCD_MESSAGE_3:          ;[   PLAY MUSIC   ] 
                        ;[ JUST A MOMENT! ] 
                DC      20H,20H,20H,50H,4CH,41H,59H,20H 
                DC      4DH,55H,53H,49H,43H,20H,20H,20H 
                DC      20H,4AH,55H,53H,54H,20H,41H,20H 
                DC      4DH,4FH,4DH,45H,4EH,54H,21H,20H 
MUSIC_DATA: 
                DC      043H,0B1H,009H,033H 
                DC      083H,0C7H,005H,023H 
                DC      0FCH,0FCH,0FDH,0FDH 
                DC      0FDH,0FDH,0FEH,0FEH 
SONG_DATA: 
                DC      06H,06H,05H,06H,05H,03H 
                DC      05H,03H,03H,02H,03H,03H 
                DC      02H,02H,01H,02H,02H,05H 
                DC      05H,03H,03H,02H,03H,03H 
                DC      06H,06H,05H,06H,05H,03H 
                DC      04H,04H,04H,03H,02H,03H,03H 
                DC      05H,05H,05H,05H,05H,07H 
                DC      06H,06H,06H,06H,05H,06H,06H 
                DC      08H,08H,08H,07H,05H 
                DC      06H,06H,06H,06H,05H,06H,05H,03H 
                DC      05H,05H,05H,05H,05H,07H 
                DC      06H,06H,06H,06H,05H,06H 
;------------------------------------------------------------ 
                END 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/dianzi/2637713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-08-12
下一篇 2022-08-12

发表评论

登录后才能评论

评论列表(0条)

保存