lcd programming design and implementation details on the way to a valid spi-lcd interface driver
Post on 19-Dec-2015
217 views
TRANSCRIPT
LCD programming
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
To be tackled today
How do you send commands from the Blackfin to a LCD device?
What commands are necessary to control the LCD device -- HD44780?
How do we get the timing correct?
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
3
Functions we have now developed for Lab. 5 void Write_SPI_TDBR_ASM(ushort transmit_value);
• Write the value “transmit_value” to SPI TDBR register void ControlFLG5_ASM(ushort low_or_high)
• Activates FLS5 (select flag 5 bit)
• Sets FLG5 bit high or low as requested void WaitWhileSPIF_ASM(ushort low_or_high);
• Waits will SPI_STAT SPIF flag is low or high void Set_SPIregisters_ASM(ushort BAUD_SCALE) void Set_SIC_IMASK_ASM(ulong bit_to_set); void WriteSPI(ushort value) All we will need today
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
4
Master / Slave conceptMaster to Slave data movement Master sends out
information to slave on MOSI wire
Slave receives information from the master on MOSI wire
SLAVE IGNORES INFORMATION UNLESS SLAVE SELECT LINE IS ACTIVE
Information (bits) is clocked by SCLK signal. • 1-bit, 1 clock tick
MOSI --MASTER OUT – SLAVE IN
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
5
Now at the stage where we can do some experimenting with the hardware
We know that the following pins are “key” to the operation of the interface. • Place scope probes on these lines
MOSI – this will show the data being transmitted from the SPI interface
PF5 – chip select line• When this is pulled low, then the slave will accept any
data being transmitted, otherwise data is ignored• When this goes – low to high – then the serial data
transmitted to the slave is “latched” (converted into a parallel signal that is then sent to LCD as a data or a command request.
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
6
Known facts -- MOSI data is transmitted from Blackfin the moment that data is written to SPI_TDBR
Blackfin Processor
LCD SCREEN SWITCHES (LOGIC LAB)
SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE
MOSI MISO
SLAVE SELECTPF5 used (PF0 to PF7)
DATACONTROL
SPICLOCK
LOADSlave toLCD
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
7
Known facts -- MOSI data is accepted by the SLAVE if slave-select is active low – PF5 is low – Master/Slave
Blackfin Processor
LCD SCREEN SWITCHES (LOGIC LAB)
SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE
MOSI MISO
SLAVE SELECTPF5 used (PF0 to PF7)
DATACONTROL
SPICLOCK
LOADSlave toLCD
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
8
Known facts – The SLAVE only sends the data to the LCD when the PF5 line goes from low to high – interface design
Blackfin Processor
LCD SCREEN SWITCHES (LOGIC LAB)
SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE
MOSI MISO
SLAVE SELECTPF5 used (PF0 to PF7)
DATACONTROL
SPICLOCK
LOADSlave toLCD
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
9
Current Solutions and Problems
Change to C++ programs as no longer taking directly to the hardware
ClearScreen( ) { WriteSPI(0x0001); }WriteLetter(char letter) {WriteSPI(0x0200 | letter); Call CursorMoveASM}
CursorMove ( ) { WriteSPI( 0x????); } etc
•How do we stop the LCD device from accepting too many commands?•How do we know when the LCD device is ready for the next command?
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
10
ENABLE Signal
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
11
Enable signal Enable signal works on the high-to-low
transition Send required signal to interface means
• Required signal + enable signal high• Wait long enough for voltages to “settle” (stabilize)• Required signal + enable signal low
• This strobes the information into the LCD screen
• Wait long enough for LCD command to work• How long is “long enough”?
• Required signal + enable signal high• Avoid “race” conditions to make sure that we don’t loose
the signal
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
12
Hooking up the LCD
WATCH OUTDB lines are ordered L-to-R
LO to HIGHBut data bit connector lines are
labelled R-to-L
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
13
Blackfin transmits 16 bits with THIS format
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 )
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
14
LCD Instruction set
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
15
Current Solutions -- Instruction
Change to C++ programs as no longer taking directly to the hardware
#define ENABLE_BIT 0x100#define R_W_BIT 0x200#define DATA_BIT 0x400
ClearScreen( ) {#define ClearDisplayCommand 0x0001;
WriteSPI(ClearDisplayCommand | ENABLE_BIT); Wait till voltages settle WriteSPI(ClearDisplayCommand); Wait for command to finish (1.64 ms – Lab 3 s, ms, us timer)
WriteSPI(ClearDisplayCommand | ENABLE_BIT); }
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
16
Current Solutions -- Data
Change to C++ programs as no longer taking directly to the hardware
#define ENABLE_BIT 0x100 // Active low#define R_W_BIT 0x200#define DATA_BIT 0x400
WriteLetter( char letter) {
WriteSPI(letter | DATA_BIT | ENABLE_BIT); Wait till voltages settle WriteSPI(letter | DATA_BIT); Wait for command to finish (40 us – Lab 3 s, ms, us timer)
WriteSPI(letter | DATA_BIT | ENABLE_BIT); }
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
17
Some commands
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’)
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
18
SetUpDisplay( )
From the manual
Send command 0x30 – wait 4 ms Send command 0x30 – wait 4 ms Send command 0x3C – wait 4 ms Send command 0x3C – wait 4 ms
Don’t forget to send the command to “activate the screen” -- LCDDisplay(ushort On_or_OFF);
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
19
You write the code for
LCDDisplay(ushort On_or_OFF); CursorMove(ushort left_or_right);
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
20
This was the solution of writing “Hello” to LCD
SetUpDisplay( ); EnableDisplay( );ClearDisplay( );
UseFixedTimeASM( );CursorIncrease( ); UseFixedTimeASM( );DisplayOn( );
Use FixedTimeASM( );WriteLetter(‘H’); UseFixedTimeASM( );CursorMove( ); UseFixedTimeASM( );WriteLetter(‘e’); etc.
General concept was there,
Now fix the solution to write
“Happy Christmas” to LCD screen
Except for the wiring and demoLab. 5 is essentially done
Note: As of 24th October theSPI interface was unstable
for input to BlackfinDON’T connect input interface
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
21
Details of what is needed
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
22
Data to send a character Complicated or not? To cause “A” to appear on
LCD screen need bit pattern 01000001 = 0x41sent to LCD data pins
Also send the necessary LCD control signals
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?
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
23
Now complete part of Lab. 4LCD as video screen
Now play the video game by moving the cursor on the LCD screen• Minimum requirements
• Move the cursor in response to temperature changes
• Print “player 1” wins if cursor moves all the way to the right
• Print “player 2” wins if cursor moves all the way to the left
04/18/23 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
24
Information taken from Analog Devices On-line Manuals with permission http://www.analog.com/processors/resources/technicalLibrary/manuals/
Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright Analog Devices, Inc. All rights reserved.