Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
private
/
Projet
/
Example
/
HC12
/
D128
:
Lcd_Ser.ASM
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
; ; ; ============================================================= ; ; Lcd_Ser.asm: Serial Lcd Driver ; Axm-0232 ; Version: 1.0 Released 4/17/2002 ; Author: Gary Karnes , Axiom Manufacturing ; Compiler: Asm12 ; Platform: Cmd912x or CML12S ; ; ============================================================= ; This program interfaces with the Serial Lcd ; port. The lcd is setup in 4 bit mode ; ; Run in ram only, one varable LCDBUF CR equ $0d return LF equ $0a return EOT equ $04 end of a text table BELL equ $07 Bell BKSP equ $08 Backspace WR: equ $20 RS: equ $40 ; lcd RS select EN: equ $80 ; lcd en select ; ; ; ; #include Dp256reg.asm ; 256 registers ; ; include the following if assembly this alone ; program start ram only org $2000 ; start ; Lcd test LCD_TST: jsr Init_Spi ; set up Spi ; ; ;mainloop: ; jsr Lcd_Init * init Lcd ; switch Lcd_cs to high, select data register ldx #LCDBUF * setup signals for lcd, bset 0,X RS * select Lcd data register jsr LCD_SEND * send to lcd LCD_LOOP: ; ldaa #$30 ; jsr LCD_WR_8 jsr LCDSTR1 fdb Axiom ; display 'Axiom' jsr LCDSTR1 fdb Is ; display 'Is' jsr LCDSTR1 fdb The ; display 'The' jsr LCDSTR1 fdb Place ;here: ; bra here rts ; ; Lcd Setup , 4 bit wide Lcd_Init: bclr LCDBUF,RS+EN ; select lcd commands Cs=0 En=0 jsr LCD_SEND ; ; ; set to 4 bit jsr DELAY50M ; delay ldaa #$03 ; send 3 jsr LCD_WR_4 jsr DELAY50M ; delay ldaa #$03 jsr LCD_WR_4 ; send 3 jsr DELAY50M ldaa #$03 jsr LCD_WR_4 ; send 3 jsr DELAY50M ldaa #$02 jsr LCD_WR_4 ; send 2 jsr DELAY50M ; ; write $2c , in 4 bit mode LCDINN: ; ldaa #$28 ldaa #$2c jsr LCD_CMD ; write command jsr DELAY10M ; delay ; ; write $0f in 4 bit mode ldaa #$06 ; ldaa #$0f jsr LCD_CMD ; send command jsr DELAY10M * delay ; ; write $14 in 4 bit mode ldaa #$0e jsr LCD_CMD ; send command jsr DELAY10M * delay ; ; write $01 in 4 bit mode ldaa #$01 jsr LCD_CMD ; send command jsr DELAY20M ; delay ldaa #$80 jsr LCD_CMD ; send command jsr DELAY10M * delay ; ; Reset Lcd states to rest ldaa #$00 * turn all signals off on lcd staa LCDBUF * save states jsr LCD_SEND * send signals rts ; ; ; ; Lcd Send LCD_SEND ldaa LCDBUF * load data & signals jsr SS_IO * send to lcd rts ; ;------------------------------------------------- ; Simple Serial Driver (SPI), source code... ; Acc A is send serially, msb first ; return received in Acc A SS_IO: jsr DELAY10M LDAB SPI0SR ; CLEAR STATUS OF SPI STAA SP0DR ; SEND / RECEIVE BYTE SS_IO_LP: brclr SPI0SR,#$80,SS_IO_LP ; WAIT IF NO FLAG ldaa SP0DR ; read receive value rts ; ; ; Simple Serial Driver initialization... Init_Spi: ; Turn on Spi movb #$52,SPI0CR1 ; Setup SPI movb #$10,SPI0CR2 ; enable /SS movb #$00,SPI0BR ; set up Spi baud clock rate ; ldaa SPI0SR ; read status ; movb #$50,SPI0CR1 ; turn on SPI bset LCDBUF,WR BCLR LCDBUF,EN JSR LCD_SEND rts ; ; OUTSTRG: ldaa 0,x ; get char cmpa #EOT ; if end message then quit beq OUTSTRGE ; jsr OUTSCI0 ; output char inx ; next char bra OUTSTRG ; repeat OUTSTRGE: rts ; OUTSTRG0: rts ; ;----------------------------------------------- ; Lcd Routines ; ; Lcd Out Write a byte LCD_OUT: bset LCDBUF,$10 ; select lcd data buffer jsr LCD_WR_8 ; write byte rts ; ; ; Send a String to the LCD ; Index register is loaded with address of string. ; continue until reading a zero. LCDSTR: pshb ; save b ldab #$03 ; select lcd buffer ldaa 0,x ; load byte from string beq LSE ; if zero then end pshx ; save x jsr LCD_OUT ; send character to lcd pulx ; restore x inx pulb ; restore b bra LCDSTR LSE ldaa #$20 ; add space jsr LCD_OUT pulb ; restore b rts ; ; Send one string to Lcd ; load 16 bit pointer after jsr ; sends space after string ; Lcdstr1S is calling from sub,sub LCDSTR1S: puld ; get d (return address) puly 0,sp ; get the return Pc value ldx 0,y ; string location pointed to by Pc iny ; skip over string pointer iny pshy pshd ; save d (return address) jsr LCDSTR ; send string rts ; LCDSTR1: jsr LCDSTR1S ; send one string + space rts ; ; ; Lcd Write 4 bit Data , lower 4 bits of acc A ; Bit assignment ; 0 = Lcd-Db4 4 = ; 1 = Lcd-Db5 5 = ; 2 = Lcd-Db6 6 = EN ; 3 = Lcd=Db7 7 = RS LCD_WR_4: pshx psha * save value ldaa LCDBUF * load Lcd buffer anda #$f0 * get only controls signals pulb * get data andb #$0f * only bits 0-3 are data aba staa LCDBUF * save data & lcd signals ldx #LCDBUF bclr 0,x EN ; enable low jsr LCD_SEND * send the data bset LCDBUF,EN ; enable high jsr LCD_SEND bclr 0,x EN ; enable low jsr LCD_SEND pulx rts ; : ; Lcd Write 8 bit Data , lower 4 bits first in acc A LCD_WR_8: psha ; save a lsra ; shift upper 4 bits to lower lsra lsra lsra jsr LCD_WR_4 ; write upper 4 bits to lcd pula jsr LCD_WR_4 ; write lower 4 bits to lcd rts ; ; ; Lcd Command LCD_CMD: bclr LCDBUF,RS ; select lcd command buffer jsr LCD_WR_8 ; wait rts ; ; ; Messages Axiom: fcc 'Axiom' fcb 0 Is: fcc 'is' fcb 0 The: fcc 'The' fcb 0 Place: fcc 'Place ' fcb 0 ; ; Delay routines ; ; ; Generate a 50 ms delay DELAY50M: pshx ldx #49998 ; delay 50,000 usecs, jsr DELML01 ; call usec delay pulx rts ; ; ; Generate a 20 ms delay DELAY20M: bsr DELAY10M bsr DELAY10M rts ; ; Generate a 10 ms delay DELAY10M: ; jsr=4cyles pshx ; 2 cycles ,save x ldx #9998 ; 2 cycles,delay 9998 usec + 2 for this routine jsr DELML01 ; call usec delay, this delay offset in sub pulx ; 3 cycles restore x rts ; 5 cycles ; ; ; Generate a 1 ms delay DELAY1MS: ; jsr=4cyles pshx ; 2 cycles ,save x ldx #998 ; 2 cycles,delay 9998 usec + 2 for this routine jsr DELML01 ; call usec delay, this delay offset in sub pulx ; 3 cycles restore x rts ; 5 cycles ; ; 8 cycles = 1 usec e = 8mhz DELML01: nop ; 1 cycle nop ; 1 cycle nop ; 1 cycle nop ; 1 cycle dex ; 1 cycle bne DELML01 ; 3 cycles rts ; 5 cycles ; ; ; ram variables LCDBUF: rmb 1 end