帮我设计单片机课程设计实验,用c语言程序写,题目是:抢答器,要求制作一个四人抢答器,4个灯跑马循环
发布网友
发布时间:2022-04-26 08:58
我来回答
共4个回答
热心网友
时间:2023-10-31 03:56
#define PlayerKey1_IO(P0.1)
#define PlayerKey2_IO(P0.2)
#define PlayerKey3_IO(P0.3)
#define PlayerKey4_IO(P0.4)
#define PlayerLED1_IO(P1.1)
#define PlayerLED2_IO(P1.2)
#define PlayerLED3_IO(P1.3)
#define PlayerLED4_IO(P1.4)
#define BuzzerEnable_IO(P1.5)
void SysInit(void)
{
//设置Key_io为上拉输入
//设置LED_io为通用输出
//设置BuzzerEnable_io为通用输出
}
unsigned char KeyScan(void)
{
if (PlayerKey1_IO == 0)return 1;
if (PlayerKey2_IO == 0)return 2;
if (PlayerKey3_IO == 0)return 3;
if (PlayerKey4_IO == 0)return 4;
return 0;
}
void Delay_Ms(unsigned char Nms)
{
volatile unsigned short tempcnt;
while (Nms--)
for (tempcnt = 0; tempcnt < 500; tempcnt++);//按照相应的参数配置计数上限,此处设为500
}
void main(void)
{
unsigned char MarqueeStep=0;
unsigned char KeyValue=0;
SysInit();
while (1)
{
Delay_Ms(400);
KeyValue = KeyScan();//无按键去抖
if (KeyValue == 0)
{
MarqueeStep++;
if (MarqueeStep > 4)MarqueeStep = 0;
BuzzerEnable_IO = 0;// 按键取消停止蜂鸣器发声
}
else
{
MarqueeStep = KeyValue;
BuzzerEnable_IO = 1;//蜂鸣器发声
}
PlayerLED1_IO = 0;
PlayerLED2_IO = 0;
PlayerLED3_IO = 0;
PlayerLED4_IO = 0;
if (MarqueeStep == 0)
PlayerLED1_IO = 1;
else if (MarqueeStep == 1)
PlayerLED2_IO = 1;
else if (MarqueeStep == 2)
PlayerLED3_IO = 1;
else if (MarqueeStep == 3)
PlayerLED4_IO = 1;
}
}
基础框架是这样。
热心网友
时间:2023-10-31 03:56
你写完了吗 我也需要
热心网友
时间:2023-10-31 03:57
你好!原理图有了吗?需不需要倒计时呢
热心网友
时间:2023-10-31 03:57
难度不大 有需要可以找我追问嗯嗯,先加个好友吧详谈0,0