hd44780 lcd programming from the hardware side design and implementation details on the way to a...

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

Post on 19-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

HD44780 LCD programming

From the Hardware Side

Design and implementation details on the way to a valid

SPI-LCD interface driver

Page 2: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

2 / 30

To be tackled today

What commands are necessary to control the LCD device -- HD44780?

How do you send commands from the Blackfin to a LCD device?

How do we get the timing correct?

Page 3: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

3 / 30

LCD Connection information

13 key connections

Page 4: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

4 / 30

Data Bus Connectionsfor LCD screen

From CJ7 connector on Blackfin interfaceBQ0BQ1BQ2BQ3BQ4BQ5BQ6BQ7

Page 5: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

5 / 30

Power Connections for LCD screen

From LOGIC LAB POWER

GROUND

+5V

Page 6: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

6 / 30

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

LCD COMMANDS

RS R/W* DATA DB7 to DB0

ClearScreen( ) 0 0 0x01

CursorIncrease( ) 0 0 0x05

CursorMove( ) 0 0 0x10

DisplayOn( ) 0 0 0x0B

WriteLetter(value) 1 0 value

WriteLetter(‘a’) 1 0 0x61 (ascii ‘a’)

WriteLetter(‘A’) 1 0 0x41 (ascii ‘A’)

Page 7: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

7 / 30

Control Line Connectionsfor LCD screen

From CJ8 connector on Blackfin interface

BQ8 RS command (0) or data (1) control

BQ9 R/W* Read (1) from LCD Write (0) to LCD

BQ10 E EnableNormally 1

Transition 1 0makes the LCD work (accept the command or data information)

Page 8: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

8 / 30

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

LCD COMMANDS

RS R/W* DATA DB7 to DB0

ClearScreen( ) 0 0 0x01

That means we must send the following “voltage” signals to the LCD pins

RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB00 0 1 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 1 // EnableStrobe0 0 1 0 0 0 0 0 0 0 1

And we must wait after sending each “signal” for sufficient time for the LCDto work. The LCD probably works 100000 times slower than Blackfin.

Page 9: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

9 / 30

To cause the “slow” LCD to Clear the screen

LCD COMMANDS

RS R/W* DATA DB7 to DB0

ClearScreen( ) 0 0 0x01

That means we must send the following “voltage” signals to the LCD pins

RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB00 0 1 0 0 0 0 0 0 0 1Wait( )0 0 0 0 0 0 0 0 0 0 1 // EnableStobeWait( )0 0 1 0 0 0 0 0 0 0 1Wait( )

Page 10: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

10 / 30

LCD Command Instruction set

Page 11: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

11 / 30

Details of what is needed

Page 12: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

12 / 30

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 = 2 ns

Page 13: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

13 / 30

To cause the LCD to Clear the screen

LCD COMMANDS

RS R/W DATA DB7 to DB0

ClearScreen( ) 0 0 0x01

That means we must send the following “voltage” signals to the LCD pins

RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB00 0 1 0 0 0 0 0 0 0 1Wait(1.64 ms ) -- Only one of these is really needed this long – Refactor later0 0 0 0 0 0 0 0 0 0 1 // EnableStobeWait( 1.64 ms ) -- Only one of these is really needed this long – Refactor later0 0 1 0 0 0 0 0 0 0 1Wait( 1.64 ms) -- Only one of these is really needed this long – Refactor later Remember – when shorten down – still must worry about Speed

Page 14: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

14 / 30

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

LCD COMMANDS

RS R/W DATA DB7 to DB0

WriteLetter(value) 1 0 value

WriteLetter(‘a’) 1 0 0x61That means we must send the following “voltage” signals to the LCD pins

RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB01 0 1 0 1 1 0 0 0 0 1Wait( 40 us)1 0 0 0 1 1 0 0 0 0 1 // EnableStobeWait( 40 us)1 0 1 0 1 1 0 0 0 0 1Wait( 40 us)

Page 15: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

15 / 30

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

patterns for the LCD data patterns relate to ASCII bit patterns? • 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 = 0x41sent to LCD data pins WriteSPI(‘A’);

Also send the necessary LCD control signals (EN / RS)

Page 16: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

16 / 30

Alpha-numeric ascii code‘A’ to ‘Z’, ‘a’ to ‘z’

Page 17: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

17 / 30

Alpha-numeric ascii code 0 through 9, ( ) etc

Page 18: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

18 / 30

Problem – we need 22 lines (in / out) to control LCD – and we don’t have them on the Blackfin

Page 19: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

19 / 30

Solution – Setup LCD as SLAVE deviceMaster (Blackfin) / Slave (LCD) concept

Will not work

LCD was set up as a PARALLEL DEVICE – many lines at one time

Not capable of MOSI control

MOSI --MASTER OUT – SLAVE IN

Page 20: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

20 / 30

Solution There is a standard chip (Name ?????) that is capable of Receiving (serial) signals from the Blackfin over the MOSI wire Converting those serial signals

(16 signals -- received one at a time) into a parallel signal (16 signals -- sent all at once)

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

All we need to do is attach 11 wires from the interface to the LED

Attach 4 wires from the interface to the Blackfin MOSI lines Program the Blackfin SPI interface and “GO”

Page 21: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

21 / 30

Lots of stuff has to happen in the correct order

Putting data into the Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line

SPI_TDBR meansSerial Parallel Interface Transmit Data Buffer Register

Page 22: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

22 / 30

Known facts -- MOSI data is transmitted from Blackfin the moment that data is written to Blackfin SPI_TDBR register

SPI_TDBR Blackfin Processor SPI_RXBR

LCD SCREEN CJ7 / CJ8 SWITCHES (LOGIC LAB)

SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE

MOSI MISO

SLAVE SELECTPF5 used (PF1 to PF7)

DATACONTROL

SPICLOCK

LOADSlave toLCD

Page 23: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

23 / 30

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

Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line

However the external device will ignore the command unless the slave select line is held

low

Page 24: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

24 / 30

Known facts -- MOSI data is accepted by the SLAVE if slave-select is active low – set PF5 to low – Master/Slave

SPI_TDBR Blackfin Processor SPI_RXBR

LCD SCREEN CJ7 / CJ8 SWITCHES (LOGIC LAB)

SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE

MOSI MISO

SLAVE SELECTPF5 used (PF1 to PF7)

DATACONTROL

SPICLOCK

LOADSlave toLCD

Page 25: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

25 / 30

Lots of stuff has to happen in the correct order Putting data into the Blackfin SPI_TDBR register

causes the data to be transmitted over the MOSI line

However the external device will ACCEPTS the command as the slave select line PF5 line is AUTOMATICALLY SET LOW by the Blackfin before the transmission is started.

When transmission is ended (16-bits sent) then the slave select line PF5 line is AUTOMATICALLY SET

HIGH by the Blackfin or ????

Page 26: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

26 / 30

Known facts – The SLAVE only sends the data to the LCD when the PF5 line goes from low to high – interface design

SPI_TDBR Blackfin Processor SPI_RXBR

LCD SCREEN CJ7 / CJ8 SWITCHES (LOGIC LAB)

SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE

MOSI MISO

SLAVE SELECTPF5 used (PF1 to PF7)

DATACONTROL

SPICLOCK

LOADSlave toLCD

Page 27: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

27 / 30

Lots of stuff has to happen in the correct order Putting data into the Blackfin SPI_TDBR register causes the data to be

transmitted over the MOSI line

However the external device will ACCEPT the command as the slave select line PF5 line is AUTOMATICALLY SET LOW by the Blackfin before the transmission is started.

When transmission is ended (16-bits sent) then the slave select line PF5 line is AUTOMATICALLY SET HIGH by the Blackfin

As PF5 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!

Page 28: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

28 / 30

Blackfin transmits 16 bits with THIS format over the MOSI line

DB7, DB6, ………DB1, DB0

RS

1 – LCD data

0 – LCD instruction

R/W

1 – Read from LCD

0 – Write to LCD

E – Enable / Strobe

1 0 – When this line goes from high to the low, then the command is send to (latched into) LCD

To make LCD respond to command 0x4F0Then Blackfin must transmit 0x5F0 ( E High )0x4F0 ( E low )0x5F0 ( E high )

Page 29: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

29 / 30

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 screenRS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB01 0 1 0 1 1 0 0 0 0 11 0 0 0 1 1 0 0 0 0 1 // EnableStobe1 0 1 0 1 1 0 0 0 0 1

ClearScreen

‘4’

‘1’

‘5’

Page 30: HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver

04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

30 / 30

Tackled today

What commands are necessary to control the LCD device -- HD44780?

How do you send commands from the Blackfin to a LCD device?

How do we get the timing correct?