360 likes | 476 Views
The Serial Peripheral Interface (SPI). Lecture L4.5. Reference. SPI Block Guide V03.06. S12SPIV3.pdf. PIM_9C32 Block Diagram. SPI module. $DA. $D8. $D8. $D8. $D9. $D9. $DB. $DB. Liquid Crystal Display. Relationship between RS, R/W, and E. CLM912C32 LCD PORT 4-bit SPI
E N D
The Serial Peripheral Interface (SPI) Lecture L4.5
Reference SPI Block Guide V03.06 S12SPIV3.pdf
PIM_9C32 Block Diagram SPI module
CLM912C32 LCD PORT 4-bit SPI Interface Write only
File: spi.asm ; Serial Peripheral Interface SPI0 SPI0CR1 equ 00D8 ; SPI Control Register 1 SPI0CR2 equ 00D9 ; SPI Control Register 1 SPI0BR equ 00DA ; SPI Baud Rate Register SPI0SR equ 00DB ; SPI Status Register SP0DR equ 00DD ; SPI Data Register spi_init ; Initialize SPI port ldaa #$10 staa SPI0CR2 ; enable /SS clr SPI0BR ; 4 MHz (/2) ldaa #$52 staa SPI0CR1 ; CPHA = 0, CPO; = 0 rts
File: spi.asm (cont.) ; send A out spi send_spi psha ; save A ss0 ldaa SPI0SR anda #$20 beq ss0 ; wait for trans. buff empty pula ; get A psha ; save it again staa SP0DR ; send char ss1 ldaa SPI0SR anda #$80 beq ss1 ; wait till sent ldaa SP0DR ; clear SPIF pula ; restore A rts
SPI0CR1 $D8
; LCD for Axiom CML9S12-C32 #include hex2asc.asm #include spi.asm #include ms_delay.asm ; Write 4-bit instruction in A instr4 psha ;save A anda #$0f jsr send_spi ;EN LO, RS LO psha ;save A oraa #$80 ;EN HI jsr send_spi pula ;get A jsr send_spi ;EN LO pula ;restore A rts
; Write 8-bit instruction in A instr8 psha ;save A lsra lsra lsra lsra bsr instr4 ;send hi nibble pula ;get A bsr instr4 ;send lo nibble rts
; Write 4-bit data in A data4 psha ;save A anda #$0f psha ;save A oraa #$40 ;EN HI jsr send_spi ;EN LO, RS HI pula ;get A psha ;save A oraa #$C0 ;EN HI jsr send_spi pula ;get A psha oraa #$40 jsr send_spi ;EN LO pula pula ;restore A rts
; Write 8-bit data in A data8 psha ;save A lsra lsra lsra lsra bsr data4 ;send hi nibble pula ;get A bsr data4 ;send lo nibble rts
; Initialize 4-bit wide lcd_init ldy #50 jsr ms_delay ldaa #3 jsr instr4 ; function set ldy #50 jsr ms_delay ldaa #3 jsr instr4 ; function set ldy #50 jsr ms_delay ldaa #3 jsr instr4 ; function set ldy #50 jsr ms_delay ldaa #2 jsr instr4 ; function set ldy #50 jsr ms_delay ldaa #$2C jsr instr8 ; 4-bits, 2 lines ldy #10 jsr ms_delay ldaa #$06 jsr instr8 ; inc cursor ldy #10 jsr ms_delay ldaa #$0f jsr instr8 ; display on ldy #10 jsr ms_delay ldaa #$01 jsr instr8 ; clear display ldy #20 jsr ms_delay ldaa #$80 jsr instr8 ; set addr to 0 ldy #10 jsr ms_delay ldaa #$00 jsr send_spi ; turn off all signals rts
clear_lcd ldaa #1 jsr instr8 ldy #10 jsr ms_delay rts ; display hex value in A on LCD hex2lcd jsr hex2asc ;convert to ascii jsr data8 ;display it rts ; display asciiz string on LCD ; X -> asciiz string type_lcd ldaa 1,x+ ;get next char beq done ;if null, quit jsr data8 ;else display it ldy #10 jsr ms_delay ; delay 10 ms bra type_lcd ;and repeat done rts
; lcdtest.asm org $800 mess1 db 'Haskell',0 org $4000 main jsr spi_init jsr lcd_init ldx #mess1 jsr type_lcd swi #include lcd.asm
1: ; lcdtest.asm 2: 3: =00000800 org $800 4: 0800 48 61 73 6B 65 6C mess1 db 'Haskell',0 0806 6C 00 5: 6: =00004000 org $4000 7: 8: 4000 main 9: 4000 16 4019 jsr spi_init 10: 4003 16 4088 jsr lcd_init 11: 4006 CE 0800 ldx #mess1 12: 4009 16 410A jsr type_lcd 13: 400C 3F swi
16 x 1 Hex Keypad