第一步--熟悉硬件
流水燈的原理圖是這樣的
LCD的接口是這樣的
我在這里突然發(fā)現(xiàn)了一個(gè)問(wèn)題,就是LED和LCD怎么有公用的端口??!但是我仔細(xì)一看發(fā)現(xiàn),這LED是由一個(gè)鎖存器控制,LCD的控制芯片有一個(gè)CS片選信號(hào),感覺(jué)這個(gè)是控制著兩個(gè)模塊的使能的,那么不同時(shí)向LED和LCD寫數(shù)據(jù)不就行了?
所以控制思路也就有了,在向LCD寫數(shù)據(jù)的時(shí)候就使能LCD控制芯片,用完就失能它。這一步我發(fā)現(xiàn)給的例程已經(jīng)做了。但LED可沒(méi)有做,所以只能自己實(shí)現(xiàn)了,控制思路和LCD一樣,用的時(shí)候使能,用完就失能。
第二步--軟件設(shè)計(jì)
首先就是套用官方給的例程,有現(xiàn)成的不用豈不是浪費(fèi)。然后初始化一下PD2口。下面就是PD2的初始化函數(shù)。
void LED_Enable_gpio_cofig(void)
{
GPIO_InitTypeDef GPIO_Strue;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
GPIO_Strue.GPIO_Pin = GPIO_Pin_2;
GPIO_Strue.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Strue.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_Strue);
//先關(guān)了燈
GPIO_SetBits(GPIOD, GPIO_Pin_2);
GPIO_Write(GPIOC,0Xff00);
GPIO_ResetBits(GPIOD, GPIO_Pin_2);
}
為了好記我把使能失能宏定義一下
#define LED_ENABLE() GPIO_SetBits(GPIOD, GPIO_Pin_2)
#define LED_DISENABLE() GPIO_ResetBits(GPIOD, GPIO_Pin_2)
延時(shí)函數(shù)就用例程帶的。
建立一個(gè)流水燈數(shù)組
uint16_t led_buff[][8] = {0xfe00, 0xfd00, 0xfb00, 0xf700, 0xef00, 0xdf00, 0xbf00, 0x7f00,
0x7f00, 0xbf00, 0xdf00, 0xef00, 0xf700, 0xfb00, 0xfd00, 0xfe00,
0x7e00, 0xbd00, 0xdb00, 0xe700, 0xe700, 0xc300, 0x8100, 0x0000,
0xe700, 0xdb00, 0xbd00, 0x7e00, 0x7e00, 0x3c00, 0x1800, 0x0000};
最后的過(guò)程就很簡(jiǎn)單了看一下mian函數(shù)吧
int main(void)
{
uint8_t i;
SysTick_Config(SystemCoreClock/1000);
//Delay_Ms(200);
STM3210B_LCD_Init();
LED_Enable_gpio_cofig();
LCD_Clear(Black);
LCD_SetBackColor(Black);
LCD_SetTextColor(White);
LCD_DisplayStringLine(Line1 ,(unsigned char *)" Flowled test");
LCD_SetBackColor(Yellow);
LCD_DisplayStringLine(Line2 ,(unsigned char *)"Flowled mode 1 test.");
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line3 ,(unsigned char *)"Flowled mode 2 test.");
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line4 ,(unsigned char *)"Flowled mode 3 test.");
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line5 ,(unsigned char *)"Flowled mode 4 test.");
LED_ENABLE();
for(i = 0; i < 8; i ++)
{
GPIO_Write(GPIOC,led_buff[0][i]);
Delay_Ms(200);
}
GPIO_Write(GPIOC,0Xff00);
LED_DISENABLE();
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line2 ,(unsigned char *)"Flowled mode 1 test.");
LCD_SetBackColor(Yellow);
LCD_DisplayStringLine(Line3 ,(unsigned char *)"Flowled mode 2 test.");
LED_ENABLE();
for(i = 0; i < 8; i ++)
{
GPIO_Write(GPIOC,led_buff[1][i]);
Delay_Ms(200);
}
GPIO_Write(GPIOC,0Xff00);
LED_DISENABLE();
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line3 ,(unsigned char *)"Flowled mode 2 test.");
LCD_SetBackColor(Yellow);
LCD_DisplayStringLine(Line4 ,(unsigned char *)"Flowled mode 3 test.");
LED_ENABLE();
for(i = 0; i < 8; i ++)
{
GPIO_Write(GPIOC,led_buff[2][i]);
Delay_Ms(200);
}
GPIO_Write(GPIOC,0Xff00);
LED_DISENABLE();
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line4 ,(unsigned char *)"Flowled mode 3 test.");
LCD_SetBackColor(Yellow);
LCD_DisplayStringLine(Line5 ,(unsigned char *)"Flowled mode 4 test.");
LED_ENABLE();
for(i = 0; i < 8; i ++)
{
GPIO_Write(GPIOC,led_buff[2][i]);
Delay_Ms(200);
}
GPIO_Write(GPIOC,0Xff00);
LED_DISENABLE();
LCD_SetBackColor(Black);
LCD_DisplayStringLine(Line5 ,(unsigned char *)"Flowled mode 4 test.");
LCD_SetBackColor(Green);
LCD_DisplayStringLine(Line6 ,(unsigned char *)"Finshed!");
LCD_SetBackColor(Red);
LCD_DisplayStringLine(Line7 ,(unsigned char *)" ");
while(1);
}
-
led燈
+關(guān)注
關(guān)注
22文章
1592瀏覽量
107950 -
LCD屏
+關(guān)注
關(guān)注
0文章
122瀏覽量
15421 -
流水燈
+關(guān)注
關(guān)注
21文章
432瀏覽量
59692 -
LCD控制
+關(guān)注
關(guān)注
0文章
6瀏覽量
7905 -
延時(shí)器
+關(guān)注
關(guān)注
1文章
36瀏覽量
15097
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論