AT90S8515单片机1602显示程序
扫描二维码
随时随地手机看文章
AT90S8515单片机1602显示程序
;****************************
;CONTANCENUMBERDEFINATION
;****************************
.EQUFCLK=4000;SYSTEMCLOCKFREQ.=4MHz
;*************************
;PORTAPINS;
;*************************
.EQUCS=0;LCD’SCSPIN
.EQURD=1;LCD’SRDPIN
.EQUWR=2;LCD’SWRPIN
.EQUD0=4;LCD’SD0--D3
.EQUD1=5;
.EQUD2=6;
.EQUD3=7;
;*************************
;PortBpins;KEYCONTROL
;*************************
.EQUSTART=0;STARTKEY
;*************************
;PortCpins;
;*************************
.EQUPOWER=0;CONTROLLCD’SPOWERSUPPLY
.INCLUDE"..\AVR90\APPNOTES\8515DEF.INC"
;*********************************************
;DEFINEVARIAVLE
;R26--R31=X/Y/Z:LOOKASCOMMONREGISTER
;*********************************************
.DEFTIMES=R16;
.DSEG
.ORG0X60
CNTER:.BYTE1;15SecTIMER,FORSAVEDATATOEEPROM
CNTDSP:.BYTE1;3SecTIMER,FORFRESHDISPLAYANGLE
TEMP:.BYTE4;
;*******************************
;DEFINEBITFLAG
;FLAG=R18
;*******************************
.EQURELKB=0;
.EQUSAVEB=1;USEINCH/INCLKEYTOMODIFYINGTHEUPPERORLOWER
;*****************************************************
;EEPROMsegment
;DEFAULTANGLE:SEL1=2--9,SEL2=10--18,SEL3=20--29
;*****************************************************
.ESEG
.ORG0X05
DATA1:.DW0X0209
DATA2:.DW0X1018
DATA3:.DW0X2029
;****Sourcecode***************************************************
.CSEG;CODEsegment
.ORG0X000
RJMPRESET;Resethandler
RETI;INT0HANDLER
RETI;INT1HANDLER
RETI;TIMER1CAPTURE
RETI;T1COMPARORA
RETI;T1COMPARORB
RETI;T1OVERFLOW
RETI;T0OVERFLOW
RETI;SPIHANDLER
RETI;UART.RXCOMPLETEHANDLER
RETI;UART.UDREHANDLER
RETI;UART.TXCOMPLETEHANDLER
RETI;ANALOGCOMPARORHANDLER
;***Resethandler**************************************************
RESET:LDIXL,HIGH(RAMEND);SETSPVALUE
OUTSPH,XL;
LDIXL,LOW(RAMEND);
OUTSPL,XL;
INITIO:CLRXL;INITIALIZEI/OREGISTER
OUTSREG,XL;DISABLEGLOBALINTERRUPT
OUTGIMSK,XL;DISABLEINT0/INT1INTERRUPT
OUTMCUCR,XL;
LDIXL,0B00001111;SETWDTCR
OUTWDTCR,XL;
CLRXL;SETSPICONTROL
OUTSPIE,XL;
OUTSPSR,XL;
OUTUCR,XL;SETUARTCONTROL
LDIXL,0B10000000;SETANALOGCOMPARORCONTROL
OUTACSR,XL;
SERXL;PORTAISOUTPUT-PORT
OUTDDRA,XL;
LDIXL,0X0F;PA=0FH
OUTPORTA,XL;
SERXL;PORTCISOUTPUT-PORT
OUTDDRC,XL;PC=0FFH
OUTPORTC,XL;
LDIXL,$FE;PORTB0ISINPUT-PORT
OUTDDRB,XL;PORTB0Hi-Z
CLRXL;
OUTPORTB,XL;
OUTPORTD,XL;PORTD=0
SERXL;
OUTDDRD,XL;PORTDISOUTPUT-PORT
LDIXL,0B00000000;DISABLET0/T1INTERRUPT
OUTTIMSK,XL;
LDIXL,0X02;T0INPUTFREQ=FCLK/8
OUTTCCR0,XL;
CLRXL;
OUTTCCR1A,XL;
LDIXL,0B10000101;T1INPUTFREQ=FCLK/1024
OUTTCCR1B,XL;
INITRAM:CLRXL;INITILIZERAM,60H--25FH
CLRYH;ALLCLEAR0
LDIYL,0X60;
INITRAM1:WDR;RESETWATCHDOG
STY+,XL;
CPIYH,HIGH(RAMEND);
BRNEINITRAM1;
CPIYL,LOW(RAMEND);
BRNEINITRAM1;
SEI;ENABLEGLOBALINTERRUPTS
CLRTIMES;
RCALLINITLCD;INITIALIZELCDMODULE
;******************************
;MAINPROGRAMPROCESS
;******************************
MAIN:WDR;RESETWDT
RCALLKEYPRS;KEYPROCESS
RJMPMAIN
;********************************
;KEYPROCESS
;********************************
KEYPRS:INXL,TCNT1L;HAVEKEYINPUT?
KEYPRS1:SBICPINB,START;
RET;
INYL,TCNT1L;HOLD0.25*64=16ms
SUBYL,XL;
CPIYL,64;
BRSHSTKEY;
RJMPKEYPRS1;
RET
;*****************************************************************
;STARTKEYPROCESS
;STARTCOMPARINGTHETESTEDANGLETOTHEUP-LIMITANDDOWNLIMIT
;*****************************************************************
STKEY:CBIPORTC,POWER;TURNONLCD’SPOWER
INCTIMES
CPITIMES,1
BREQSTKEY1
CPITIMES,2
BREQSTKEY2
CPITIMES,3
BREQSTKEY3
CPITIMES,4
BREQSTKEY4
CPITIMES,5
BREQSTKEY5
CPITIMES,6
BREQSTKEY6
RJMPSTKEY7
STKEY1:RCALLALLON
RJMPWAITREL
STKEY2:RCALLALLOFF
RJMPWAITREL
STKEY3:RCALLCOLON
RJMPWAITREL
STKEY4:RCALLCOLOFF
RJMPWAITREL
STKEY5:RCALLROWON
RJMPWAITREL
STKEY6:RCALLROWOFF
RJMPWAITREL
STKEY7:RCALLALLOFF;TURNOFFALLDISPLAY
CLRTIMES;
SBIPORTC,POWER;SHUTOFFLCD’SPOWER
WAITREL:INXL,TCNT1L;RELEASESTARTKEYFORCONTINUOUS12ms
WAITREL1:SBISPINB,START;
RJMPWAITREL;
INXH,TCNT1L;
SUBXH,XL;
CPIXH,50;
BRLOWAITREL1;
RET
;******************************************
;DELAYAMOMENT,MIN=0.25ms,MAX=64ms
;INPUT:R24
;USEDREGISTER:R24,R23,R22
;******************************************
DELAY:INR23,TCNT1L;T1COUNTER’Sf=FCLK/1024
DELAY1:WDR;RESETWDT
INR22,TCNT1L
SUBR22,R23
CPR22,R24
BRLODELAY1
RET
;******************************************
;DELAY,MIN=64ms,MAX=16Sec
;INPUT:R24
;USEDREGISTER:R24,R23,R22
;******************************************
DL64MS:INR23,TCNT1L
INR23,TCNT1H;T1COUNTER’Sf=FCLK/1024
DL64MS1:WDR;RESETWDT
INR22,TCNT1L
INR22,TCNT1H
SUBR22,R23
CPR22,R24
BRLODL64MS1
RET
;*********************************************
;DECIL-->HEX
;INPUT:XL
;OUTPUT:YL=XL.(b7b6b5b4)*10+XL.(b3b2b1b0)
;USEDREGISTER:XL,XH,YL,YH
;*********************************************
DECHEX:MOVYL,XL;XL.(b7b6b5b4)-->YL.(b3b2b1b0)
ANDIXL,$0F;
ANDIYL,$F0;
SWAPYL;
LSLYL;YL*2
MOVXH,YL;YL-->XH
LSLYL;YL*4
LSLYL;
ADDYL,XH;
ADCYL,XL;
RET;
;*********************************************
;HEX-->DECIL
;INPUT:XL
;OUTPUT:YL=(((((((b7*2+b6)+b5)*2+...)*2+b0
;USEDREGISTER:XL,YL,YH,ZL,ZH
;*********************************************
HEXDEC:CLRYL
LDIZL,6
LDIZH,8
HEXDEC1:CLC
ROLXL
ROLYL
SBRCYL,4
ADDYL,ZL
MOVYH,YL
ANDIYH,$0F
CPIYH,$0A
BRLOHEXDEC2
ADDYL,ZL
HEXDEC2:DECZH
BRNEHEXDEC1
RET
;********************************
;READLCD
;INPUT:XL=Addr(A7--A0)
;OUTPUT:XL
;********************************
READ:CBIPORTA,CS;CS=0
LDIXH,0B01100000;
ORIXH,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
MOVXH,XL;
ANDIXH,0XF0;
ORIXH,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
ANDIXL,0X0F;
SWAPXL;
ORIXL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
CBIPORTA,RD;RD:1-->0
LDIXL,0X0F;PORTA7--PORTA4ISCHANGEDTOINPUT
OUTDDRA,XL;
LDIXL,0XF4;WR=1
OUTPORTA,XL;
RCALLWAIT;
SBIPORTA,RD;RD=1
INXL,PINA;
SERXH;
OUTDDRA,XH;PORTA7--PORTA4:COMETOOUTPUT
SBIPORTA,CS;
RET;
;*******************************************************************
;HT1647ISUSEDCOM0--COM15,SEG0--SEG47
;INITIALIZELCDBYINSTRUCTION
;1)LCDMODULEISINITIALIZEDBYINTERNALRESETCIRCUITONPOWER-ON
;2)LCDMODULEISINITIALIZEDBYINSTRUCTION,TOO
;USEDREGISTER:XL,XH
;*******************************************************************
INITLCD:LDIXH,0B01000001;RC32K
LDIXL,0B01000000;
RCALLCOMMAND;
LDIXH,0B01000000;SYSEN
LDIXL,0B00010000;
RCALLCOMMAND;
LDIXH,0B01000001;BIAS1/5
LDIXL,0B10010000;
RCALLCOMMAND;
LDIXH,0B01000001;LARGEBIAS
LDIXL,0B10000000;
RCALLCOMMAND;
LDIXH,0B01000001;FRAME89Hz
LDIXL,0B11010000;
RCALLCOMMAND;
LDIXH,0B01000011;GRSLEVEL1=X100-001b4-b3b2b1b00-XXXX
LDIXL,0B11110000;b4--b0=11111
RCALLCOMMAND;
LDIXH,0B01000101;GRSLEVEL2=X100-010b4-b3b2b1b00-XXXX
LDIXL,0B00000000;b4--b0=10000
RCALLCOMMAND;
LDIXH,0B01000110;GRSLEVEL3=X100-011b4-b3b2b1b00-XXXX
LDIXL,0B10000000;b4--b0=01000
RCALLCOMMAND;
LDIXH,0B01001000;GRSLEVEL4=X100-100b4-b3b2b1b00-XXXX
LDIXL,0B00000000;b4--b0=00000
RCALLCOMMAND;
LDIXH,0B01001111;NORMAL
LDIXL,0B11100000;
RCALLCOMMAND;
LDIXH,0B01000000;LCDON
LDIXL,0B00110000;
RCALLCOMMAND;
RET
;**********************************
;WRITEACOMMANDTOLCD
;INPUT:X,COMMAND(2BYTES)
;USEDREGISTER:XL,XH,YL
;**********************************
COMMAND:CBIPORTA,CS
MOVYL,XH;WRITEHIGHESTNIBBLE(b15b14b13b12)
ANDIYL,0XF0;
ORIYL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
ANDIXH,0X0F;WRITEb11b10b9b8
SWAPXH;
ORIXH,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
MOVYL,XL;WRITEb7b6b5b4
ANDIYL,0XF0;
ORIYL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
ANDIXL,0X0F;WRITEb3b2b1b0
SWAPXL;
ORIXL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
LDIR24,4;DELAY0.25ms*4=1ms
RCALLDELAY;
SBIPORTA,CS;CS:0-->1
RCALLWAIT;
RET;
;**********************************************
;WRITE2BYTES(4NIBBLES)TOLCD
;INPUT:X,A8101-A7A6A5A4-A3A2A1A0-D3D2D1D0
;USEDREGISTER:XL,XH,YL
;**********************************************
LCDDATA:CBIPORTA,CS;
MOVYL,XH;WRITEHIGHESTNIBBLE(b15b14b13b12)
ANDIYL,0XF0;
ORIYL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
ANDIXH,0X0F;WRITEb11b10b9b8
SWAPXH;
ORIXH,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
MOVYL,XL;WRITEb7b6b5b4
ANDIYL,0XF0;
ORIYL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
LDIYL,4;SETLOOPTIMES=4
ANDIXL,0X0F;WRITEb3b2b1b0=D3D2D1D0
SWAPXL;
ORIXL,1<
RCALLWAIT;
SBIPORTA,WR;WR:0-->1
RCALLWAIT;
DECYL;
BRNELCDDATA1;
LDIR24,4;DELAY0.25ms*4=1ms
RCALLDELAY;
SBIPORTA,CS;CS:0-->1
RCALLWAIT;
RET;
;***************************************************
;TURNONOROFFALLLCD’SDOTS
;LCDCOM0--COM15,SEG0--SEG47,TOTAL16*48DOTS
;FIANLAddr=48*16/2-1=384-1=180H-1
;***************************************************
ALLON:LDIZH,$0F;
RJMPALLLCD;
ALLOFF:LDIZH,$0;
ALLLCD:CLRZL;ZL=LCDRAMAddr(0A8A7A6-A5A4A3A2)
ALLLCD1:MOVXH,ZL;X=A8101-A7A6A5A4-A3A2A1A0-D3D2D1D0
LSRXH;ZL.(b5--b2)-->XH.(b3--b0)
LSRXH;
ANDIXH,$0F;
ORIXH,0B01010000;
BSTZL,6;
BLDXH,7;
CLRXL;
BSTZL,0;
BLDXL,6;
BSTZL,1;
BLDXL,7;
ORXL,ZH;
RCALLLCDDATA;
INCZL;
CPIZL,96;
BRLOALLLCD1;
RET;
;***************************************************
;DISPLAYONROW
;LCDCOM0--COM15,SEG0--SEG36,TOTAL73*8DOTS
;FIANLAddr=36*8=288=120H
;***************************************************
ROWON:LDIZH,$0C;
RJMPALLLCD;
ROWOFF:LDIZH,$03;
RJMPALLLCD;
;***************************************************
;DISPLAYONCOL
;LCDCOM0--COM15,SEG0--SEG47,TOTAL48*16DOTS
;FIANLAddr=48*16/2-1=384-1=180H-1
;***************************************************
COLON:LDIZH,$0F;
RJMPCOL;
COLOFF:LDIZH,$00;
COL:CLRZL;ZL=LCDRAMAddr(0A8A7A6-A5A4A3A2)
CLRYH
COL1:RCALLHALFCOL
INCZL
INCZL
COMZH
ANDIZH,$0F
RCALLHALFCOL
COMZH
ANDIZH,$0F
INCZL
INCZL
CPIZL,48
BRLOCOL1
TSTYH
BRNECOL2
COMZH
ANDIZH,$0F
INCYH
COL2:CPIZL,96
BRLOCOL1
RET;
;***********************************************
;WRITE16DOTS
;INPUT:ZH,ZL,ZH=0F/00,ZL=0A8A7A6-A5A4A3A2
;***********************************************
HALFCOL:MOVXH,ZL;X=A8101-A7A6A5A4-A3A2A1A0-D3D2D1D0
LSRXH;XH=A8101-A7A6A5A4
LSRXH;
ANDIXH,$0F;
ORIXH,0B01010000;
BSTZL,6;
BLDXH,7;
MOVXL,ZH;
BSTZL,1;XL=A3A200-D3D2D1D0
BLDXL,7;
BSTZL,0;
BLDXL,6;
PUSHXH;SAVEXH,XLTOSTACK
PUSHXL;
RCALLLCDDATA;
POPXL;
POPXH;
LDIYL,$40;
ADDXL,YL;
RJMPLCDDATA;
;**********************************************
;WHENOPERATINGLCDMODULE,WAITFORAMOMENT
;USEDREGISTER:
;**********************************************
WAIT:PUSHXL
CLRXL
WAIT1:INCXL
CPIXL,0X02
BRLOWAIT1
POPXL
RET