********************************************************************** * Example 2 ********************************************************************** * Demonstrates sending a text message to the display * written by Kenrick Chin * version: 1.00 1997 Feb 28, using indexed addressing * version: 1.01 1999 Jul 06, using extended and indexed addresing ********************************************************************** * Hardware Constants ********************************************************************** STACK EQU $00FF REGS EQU $1000 EEPROM EQU $F800 ; Short definitions .PORTA EQU $00 .PIOC EQU $02 .PORTC EQU $03 .PORTB EQU $04 .PORTCL EQU $05 .DDRC EQU $07 .PORTD EQU $08 .DDRD EQU $09 .PORTE EQU $0A ; Extended definitions PORTA EQU $1000 PIOC EQU $1002 PORTC EQU $1003 PORTB EQU $1004 PORTCL EQU $1005 DDRC EQU $1007 PORTD EQU $1008 DDRD EQU $1009 PORTE EQU $100A PACTL EQU $1026 ;portA PA7 EQU $80 DDRA7 EQU $80 ;portB PB7 EQU $80 PB6 EQU $40 PB5 EQU $20 PB4 EQU $10 PB3 EQU $08 PB2 EQU $04 PB1 EQU $02 PB0 EQU $01 ;portD PD5 EQU $20 ;LCD E EQU $04 RW EQU $02 RS EQU $01 ;character constants SP EQU $20 ;************************************************** ; Start of code segment ;************************************************** ORG EEPROM ;************************************************** ; LCD 4-bit interface ;************************************************** ;initialize LCD LCDini LDA #$28 ;dual line, 4 bits BSR LCDir LDA #$06 ;increment mode BSR LCDir LDA #$0C ;cursor turned OFF BSR LCDir LDA #$10 ;move cursor right BSR LCDir LDA #$01 ;clear display BSR LCDir RTS ;LCD clear display LCDclr PSHA LDA #$01 BSR LCDir PULA RTS ;LCD home home PSHA LDA #$02 BSR LCDir PULA RTS ;LCD spaces ;enter with B = number of spaces ;Destroyed: A,B LCDsps LDA #SP LCDsp1 BSR LCDdr DECB BNE LCDsp1 RTS ;display at line #1 line1 PSHA LDA #$80 BSR LCDir PULA RTS ;display at line #2 and clear line line2 PSHA PSHB LDA #$C0 BSR LCDir LDB #16 BSR LCDsps LDA #$C0 BSR LCDir PULB PULA RTS ;display at any position ;enter with A = LCD position (0-79) LCDpos PSHA CMPA #40 BLO LCDp1 ADDA #24 LCDp1 ORA #$80 BSR LCDir PULA RTS ;output to LCD instruction register ;Enter: A = 8 bits ;unchanged: A,B,X,Y LCDir PSHX PSHB PSHA PSHA LDX #REGS ;set up I/O base address BSR LCDrdy ;wait for LCD ready BCLR .PORTB,X RS ;set RS = 0 (PB0) BCLR .PORTB,X RW ;set R/W = 0 (PB1) LDA #$3C ;set for output STA .DDRD,X PULA TAB LSRA LSRA LSLB LSLB STA .PORTD,X ;output MS 4 bits BSET .PORTB,X E ;pulse E (PB2) BCLR .PORTB,X E STB .PORTD,X ;output LS 4 bits BSET .PORTB,X E ;pulse E (PB2) BCLR .PORTB,X E PULA PULB PULX RTS ;Output to LCD data register ;Enter with A = 8 bits ;unchanged: A,B,X,Y LCDdr PSHX PSHB PSHA PSHA LDX #REGS ;set up I/O base address BSR LCDrdy ;wait for LCD ready BSET .PORTB,X RS ;set RS = 1 (PB0) BCLR .PORTB,X RW ;set R/W = 0 (PB1) LDA #$3C ;set for output STA .DDRD,X PULA TAB LSRA LSRA LSLB LSLB STA .PORTD,X ;output MS 4 bits BSET .PORTB,X E ;pulse E (PB2) BCLR .PORTB,X E STB .PORTD,X ;output LS 4 bits BSET .PORTB,X E ;pulse E (PB2) BCLR .PORTB,X E PULA PULB PULX RTS ;wait for LCD ready ;enter with X = REGS ;destroyed: A LCDrdy CLR .DDRD,X ;set for input BSET .PORTB,X RW ;set R/W = 1 (PB1) BCLR .PORTB,X RS ;set RS = 0 (PB0) LCD1 BSET .PORTB,X E ;pulse E (PB2) LDA .PORTD,X BCLR .PORTB,X E BSET .PORTB,X E ;pulse E (PB2) BCLR .PORTB,X E BITA #$20 ;test bit5 BNE LCD1 RTS ;LCD text display ;enter with Y = address of text ;return with Y = address of null char LCDtxt PSHA txt1 LDA 0,Y ;get char BEQ txt9 ;test for end char BSR LCDdr INY BRA txt1 txt9 PULA RTS ;************************************************** ; Start of program ;************************************************** start LDS #STACK ;set up stack LDX #REGS ;set up I/O base address JSR LCDini ;initialize LCD ;************************************************** ; Main program ;************************************************** LDY #title ;point to title JSR LCDtxt ;output to LCD JSR line2 ;go to second line LDY #mess ;point to message JSR LCDtxt ;output to LCD ;loop here forever with pulse on PD5 main BSET .PORTD,X PD5 BCLR .PORTD,X PD5 BRA main ;************************************************** ; Text strings ;************************************************** title FCS 'Physics 4D6' mess FCS 'Example 2' ;************************************************** ; Interrupt Vectors ;************************************************** ORG $FFFE FDB start ;cold reset END