Download presentation
Presentation is loading. Please wait.
Published bySherman Adam Wheeler Modified over 9 years ago
1
The Serial Peripheral Interface (SPI) Chapter 8 CML9S12-DP256
2
PIM_9DP256 Block Diagram
17
Liquid Crystal Display
18
Relationship between RS, R/W, and E
20
CLM912-DP256 LCD PORT 4-bit SPI Interface Write only
21
File: SPI0.WHP \Serial Peripheral Interface SPI0 HEX 00D8CONSTANT SPI0CR1 \ SPI Control Register 1 00D9CONSTANT SPI0CR2 \ SPI Control Register 1 00DACONSTANT SPI0BR \ SPI Baud Rate Register 00DBCONSTANT SPI0SR \ SPI Status Register 00DDCONSTANT 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
23
\ 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 ;
24
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 ;
25
\ 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
26
: 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.