1 / 26

The Serial Peripheral Interface (SPI)

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

nova
Télécharger la présentation

The Serial Peripheral Interface (SPI)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Serial Peripheral Interface (SPI) Chapter 8 CML9S12-DP256

  2. PIM_9DP256 Block Diagram

  3. Liquid Crystal Display

  4. Relationship between RS, R/W, and E

  5. CLM912-DP256 LCD PORT 4-bit SPI Interface Write only

  6. 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

  7. \ 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 ;

  8. 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 ;

  9. \ 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

  10. : 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

More Related