#include <reg52.h>
#define wei P2
#define seg P0
sbit P3_0 = P3^0;
sbit P3_1 = P3^1;
sbit P3_2 = P3^2;
sbit P3_3 = P3^3;
unsigned char code smgduan[18]={0x00, 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code smgwei[8] = {0x00, 0x04,0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c};
void DelayUs2x(unsigned int n)//t = 2*n + 6 us
{
while(--n);
}
void DelayMs(unsigned int n)//t = n ms
{
while(n--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
int disp(unsigned char i) //按键抢答
{
//while(1)
//{
if(P3_3 == 0)
{
DelayMs(1);
if(P3_3 == 0)
{
if(i == 0 || i == 5)
{
i = 4;
return i;
}
}
while(P3_3 == 0);
}
else if(P3_2 == 0)
{
DelayMs(1);
if(P3_2 == 0)
{
if(i == 0 || i == 5)
{
i =3;
return i;
}
}
while(P3_2 == 0);
}
else if(P3_0 == 0)
{
DelayMs(1);
if(P3_0 == 0)
{
if(i == 0 || i == 5)
{
i = 2;
return i;
51单片机简易抢答器
最新推荐文章于 2024-01-03 13:41:47 发布