260 likes | 386 Views
The Serial Peripheral Interface (SPI). Chapter 8 CML9S12-DP256. PIM_9DP256 Block Diagram. Liquid Crystal Display. Relationship between RS, R/W, and E. CLM912-DP256 LCD PORT 4-bit SPI Interface Write only. File: SPI0.WHP. Serial Peripheral Interface SPI0 HEX
E N D
The Serial Peripheral Interface (SPI) Chapter 8 CML9S12-DP256
PIM_9DP256 Block Diagram
CLM912-DP256 LCD PORT 4-bit SPI Interface Write only
File: SPI0.WHP \ Serial Peripheral Interface SPI0 HEX 00D8 CONSTANT SPI0CR1 \ SPI Control Register 1 00D9 CONSTANT SPI0CR2 \ SPI Control Register 1 00DA CONSTANT SPI0BR \ SPI Baud Rate Register 00DB CONSTANT SPI0SR \ SPI Status Register 00DD CONSTANT SP0DR \ SPI Data Register : SPI.INIT ( -- ) \ Initialize SPI port 10 SPI0CR2 C! \ enable /SS 00 SPI0BR C! \ 4 MHz (/2) 52 SPI0CR1 C! ; \ CPHA = 0, CPO; = 0 : ?SPI.DONE ( -- f ) \ Is SPI data sent? 7 SPI0SR ?HI ; : SEND.SPI ( c -- ) SP0DR C! \ send char BEGIN ?SPI.DONE \ wait till sent UNTIL SP0DR C@ DROP ; \ clear SPIF
\ LCD for Axiom CML9S12-DP256 load hex2asc.whp load string.whp load spi0.whp DECIMAL : 10ms.delay ( -- ) 7267 FOR NEXT ; : 20ms.delay ( -- ) 10ms.delay 10ms.delay ; : 50ms.delay ( -- ) 5 FOR 10ms.delay NEXT ;
HEX \ Write 4-bit instruction : >instr4 ( n -- ) 0F AND DUP send.spi \ EN LO, RS LO DUP 80 OR \ EN HI send.spi send.spi ; \ EN LO \ Write 8-bit instruction : >instr8 ( n -- ) DUP 4 RSHIFT >instr4 >instr4 ; \ Write 4-bit data : >data4 ( c -- ) 0F AND DUP 40 OR send.spi \ EN LO, RS HI DUP C0 OR send.spi \ EN HI 40 OR send.spi ; \ EN LO \ Write 8-bit data : >data8 ( n -- ) DUP 4 RSHIFT >data4 >data4 ;
\ Initialize 4-bit wide : lcd.init ( -- ) 50ms.delay 3 >instr4 \ function set 50ms.delay 3 >instr4 \ function set 50ms.delay 3 >instr4 \ function set 50ms.delay 2 >instr4 \ function set 50ms.delay 2C >instr8 \ 4-bits, 2 lines 10ms.delay 06 >instr8 \ inc cursor 10ms.delay 0f >instr8 \ display on 10ms.delay 01 >instr8 \ clear display 20ms.delay 80 >instr8 \ set addr to 0 10ms.delay 0 send.spi \ turn off all signals 0A BASE ! ; \ decimal default
: clear.lcd ( -- ) 1 >instr8 10ms.delay ; : hex>lcd ( hex -- ) HEX2ASC >data8 ; : type.lcd ( addr len -- ) ?DUP IF 0 DO DUP C@ >data8 10ms.delay 1+ LOOP THEN DROP ; : .lcd ( n -- ) (.) type.lcd ; : u.lcd ( u -- ) (u.) type.lcd ; DECIMAL