Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Serial Peripheral Interface (SPI)

Similar presentations


Presentation on theme: "The Serial Peripheral Interface (SPI)"— Presentation transcript:

1 The Serial Peripheral Interface (SPI)
Lecture L4.5

2 Reference SPI Block Guide V03.06 S12SPIV3.pdf

3 PIM_9C32 Block Diagram SPI module

4

5

6

7 $DA

8

9

10 $D8

11 $D8

12

13

14 $D8

15 $D9

16 $D9

17 $DB

18 $DB

19 Liquid Crystal Display

20 Relationship between RS, R/W, and E

21

22 CLM912C32 LCD PORT 4-bit SPI Interface Write only

23

24 File: spi.asm ; Serial Peripheral Interface SPI0
SPI0CR equ 00D8 ; SPI Control Register 1 SPI0CR 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

25 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

26 SPI0CR1 $D8

27 ; 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 oraa #$80 ;EN HI jsr send_spi pula ;get A jsr send_spi ;EN LO pula ;restore A rts

28 ; Write 8-bit instruction in A
psha ;save A lsra bsr instr4 ;send hi nibble pula ;get A bsr instr4 ;send lo nibble rts

29 ; Write 4-bit data in A data4 psha ;save A anda #$0f oraa #$40 ;EN HI jsr send_spi ;EN LO, RS HI pula ;get A oraa #$C0 ;EN HI jsr send_spi psha oraa #$40 jsr send_spi ;EN LO pula pula ;restore A rts

30 ; Write 8-bit data in A data8 psha ;save A lsra bsr data4 ;send hi nibble pula ;get A bsr data4 ;send lo nibble rts 

31 ; Initialize 4-bit wide lcd_init ldy #50 jsr ms_delay ldaa #3 jsr instr4 ; function set ldaa #2 ldaa #$2C jsr instr8 ; 4-bits, 2 lines ldy #10 ldaa #$06 jsr instr8 ; inc cursor ldaa #$0f jsr instr8 ; display on ldaa #$01 jsr instr8 ; clear display ldy #20 ldaa #$80 jsr instr8 ; set addr to 0 ldaa #$00 jsr send_spi ; turn off all signals rts

32 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 ; 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

33 ; 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

34 1: ; lcdtest.asm 2: 3: = org $800 4: B 65 6C mess1 db 'Haskell',0 0806 6C 00 5: 6: = org $4000 7: 8: main 9: jsr spi_init 10: jsr lcd_init 11: CE ldx #mess1 12: A jsr type_lcd 13: C 3F swi

35 16 x 1 Hex Keypad

36


Download ppt "The Serial Peripheral Interface (SPI)"

Similar presentations


Ads by Google