写出STC12C5A60S2单片机的一个kile5编程,要求:按下第一排第一个按键时形成流水灯;按下第一排第二个按键时形成呼吸灯;按下第一排第三个按键时蜂鸣器发出救护车声音;按下第二排第一个按钮时1602LED显示屏显示出“hallo”字样。
时间: 2023-03-09 18:08:16 浏览: 155
呼吸灯STC12C5A60S2
4星 · 用户满意度95%
#include <STC12C5A60S2.h>
sbit P10 = P1^0;
sbit P11 = P1^1;
sbit P12 = P1^2;
sbit P21 = P2^1;
sbit P22 = P2^2;
sbit P23 = P2^3;
sbit P24 = P2^4;void main()
{
P2 = 0x00;
while(1)
{
if(P10 == 0) //当按下第一排第一个按键时
{
P1 = 0x01; //形成流水灯
delay(500);
P1 = 0x02;
delay(500);
P1 = 0x04;
delay(500);
}
if(P11 == 0) //当按下第一排第二个按键时
{
int i;
for(i=0;i<3;i++)
{
P1 = 0x02; //形成呼吸灯
delay(500);
P1 = 0x00;
delay(500);
}
}
if(P12 == 0) //当按下第一排第三个按键时
{
int j;
for(j=0;j<2;j++)
{
P22 = 1; //蜂鸣器发出救护车声音
delay(500);
P22 = 0;
delay(500);
}
}
if(P21 == 0) //当按下第二排第一个按键时
{
P23 = 0;
P24 = 1;
delay(500);
P23 = 1;
P24 = 0;
delay(500);
P23 = 0;
P24 = 1;
delay(500);
P23 = 1;
P24 = 0;
delay(500);
P23 = 0;
P24 = 1;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 1;
P24 = 0;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 1;
P24 = 1;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 0;
P24 = 1;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 1;
P24 = 0;
delay(500);
P23 = 0;
P24 = 0;
delay(500);
P23 = 1;
P24 = 1;
delay(500);
P23 = 0;
P24 = 0;
}
}
}
阅读全文