Lecture 3 - GPIO Review, LCD Screen
Note that for A1, use HAL_Delay(ms)
since it's calibrated to actually count time accurately based on its internal clock.
Further, you may just want to use the SYSCLK
for now. There's certain clocks that slow down/speed up based on the temperature of the device.
One thing too is that don't use RCC_MSIRANGE_11
(at least for now), since it requires an overvoltage of the clocking mechanism.
Using the LCD Screen
Use [[HD44780.pdf]] and [[NHD-C0220AA-FSW-FTW.pdf]] for using the LCD screen:
- The former does a generally better job of using it
- We use the latter to explain how the device works
Check out [[NHD-C0220AA-FSW-FTW.pdf#pages=5]] for what we cover here. Some tidbits:
R/W
indicates if we want to read or write. Most likely you'll want to set it to write as it's an output.E
says whether or not the data on the bus is valid.- If you're in nibble mode:
- You save 4 pins on your LCD that are being used
- However, you have to write each hex character data separately (hex 1 then hex 2)
How do we write to this thing? See [[NHD-C0220AA-FSW-FTW.pdf#pages=8]]. Essentially, you need to set RS
, R/W
, ... as described before for the timings described in the chart. You can see the timings in the bottom chart.
We recommend that, at first, you build it slowly, by adding HAL_Delay
in many instruction spots in your code. This allows you to try to see if the logic works in a larger timeframe, and then you can slowly remove delays to see where things start to break.
Example
Let's use PA4
as RS
, PA5
as R/W
, PA6
as E
, and PC7:0
as DB
:
GPIOA->ODR &= ~(0x3 << 4); //clear both PA4 and PA5, RS RW are low
// can HAL_Delay if we don't meet the t_AS
GPIOA->ODR |= (0x1 << 6); // set PA6 as 1, E high
// potential HAL_Delay for t_{RE}
GPIOA->ODR &= ~(0xFF); // clears the bottom 8 bits
GPIOA->ODR |= (0xFF & DATA); // DATA is some 8 bit quantity
// wait more until t_{DS}, a total of t_{WHE} total from setting our E bit
GPIOA->ODR &= ~(0x1 << 6); // reset the value of PA6 as 0, E low
// maybe delay, either t_{AH} times
Okay we know how to write to it, now what do we write in the DATA
part?
See the [[NHD-C0220AA-FSW-FTW.pdf#pages=11]]. Here:
- We first pass
0x30
to theDATA
- Then we wait 100 ms
- Then we write
0x38
- ... (continue with
0x10, 0x0C, 0x06
)
Where are the Hex Codes coming from? Why [[NHD-C0220AA-FSW-FTW.pdf#pages=7]] of course!
For instance, for 0x30
is 00110000
, which says DB5
and DB4
are the only ones high. Use the instruction code if we are sending a command, and the bottom row if we are sending DATA
:
- So
0x30
isD
andC
, which sets the display on and the cursor display on. 0x38
isD
,C
, andB
, whihc blicks the cursor on (previously it was off)- ...
So #TODO: