电子说
第一步--熟悉硬件
流水灯的原理图是这样的
LCD的接口是这样的
我在这里突然发现了一个问题,就是LED和LCD怎么有公用的端口!!但是我仔细一看发现,这LED是由一个锁存器控制,LCD的控制芯片有一个CS片选信号,感觉这个是控制着两个模块的使能的,那么不同时向LED和LCD写数据不就行了?
所以控制思路也就有了,在向LCD写数据的时候就使能LCD控制芯片,用完就失能它。这一步我发现给的例程已经做了。但LED可没有做,所以只能自己实现了,控制思路和LCD一样,用的时候使能,用完就失能。
第二步--软件设计
首先就是套用官方给的例程,有现成的不用岂不是浪费。然后初始化一下PD2口。下面就是PD2的初始化函数。
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);
//先关了灯
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)
延时函数就用例程带的。
建立一个流水灯数组
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};
最后的过程就很简单了看一下mian函数吧
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);
}
全部0条评论
快来发表一下你的评论吧 !