STM32簡(jiǎn)易交通燈設(shè)計(jì)(定時(shí)可調(diào))
//-----定時(shí)設(shè)置函數(shù)-------
void LED_SET_GREEN(u8 k)
{
LCD_ShowNum(160,235,k,2,16);
}
void LED_SET_YELLOW(u8 k)
{
LCD_ShowNum(160,145,k,2,16);
}
void LED_SET_RED(u8 k)
{
LCD_ShowNum(160,55,k,2,16);
}
//-----定時(shí)器中斷函數(shù)---掃描按鍵和顯示設(shè)定值用----
void TIM3_IRQHandler(void)
{
if(TIM3->SR&0x0001)
{
scan_key1();
scan_key2();
scan_key3();
LED_SET_RED(R);
LED_SET_GREEN(G);
LED_SET_YELLOW(Y);
}
TIM3->SR=~(1<<0);
}
//------主函數(shù)-----------
int main(void)
{
u16 code; //TFT驅(qū)動(dòng)芯片代號(hào)
int i;
Stm32_Clock_Init(9);
delay_init(72);
uart_init(72,9600);
printf("uart is ok. ");
Timer_init(300,7199); //定時(shí)器初始化 設(shè)定溢出時(shí)間是 30ms
printf("time_init is ok. ");
LCD_Init(); //TFT-LCD初始化
printf("lcd_init is ok.");
key_init(); //按鍵I/O口設(shè)置初始化
printf("key_init is ok.");
JTAG_Set(JTAG_SWD_DISABLE); //關(guān)閉JTAG調(diào)試器
code=LCD_ReadReg(0x0000);
delay_ms(500);
printf("deiver code is %ld",code); //讀取驅(qū)動(dòng)芯片型號(hào)是發(fā)送到串口
LCD_Fill(30,200,100,270,BLACK);
LCD_Fill(30,110,100,180,BLACK);
LCD_Fill(30,20,100,90,BLACK);
LCD_ShowString(110,15,"Show");
LCD_ShowString(110,30,"Time");
LCD_ShowString(160,15,"Set ");
LCD_ShowString(160,30,"Time");
LED_GREEN(0);
LED_YELLOW(0);
LED_RED(0);
while(1)
{
for(i=G;i>=0;i--) //綠燈控制
{
LED_GREEN(i);
LCD_Fill(30,200,100,270,GREEN);
delay_ms(1000);
LCD_Fill(30,200,100,270,BLACK);
delay_ms(1000);
}
for(i=Y;i>=0;i--) //黃燈控制
{
LED_YELLOW(i);
LCD_Fill(30,110,100,180,YELLOW);
delay_ms(1000);
LCD_Fill(30,110,100,180,BLACK);
delay_ms(1000);
}
for(i=R;i>=0;i--) //紅燈控制
{
LED_RED(i);
LCD_Fill(30,20,100,90,RED);
delay_ms(1000);
LCD_Fill(30,20,100,90,BLACK);
delay_ms(1000);
}
}
}
//-------各類庫(kù)函數(shù)省略---------
//-------各類庫(kù)函數(shù)省略---------
評(píng)論