//主要程序代码如下所示:
int main(void)
{
u8 key;
Stm32_Clock_Init(336,8,2,7);//设置时钟,168Mhz
delay_init(168); //延时初始化
uart_init(84,115200); //初始化串口波特率为115200
LED_Init(); //初始化LED
OLED_Init(); //初始化OLED
KEY_Init(); //初始化与按键连接的硬件接口
LED0=!LED0;
while(1)
{
key=KEY_Scan(0); //得到键值
if(key)
{
switch(key)
{
case KEY0_PRES:
OLED_ShowString(0,0,"music",12);
OLED_ShowString(0,10,"hello",12);
OLED_ShowString(0,20,"cycle",12);
OLED_ShowString(0,30,"world",12);
OLED_Refresh_Gram();//更新显示到OLED
delay_us(1000);
break;
case KEY1_PRES:
OLED_ShowString(0,0,"enter",12);
OLED_ShowString(0,10,"dream",12);
OLED_ShowString(0,20,"eager",12);
OLED_ShowString(0,30,"drink",12);
OLED_Refresh_Gram();//更新显示到OLED
delay_us(1000);
break;
case KEY2_PRES:
OLED_ShowString(0,0,"final",12);
OLED_ShowString(0,10,"flash",12);
OLED_ShowString(0,20,"float",12);
OLED_ShowString(0,30,"fruit",12);
OLED_Refresh_Gram();//更新显示到OLED
delay_us(1000);
break;
}
}else delay_ms(10);
}
}
全部程序51hei下载地址:
OLED显示实验(按键切换).7z
(110.45 KB, 下载次数: 130)
|