;********************************************
;Function:LCD字符顯示+KEY按鍵處理示例程序*
;MICroProcessor:HT48R50A-1/28SKDIP-A*
;Author:www.picavr.com*
;Crystal:4MHz*
;********************************************
#INCLUDEHT48R50A-1.INC
LCD_DATAEQUPC
LCD_DATA_CTRLEQUPCC
LCD_CTRLEQUPB
LCD_CTRL_CTRLEQUPBC
EEQU1
RSEQU0
;------------------------------------------------------------
DATA.SECTIONAT60H’DATA’
DELAY_COUNTER_1DB?;[60H]
DELAY_COUNTER_2DB?;[61H]
DELAY_COUNTER_3DB?;[62H]
DATADB?;[63H]
COUNTERDB?;[64H]
;------------------------------------------------------------
CODE.SECTIONAT00H’CODE’
ORG00H
JMPSTART
ORG0CH
JMPTIMER1
ORG20H
START:
MOV A,01111111B
MOV PAC,A
CALLLCD_RESET
MOV A,OFFSETLCD_MESSAGE_1
MOV TBLP,A
CALLLCD_DISPLAY
MOV A,09H
MOV INTC,A
MOV A,80H
MOV TMR1C,A
FIRST_TIME:
MOV A,PA
ANDA,00010000B
SUBA,00010000B
SZACC
JMPFIRST_TIME
PRESS_ANY_KEY:
MOV A,OFFSETLCD_MESSAGE_2
MOV TBLP,A
CALLLCD_DISPLAY
ANY_KEY:
MOV A,PA
ANDA,00010000B
SUBA,00010000B
SZACC
JMPANY_KEY
MOV A,PA
ANDA,00001111B
MOV DATA,A
SUBA,09H
SZACC
JMPNEXT_CHECK
JMPSTART
NEXT_CHECK:
MOV A,DATA
SUBA,08H
SZACC
JMPPLAY_MONOTONY
JMPPLAY_A_SONG
PLAY_MONOTONY:
CALLMONOTONY
JMPANY_KEY
PLAY_A_SONG:
MOV A,OFFSETLCD_MESSAGE_3
MOV TBLP,A
CALLLCD_DISPLAY
CLRCOUNTER
PLAY_LOOP:
MOV A,OFFSETSONG_DATA
ADDA,COUNTER
MOV TBLP,A
TABRDLDATA
DECDATA
CALLMONOTONY
INCCOUNTER
MOV A,COUNTER
SUBA,4BH
SZACC
JMPPLAY_LOOP
JMPPRESS_ANY_KEY
RET
;------------------------------------------------------------
TIMER1:
CPLPA
RETI
;------------------------------------------------------------
MONOTONYPROC
MOV A,OFFSETMUSIC_DATA
ADDA,DATA
MOV TBLP,A
TABRDLDATA
MOV A,DATA
MOV TMR1L,A
MOV A,TBLP
ADDA,08H
MOV TBLP,A
TABRDLDATA
MOV A,DATA
MOV TMR1H,A
SETTMR1C.4
CALLDELAY_LONG
CLRTMR1C.4
RET
MONOTONYENDP
;------------------------------------------------------------
LCD_RESETPROC
CLRLCD_DATA_CTRL
CLRLCD_CTRL_CTRL
CLRLCD_DATA
CLRLCD_CTRL
MOV A,00110011B;STEP0
MOV DATA,A;LCDRESET
CALLTRANSFER;
MOV A,00110010B;SETP1
MOV DATA,A;FUNCTIONSET
CALLTRANSFER;
MOV A,00001100B;STEP2
MOV DATA,A;DISPLAYTURNON
CALLTRANSFER;
MOV A,00000001B;STEP3
MOV DATA,A;DISPLAYCLEAN
CALLTRANSFER;
CALLDELAY;DELAYSOMETIME
MOV A,00000110B;STEP4
MOV DATA,A;ENTRYMODESET
CALLTRANSFER;
RET
LCD_RESETENDP
;------------------------------------------------------------
LCD_DISPLAYPROC
MOV A,10000000B;STEP1
MOV DATA,A;DDRAMADDRESSSET
CALLTRANSFER;FIRSTLINE
MOV A,10H;STEP2-1
MOV COUNTER,A;WRITEDATATODDRAM
FIRST_LINE:
CLRLCD_CTRL.RS
MOV A,00011100B;STEP2-2
MOV DATA,A;DISPLAY/CURSOR
CALLTRANSFER;SHIFT
SETLCD_CTRL.RS
TABRDLDATA
CALLTRANSFER
CALLDELAY
INCTBLP
SDZCOUNTER
JMPFIRST_LINE
CLRLCD_CTRL.RS
MOV A,11000000B;STEP3
MOV DATA,A;DDRAMADDRESSSET
CALLTRANSFER;SECONDLINE
MOV A,10H;STEP4-1
MOV COUNTER,A;WRITEDATATODDRAM
SECOND_LINE:
CLRLCD_CTRL.RS
MOV A,00011000B;STEP4-2
MOV DATA,A;DISPLAY/CURSOR
CALLTRANSFER;SHIFT
SETLCD_CTRL.RS
TABRDLDATA
CALLTRANSFER
CALLDELAY
INCTBLP
SDZCOUNTER
JMPSECOND_LINE
CLRLCD_CTRL.RS
RET
LCD_DISPLAYENDP
;------------------------------------------------------------
TRANSFERPROC
SWAPDATA
MOV A,DATA
MOV PC,A
CALLWRITE
SWAPDATA
MOV A,DATA
MOV PC,A
CALLWRITE
RET
TRANSFERENDP
;------------------------------------------------------------
WRITEPROC
SETLCD_CTRL.E
CLRLCD_CTRL.E
MOV A,0FFH
MOV DELAY_COUNTER_1,A
WRITE_WAIT:
SDZDELAY_COUNTER_1
JMPWRITE_WAIT
RET
WRITEENDP
;------------------------------------------------------------
DELAYPROC
MOV A,0A0H
MOV DELAY_COUNTER_1,A
MOV DELAY_COUNTER_2,A
DELAY_WAIT:
SDZDELAY_COUNTER_2
JMPDELAY_WAIT
SDZDELAY_COUNTER_1
JMPDELAY_WAIT
RET
DELAYENDP
;------------------------------------------------------------
DELAY_LONGPROC
MOV A,003H
MOV DELAY_COUNTER_1,A
MOV DELAY_COUNTER_2,A
MOV DELAY_COUNTER_3,A
DELAY_LONG_WAIT:
SDZDELAY_COUNTER_3
JMPDELAY_LONG_WAIT
SDZDELAY_COUNTER_2
JMPDELAY_LONG_WAIT
SDZDELAY_COUNTER_1
JMPDELAY_LONG_WAIT
RET
DELAY_LONGENDP
;------------------------------------------------------------
ORG0F00H
LCD_MESSAGE_1:;[LCD4BITSDATA]
;[TRANSFERTESTOK]
DC4CH,43H,44H,20H,34H,20H,42H,49H
DC54H,53H,20H,44H,41H,54H,41H,20H
DC54H,52H,41H,4EH,53H,46H,45H,52H
DC20H,54H,45H,53H,54H,20H,4FH,4BH
LCD_MESSAGE_2:;[MINIPIANO]
;[PRESSANYKEY!]
DC20H,20H,20H,4DH,49H,4EH,49H,20H
DC50H,49H,41H,4EH,4FH,20H,20H,20H
DC20H,50H,52H,45H,53H,53H,20H,41H
DC4EH,59H,20H,4BH,45H,59H,21H,20H
LCD_MESSAGE_3:;[PLAYMUSIC]
;[JUSTAMOMENT!]
DC20H,20H,20H,50H,4CH,41H,59H,20H
DC4DH,55H,53H,49H,43H,20H,20H,20H
DC20H,4AH,55H,53H,54H,20H,41H,20H
DC4DH,4FH,4DH,45H,4EH,54H,21H,20H
MUSIC_DATA:
DC043H,0B1H,009H,033H
DC083H,0C7H,005H,023H
DC0FCH,0FCH,0FDH,0FDH
DC0FDH,0FDH,0FEH,0FEH
SONG_DATA:
DC06H,06H,05H,06H,05H,03H
DC05H,03H,03H,02H,03H,03H
DC02H,02H,01H,02H,02H,05H
DC05H,03H,03H,02H,03H,03H
DC06H,06H,05H,06H,05H,03H
DC04H,04H,04H,03H,02H,03H,03H
DC05H,05H,05H,05H,05H,07H
DC06H,06H,06H,06H,05H,06H,06H
DC08H,08H,08H,07H,05H
DC06H,06H,06H,06H,05H,06H,05H,03H
DC05H,05H,05H,05H,05H,07H
DC06H,06H,06H,06H,05H,06H
;------------------------------------------------------------
END