ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
the LCD initialization function. Our LCD init function will
follow the SSD1332 datasheet’s Configuration Command
Table definitions line by line:
void lcdInit(void)
{
clrRST;
HAL_Delay(200);
setRST;
HAL_Delay(500);
writeCmd(0xAE); // 10101111: set display
off
writeCmd(0xA4); // 10100100: set nomal
display(POR)
writeCmd(0x15); // 00010101: Set Column
address
writeCmd(0x00); // 00000000: A[6:0] sets
the column start address from 0-95, RESET=00d.
writeCmd(0x5F); // 01011111: B[6:0] sets
the column end address from 0-95 RESET=95d.
writeCmd(0x75); // 10000001: Set Row
Address
writeCmd(0x00); // 00000000: A[5:0] sets
the row start address from 0-63, RESET=00d.
writeCmd(0x3F); // 00111111: B[5:0] sets
the row end address from 0-63, RESET=63d.
writeCmd(0x87); // 10000111: Master
current Control
writeCmd(0x07); // 00000111: 00000000 to
00001111 for attenuation factor (less is more)
writeCmd(0x81); // 10000001: set contrast
control for color A
writeCmd(0xA0); // 11111111: contrast
set(select from 1 to 256)
writeCmd(0x82); // 10000010: set contrast
control for color B
writeCmd(0x60); // 11111111: contrast
set(select from 1 to 256)
writeCmd(0x83); // 10000011: set contrast
control for color C
writeCmd(0xB0); // 11111111: contrast
set(select from 1 to 256)
writeCmd(0xA0); // 10100000: set re-map &
data format
writeCmd(0x60); // 01100000:
a[7,6]:01:65k color format(por)CCCCCBBBBBBAAAAA
00:256 color formatCCCBBBAA
writeCmd(0xA1); // 10100001: set display
start line
writeCmd(0x00);
writeCmd(0xA2); // 10100010: set display
offset
writeCmd(0x00);
writeCmd(0xA8); // 10101000: set
multiplex ratio
writeCmd(0x3F);
writeCmd(0xB0); // set power save
writeCmd(0x00); // 0x12:power saving mode
writeCmd(0xB1); // phase 1 and period
adjustment(discharge,charge)
writeCmd(0x74);
writeCmd(0xB3); // display clock divider/
oscillator frequency
writeCmd(0xD0);
writeCmd(0xBB); // set vpa
writeCmd(0x1F);
writeCmd(0xBC); // set vpb
writeCmd(0x1F);
writeCmd(0xBD); // set vpc
writeCmd(0x1F);
writeCmd(0xBE); // set vcomh
writeCmd(0x3F);
writeCmd(0xAD); // 10101101: set contrast
control for color A
writeCmd(0x8E); // 11111111: contrast
set(select from 1 to 256)
writeCmd(0xAF); // display on
}
Right now, we have code that will:
y Initialize the STM32F030R8T6 peripherals
y Set up the STM32F030R8T6 system clock
y Set up the STM32F030R8T6 Sys Tick
y Initialize the STM32F030R8T6 GPIO
y Initialize the STM32F030R8T6 SPI portal
y Initialize the CFAL9664B-F-B1
y Send commands and data to the CFAL9664B-F-B1
Not too shabby.
Raising the Flag
Let’s add some functions that will allow us to draw an
American flag on our little LCD. We’ll need to be able to
draw rectangles and fill them with a desired color. We’ll
also need to be able to color in individual pixels on the
display.
Here’s a function that draws and fills a rectangular area
on the LCD:
void drawRect(uint8_t colStart,uint8_t
rowStart,uint8_t colEnd,uint8_t rowEnd,uint8_t
colorOutlineR,uint8_t colorOutlineG,uint8_t
colorOutlineB,uint8_t colorFillR,uint8_t
colorFillG,uint8_t colorFillB)
{
writeCmd(0x22);
March 2018 59