HD 44780 LCD programming From the Hardware Side

  • Slides: 30
Download presentation
HD 44780 LCD programming From the Hardware Side Design and implementation details on the

HD 44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

To be tackled today l l l What commands are necessary to control the

To be tackled today l l l What commands are necessary to control the LCD device -- HD 44780? How do you send commands from the Blackfin to a LCD device? How do we get the timing correct? 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 2 / 30

LCD Connection information l 13 key connections 3/6/2021 SPI and LCD , Copyright M.

LCD Connection information l 13 key connections 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 3 / 30

Data Bus Connections for LCD screen From CJ 7 connector on Blackfin interface BQ

Data Bus Connections for LCD screen From CJ 7 connector on Blackfin interface BQ 0 BQ 1 BQ 2 BQ 3 BQ 4 BQ 5 BQ 6 BQ 7 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 4 / 30

Power Connections for LCD screen From LOGIC LAB POWER GROUND +5 V 3/6/2021 SPI

Power Connections for LCD screen From LOGIC LAB POWER GROUND +5 V 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 5 / 30

LCD operations require certain values on RS, R/W* and DBx lines LCD COMMANDS Clear.

LCD operations require certain values on RS, R/W* and DBx lines LCD COMMANDS Clear. Screen( ) Cursor. Increase( ) Cursor. Move( ) Display. On( ) Write. Letter(value) Write. Letter(‘a’) Write. Letter(‘A’) 3/6/2021 RS R/W* DATA DB 7 to DB 0 0 0 1 1 1 0 0 0 0 x 01 0 x 05 0 x 10 0 x 0 B value 0 x 61 (ascii ‘a’) 0 x 41 (ascii ‘A’) SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 6 / 30

Control Line Connections for LCD screen From CJ 8 connector on Blackfin interface BQ

Control Line Connections for LCD screen From CJ 8 connector on Blackfin interface BQ 8 RS command (0) or data (1) control BQ 9 R/W* Read (1) from LCD Write (0) to LCD BQ 10 E Enable Normally 1 Transition 1 0 1 makes the LCD work (Meaning LCD ONLY accepts the command or data information after this line goes 1 0 1) 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 7 / 30

The “idea” of how to cause the LCD to -- Clear the screen LCD

The “idea” of how to cause the LCD to -- Clear the screen LCD COMMANDS Clear. Screen( ) RS R/W* DATA DB 7 to DB 0 0 x 01 That means we must send the following “voltage” signals to the LCD pins from the Blackfin RS 0 0 0 R/W E 0 1 0 0 0 1 DB 7 DB 6 DB 5 DB 4 DB 3 DB 2 DB 1 DB 0 0 0 0 1 // Enable. Strobe 0 0 0 0 1 // LCD reads on high to low And we must wait after sending each “signal” for sufficient time for the LCD to work. The LCD probably works 100000 times slower than Blackfin. 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 8 / 30

To cause the “slow” LCD to Clear the screen – Actual Code LCD COMMANDS

To cause the “slow” LCD to Clear the screen – Actual Code LCD COMMANDS Clear. Screen( ) RS R/W* DATA DB 7 to DB 0 0 x 01 That means we must send the following “voltage” signals to the LCD pins RS R/W E DB 7 DB 6 DB 5 DB 4 DB 3 DB 2 DB 1 DB 0 0 0 1 0 0 0 0 1 Waste. Some. Time. CPP( ) 0 0 0 0 0 1 // Enable. Stobe Waste. Some. Time. CPP( ) 0 0 1 0 0 0 0 1 Waste. Some. Time. CPP( ) 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 9 / 30

LCD Command Instruction set 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University

LCD Command Instruction set 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 10 / 30

Details of what is needed to make each LCD instruction in last slide work

Details of what is needed to make each LCD instruction in last slide work l These are “LCD” instructions NOT Blackfin instructions. We must code the Blackfin to send these instructions to LCD 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 11 / 30

LCD Command Instruction set For some commands the LCD is very slow 1. 640

LCD Command Instruction set For some commands the LCD is very slow 1. 640 ms For other commands the LCD is faster 0. 040 ms = 40 us Remember the Blackfin instruction is around 0. 000002 ms = 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 2 ns 12 / 30

To cause the LCD to Clear the screen LCD COMMANDS Clear. Screen( ) RS

To cause the LCD to Clear the screen LCD COMMANDS Clear. Screen( ) RS R/W DATA DB 7 to DB 0 0 x 01 That means we must send the following “voltage” signals to the LCD pins RS R/W E DB 7 DB 6 DB 5 DB 4 DB 3 DB 2 DB 1 DB 0 0 0 1 0 0 0 0 1 Wait(1. 64 ms ) -- Only one wait is really needed this long – Refactor later 0 0 0 0 0 1 // Enable. Stobe Wait( 1. 64 ms ) -- Only one wait is really needed this long – Refactor later 0 0 1 0 0 0 0 1 Wait( 1. 64 ms) -- Only wait is really needed this long – Refactor later Remember – when shorten down – still must worry about Speed 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 13 / 30

To cause the LCD to write the letter ‘A’ on its screen LCD COMMANDS

To cause the LCD to write the letter ‘A’ on its screen LCD COMMANDS Write. Letter(value) Write. Letter(‘a’) RS R/W DATA DB 7 to DB 0 1 1 0 0 value 0 x 61 That means we must send the following “voltage” signals to the LCD pins RS R/W E 1 0 1 Wait( 40 us) 1 0 0 Wait( 40 us) 1 0 1 Wait( 40 us) 3/6/2021 DB 7 DB 6 DB 5 DB 4 DB 3 DB 2 DB 1 DB 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 // Enable. Stobe SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 14 / 30

Bit patterns to send a character l l Complicated or not? How do the

Bit patterns to send a character l l Complicated or not? How do the letter bit patterns for the LCD data patterns relate to ASCII bit patterns? • • l l standard format used to store characters in a C++ character array? Just copy from an array onto the LCD data pins To cause “A” to appear on LCD screen need bit pattern 01000001 = 0 x 41 sent to LCD data pins Write. SPI(‘A’); Also send the necessary LCD control signals (EN / RS) 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 15 / 30

Alpha-numeric ascii code ‘A’ to ‘Z’, ‘a’ to ‘z’ 3/6/2021 SPI and LCD ,

Alpha-numeric ascii code ‘A’ to ‘Z’, ‘a’ to ‘z’ 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 16 / 30

Alpha-numeric ascii code 0 through 9, ( ) etc 3/6/2021 SPI and LCD ,

Alpha-numeric ascii code 0 through 9, ( ) etc 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 17 / 30

Problem – we need 22 lines (11 in / 11 out) to control LCD

Problem – we need 22 lines (11 in / 11 out) to control LCD – and we don’t have them on the Blackfin 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 18 / 30

Solution – Setup LCD as SLAVE device Master (Blackfin) / Slave (LCD) concept l

Solution – Setup LCD as SLAVE device Master (Blackfin) / Slave (LCD) concept l Will not work l LCD was set up as a PARALLEL DEVICE – many lines at one time l Not capable of MOSI control 3/6/2021 MOSI --MASTER OUT – SLAVE IN SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 19 / 30

Solution There is a standard chip (Name ? ? ? ) that is capable

Solution There is a standard chip (Name ? ? ? ) that is capable of l Receiving (serial) signals from the Blackfin over the MOSI wire l Converting those serial signals (16 signals -- received one at a time) into a parallel signal (16 signals -- sent all at once) l Sending the PARALLEL voltage signals to the LCD This chip has been designed into the Logic Station Blackfin interface (is not part of the Blackfin itself l All we need to do is attach 11 wires from the interface to the LED l Attach 4 wires from the interface to the Blackfin MOSI lines l Program the Blackfin SPI interface and “GO” 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 20 / 30

Lots of stuff has to happen in the correct order l Putting data into

Lots of stuff has to happen in the correct order l Putting data into the Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line “automatically” SPI_TDBR means Serial Peripheral Interface Transmit Data Buffer Register 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 21 / 30

Known facts -- MOSI data starts being transmitted from Blackfin THE MOMENT that ANY

Known facts -- MOSI data starts being transmitted from Blackfin THE MOMENT that ANY data is written to Blackfin SPI_TDBR register SPI_TDBR Blackfin Processor SLAVE SELECT PF 5 used (PF 1 to PF 7) MOSI SPI_RXBR SPI CLOCK MISO SLAVE OUTPUT INTERFACE SLAVE INPUT INTERFACE LOAD Slave to LCD CONTROL DATA LCD SCREEN CJ 7 / CJ 8 3/6/2021 SWITCHES (LOGIC LAB) SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 22 / 30

Lots of stuff has to happen in the correct order l Putting (8 -bit

Lots of stuff has to happen in the correct order l Putting (8 -bit parallel) data into the Blackfin SPI_TDBR register causes the (1 -bit serial) data to be transmitted over the MOSI line l However the external device will ignore the command unless the slave select line is held low 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 23 / 30

Known facts -- MOSI data is accepted by the SLAVE IF slave-select is active

Known facts -- MOSI data is accepted by the SLAVE IF slave-select is active low – set PF 5 to low – Master/Slave SPI_TDBR Blackfin Processor SLAVE SELECT PF 5 used (PF 1 to PF 7) MOSI SPI_RXBR SPI CLOCK MISO SLAVE OUTPUT INTERFACE SLAVE INPUT INTERFACE LOAD Slave to LCD CONTROL DATA LCD SCREEN CJ 7 / CJ 8 3/6/2021 SWITCHES (LOGIC LAB) SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 24 / 30

Lots of stuff has to happen in the correct order l Putting data into

Lots of stuff has to happen in the correct order l Putting data into the Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line l However the external device will ACCEPT the command if the slave select line PF 5 line is AUTOMATICALLY SET LOW by the Blackfin before the transmission is started. l When transmission is ended (16 -bits sent) then the slave select line PF 5 line is AUTOMATICALLY SET HIGH by the Blackfin or ? ? 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 25 / 30

Known facts – The SLAVE only sends the data to the LCD when the

Known facts – The SLAVE only sends the data to the LCD when the PF 5 line goes from low to high – interface design SPI_TDBR Blackfin Processor SLAVE SELECT PF 5 used (PF 1 to PF 7) MOSI SPI_RXBR SPI CLOCK MISO SLAVE OUTPUT INTERFACE SLAVE INPUT INTERFACE LOAD Slave to LCD CONTROL DATA LCD SCREEN CJ 7 / CJ 8 3/6/2021 SWITCHES (LOGIC LAB) SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 26 / 30

Lots of stuff has to happen in the correct order l Putting data into

Lots of stuff has to happen in the correct order l Putting data into the Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line l However the external device will ACCEPT the command as the slave select line PF 5 line is AUTOMATICALLY SET LOW by the Blackfin before the transmission is started. l When transmission is ended (16 -bits sent) then the slave select line PF 5 line is AUTOMATICALLY SET HIGH by the Blackfin l As PF 5 line goes high the data sent by the Blackfin over the MOSI line to the special interface is transferred to the LCD Everything in the garden is wonderful!!!!!!! ALL? we have to do is make it happen! 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 27 / 30

Blackfin transmits 16 bits with THIS format over the MOSI line DB 7, DB

Blackfin transmits 16 bits with THIS format over the MOSI line DB 7, DB 6, ………DB 1, DB 0 E – Enable / Strobe RS 1 0 – When this line goes from high to the low, then the command is send to (latched into) LCD 1 – LCD data 0 – LCD instruction R/W 1 – Read from LCD 0 – Write to LCD 3/6/2021 To make LCD respond to command 0 x 4 F 0 Then Blackfin must transmit 0 x 5 F 0 ( E High ) 0 x 4 F 0 ( E low ) 0 x 5 F 0 ( E high ) SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 28 / 30

Design the controls signals and data signals to ‘Clear the screen’ and then send

Design the controls signals and data signals to ‘Clear the screen’ and then send the char string “ 415” to LCD Reminder – sequence to sent the letter ‘a” to the screen RS 1 1 1 R/W 0 0 0 E 1 0 1 DB 7 DB 6 DB 5 DB 4 DB 3 DB 2 DB 1 DB 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 // Enable. Stobe Clear. Screen ‘ 4’ ‘ 1’ ‘ 5’ 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 29 / 30

Tackled today l l l What commands are necessary to control the LCD device

Tackled today l l l What commands are necessary to control the LCD device -- HD 44780? How do you send commands from the Blackfin to a LCD device? How do we get the timing correct? 3/6/2021 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada 30 / 30