| MINI51DE_BSP V3.02.004 The Board Support Package for Mini51DE Series MCU

lcd_driver.c
Go to the documentation of this file.
1/**************************************************************************/
12#include "Mini51Series.h"
13#include "lcd_driver.h"
14
15 extern const char Ascii[];
16
22 static __INLINE void SpiWrite(uint32_t u32Data)
23{
24 SPI->TX = u32Data;
25 SPI->CNTRL |= SPI_CNTRL_GO_BUSY_Msk;
26 while((SPI->CNTRL & SPI_CNTRL_GO_BUSY_Msk));
27 SPI->CNTRL |= SPI_CNTRL_IF_Msk;
28}
29
35 void LCD_Init(void)
36{
37 /* Use SPI for LCD */
38 SYS->P0_MFP &= ~(SYS_MFP_P07_Msk | SYS_MFP_P06_Msk | SYS_MFP_P05_Msk | SYS_MFP_P04_Msk);
39 SYS->P0_MFP |= SYS_MFP_P07_SPICLK | SYS_MFP_P06_MISO | SYS_MFP_P05_MOSI | SYS_MFP_P04_SPISS;
40
41 CLK->APBCLK |= CLK_APBCLK_SPI_EN_Msk;
42
43 SYS->IPRSTC2 |= SYS_IPRSTC2_SPI_RST_Msk;
44 SYS->IPRSTC2 &= (~SYS_IPRSTC2_SPI_RST_Msk);
45
46 /* Initial SPI data format and SPI clock */
47 SPI->CNTRL = SPI_CNTRL_CLKP_Msk | SPI_CNTRL_TX_NEG_Msk | (9 << SPI_CNTRL_TX_BIT_LEN_Pos);
48 SPI->DIVIDER = (((12000000 / 2000000) + 1) >> 1) - 1;
49
50 /* Enable the automatic hardware slave select function. Select the SS pin and configure as low-active. */
51 SPI->SSR = SPI_SSR_AUTOSS_Msk | SPI_SSR_SSR_Msk ;
52
53 // Set BR
54 SpiWrite(0xEB);
55
56 // Set PM
57 SpiWrite(0x81);
58 SpiWrite(0xA0);
59
60 SpiWrite(0xC0);
61
62 // Set Display Enable
63 SpiWrite(0xAF);
64}
65
72 static void SetPACA(uint8_t PA, uint8_t CA)
73{
74 // Set PA
75 SpiWrite(0xB0 | PA);
76
77 // Set CA MSB
78 SpiWrite(0x10 | (CA >> 4) & 0xF);
79
80 // Set CA LSB
81 SpiWrite(0x00 | (CA & 0xF));
82}
83
91 static void ShowChar(uint8_t x, uint8_t y, uint8_t ascii_word)
92{
93 int i = 0, k = 0;
94 unsigned char temp;
95 k = (ascii_word - 32) * 16;
96
97 for (i = 0; i < 8; i++)
98 {
99 SetPACA((x*2), (129 - (y*8) - i));
100 temp = Ascii[k+i];
101 SpiWrite(0x100 | temp);
102 }
103
104 for (i = 0; i < 8; i++)
105 {
106 SetPACA((x*2) + 1, (129 - (y*8) - i));
107 temp = Ascii[k+i+8];
108 SpiWrite(0x100 | temp);
109 }
110}
111
117 void LCD_EnableBackLight(void)
118{
119 GPIO_SetMode(P5,0x10,GPIO_PMD_OUTPUT);
120 P54 = 0;
121}
122
128 void LCD_DisableBackLight(void)
129{
130 GPIO_SetMode(P5,0x10,GPIO_PMD_OUTPUT);
131 P54 = 1;
132}
133
140 void LCD_Print(uint8_t line, char *str)
141{
142 int i = 0;
143 do
144 {
145 ShowChar(line, i, *str++);
146 i++;
147 if (i > 15)
148 break;
149 }
150 while (*str != '\0');
151}
152
158 void LCD_ClearScreen(void)
159{
160 int i = 0;
161 /*CLEAR ALL PANEL*/
162 SetPACA(0x0, 0x0);
163
164 for (i = 0; i < 132 *8; i++)
165 {
166 SpiWrite(0x100);
167 }
168 SpiWrite(0x10f);
169}
170
171
Mini51Series.h
Mini51 series peripheral access layer header file. This file contains all the peripheral register's d...
SPI_CNTRL_TX_NEG_Msk
#define SPI_CNTRL_TX_NEG_Msk
Definition: Mini51Series.h:4507
SPI_CNTRL_IF_Msk
#define SPI_CNTRL_IF_Msk
Definition: Mini51Series.h:4522
SPI_SSR_SSR_Msk
#define SPI_SSR_SSR_Msk
Definition: Mini51Series.h:4552
SPI_SSR_AUTOSS_Msk
#define SPI_SSR_AUTOSS_Msk
Definition: Mini51Series.h:4558
SPI_CNTRL_CLKP_Msk
#define SPI_CNTRL_CLKP_Msk
Definition: Mini51Series.h:4516
SPI_CNTRL_TX_BIT_LEN_Pos
#define SPI_CNTRL_TX_BIT_LEN_Pos
Definition: Mini51Series.h:4509
SYS_IPRSTC2_SPI_RST_Msk
#define SYS_IPRSTC2_SPI_RST_Msk
Definition: Mini51Series.h:1581
SPI_CNTRL_GO_BUSY_Msk
#define SPI_CNTRL_GO_BUSY_Msk
Definition: Mini51Series.h:4501
CLK_APBCLK_SPI_EN_Msk
#define CLK_APBCLK_SPI_EN_Msk
Definition: Mini51Series.h:917
P54
#define P54
Definition: gpio.h:142
GPIO_PMD_OUTPUT
#define GPIO_PMD_OUTPUT
Definition: gpio.h:38
GPIO_SetMode
void GPIO_SetMode(GPIO_T *gpio, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO operation mode.
Definition: gpio.c:40
P5
#define P5
Pointer to GPIO port 5 register structure.
Definition: Mini51Series.h:5743
CLK
#define CLK
Pointer to CLK register structure.
Definition: Mini51Series.h:5736
SPI
#define SPI
Pointer to SPI register structure.
Definition: Mini51Series.h:5727
SYS
#define SYS
Pointer to SYS register structure.
Definition: Mini51Series.h:5735
SYS_MFP_P05_MOSI
#define SYS_MFP_P05_MOSI
Definition: sys.h:81
SYS_MFP_P07_SPICLK
#define SYS_MFP_P07_SPICLK
Definition: sys.h:89
SYS_MFP_P05_Msk
#define SYS_MFP_P05_Msk
Definition: sys.h:82
SYS_MFP_P04_SPISS
#define SYS_MFP_P04_SPISS
Definition: sys.h:76
SYS_MFP_P04_Msk
#define SYS_MFP_P04_Msk
Definition: sys.h:78
SYS_MFP_P07_Msk
#define SYS_MFP_P07_Msk
Definition: sys.h:90
SYS_MFP_P06_MISO
#define SYS_MFP_P06_MISO
Definition: sys.h:85
SYS_MFP_P06_Msk
#define SYS_MFP_P06_Msk
Definition: sys.h:86
ShowChar
static void ShowChar(uint8_t x, uint8_t y, uint8_t ascii_word)
Show a char on LCD.
Definition: lcd_driver.c:91
LCD_ClearScreen
void LCD_ClearScreen(void)
Clear screen to background color.
Definition: lcd_driver.c:158
Ascii
const char Ascii[]
Definition: ascii_table.c:14
SpiWrite
static __INLINE void SpiWrite(uint32_t u32Data)
Macro for SPI write method.
Definition: lcd_driver.c:22
LCD_EnableBackLight
void LCD_EnableBackLight(void)
Enable back-light of LCD.
Definition: lcd_driver.c:117
LCD_Print
void LCD_Print(uint8_t line, char *str)
Show a string on specific line.
Definition: lcd_driver.c:140
SetPACA
static void SetPACA(uint8_t PA, uint8_t CA)
Configure start address of LCD.
Definition: lcd_driver.c:72
LCD_Init
void LCD_Init(void)
Use SPI interface to configure LCD module.
Definition: lcd_driver.c:35
LCD_DisableBackLight
void LCD_DisableBackLight(void)
Disable back-light of LCD.
Definition: lcd_driver.c:128
lcd_driver.h