;------------------------------------------------------------------- ;ENSC 151 Sample File ;------------------------------------------------------------------- ;AUTHOR(S): Bill De Vries ;DATE: 99-02-03 ;VERSION: 0.0 Module Created ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; This program is the sample code to show how the LCD works. ;------------------------------------------------------------------- ;------------------------------------------------------------------- ; LOCAL DEFINITIONS ;------------------------------------------------------------------- PORTA: equ $00 ;Port A Data Register PORTB: equ $01 ;Port B Data Register DDRA: equ $02 ;Port A Data Direction Register DDRB: equ $03 ;Port B Data Direction Register PORTC: equ $04 ;Port C Data Register DDRC: equ $06 ;Port C Data Direction Register PORTE: equ $08 ;Port E Data Register DDRE: equ $09 ;Port E Data Direction Register PEAR: equ $0A ;Port E Assigment Register MODE: equ $0B ;Mode Register PUCR: equ $0C ;Pull Up Control Register RDRIV: equ $0D ;Reduced Drive of I/O Lines Register INITRM: equ $10 ;Initialization of Internal RAM Position Register INITRG: equ $11 ;Initialization of Internal Register Position Register INITEE: equ $12 ;Inittaps ;------------------------------------------------------------------- ;------------------------------------------------------------------- ; INITIALIZATION CODE ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; This section of the code initializes the LCD display and sets up ; all of the sub functions required for proper operation. This ; includes the WRITE_DATA, WRITE_INST subroutines and specific delay ; counters. ;------------------------------------------------------------------- ORG $0800 ; beginning of RAM COUNTER RMB 1 ; reserve memory for delay counter ORG $0840 ldaa #$07 ; Set lower 3 bits of Port A staa DDRA ; to output mode ldaa #$FF ; Set all bits of Port B staa DDRB ; to output mode jsr LCD_INIT ; Initialize the LCD LINE_1 ldaa #$80 ; Write message to top line jsr WRITE_INST ldx #STRING1 jsr WRITE_MSG LINE_2 ldaa #$C0 ; Write message to bottom line jsr WRITE_INST ldx #STRING2 jsr WRITE_MSG LOOP bra LOOP ; End of program - idle. ;------------------------------------------------------------------- ; PROCEDURE: WRITE_DATA ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; Strobes the correct control lines to write data into the LCD. ; The data must be stored in ACCA before executing. ;------------------------------------------------------------------- WRITE_DATA ;Assume data in ACCA staa PORTB ;Write data to Port B ldaa #$01 ;Set the interface lines for data write staa PORTA jsr PAUSE ldaa #$05 staa PORTA jsr PAUSE ldaa #$01 staa PORTA jsr PAUSE rts ;------------------------------------------------------------------- ; PROCEDURE: WRITE_INST ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; Strobes the correct control lines to write an instruction to the ; LCD. Ensure that the instruction is stored in ACCA before executing. ;------------------------------------------------------------------- WRITE_INST staa PORTB ldaa #$00 staa PORTA jsr PAUSE ldaa #$04 staa PORTA jsr PAUSE ldaa #$00 staa PORTA jsr PAUSE rts ;------------------------------------------------------------------- ; PROCEDURE: WRITE_MESSAGE ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; Writes a message to the LCD. ;------------------------------------------------------------------- WRITE_MSG NEXT_CHAR ldaa 0,X ;Load string into ACCA cmpa #$00 ;Check for the end of the string beq END_MSG jsr WRITE_DATA inx ;Increment string pointer bra NEXT_CHAR END_MSG rts ;------------------------------------------------------------------- ; PROCEDURE: LCD_INIT ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; Initializes the LCD display and the ports of the HC12 for required ; operation. ;------------------------------------------------------------------- LCD_INIT ldaa #$30 jsr WRITE_INST ldaa #!15 jsr LONGPAUSE ldaa #$38 jsr WRITE_INST ldaa #$08 jsr WRITE_INST ldaa #$01 jsr WRITE_INST ldaa #!4 jsr LONGPAUSE ldaa #$06 jsr WRITE_INST ldaa #$0C jsr WRITE_INST rts ;------------------------------------------------------------------- ; PROCEDURE: Delays ;------------------------------------------------------------------- ; DESCRIPTION: ; ~~~~~~~~~~~~ ; Delay functions for proper timing interface with the LCD. ;------------------------------------------------------------------- LONGPAUSE staa COUNTER LOOK tst COUNTER beq FINISH dec COUNTER jsr PAUSE bra LOOK FINISH rts PAUSE ldy #$00FF ;Delay for a little while AGAIN dey ;Counts down the contents of the cpy #$0000 ;Y index register. bne AGAIN ;Delay = #counts * processing speed. rts STRING1 DB ' Welcome to' ; Set up strings to be displayed FCB $00 STRING2 DB ' Ensc 151' ; String for the lower line FCB $00