|
寫了一天都沒寫對,比賽馬上要結(jié)束了,給為大哥有沒有寫過的,救救小弟吧!
ps:
這是我寫的,能不能看看哪錯了啊
#include <REGX51.H>
#include<intrins.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
sbit SENSOR=P0^0;
sbit LED1=P2^3;
sbit LED2=P2^2;
sbit LED3=P2^1;
sbit LED4=P2^0;
sbit a=P1^0;
sbit b=P1^1;
sbit c=P1^2;
sbit d=P1^3;
sbit e=P1^4;
sbit f=P1^5;
sbit g=P1^6;
sbit dp=P1^7;
unsigned int n=10;
unsigned int KEY_NUM=0;
int count=0;
int state=0;
bit flag=0;
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0X7f,0x6F
unsigned char dat[]={0,0,0,0};
void Delay()
{
unsigned int i,j;
for(i=0;i<n;i++ )
for(j=0;j<123;j++);
}
void scanSensor()
{
if(SENSOR==1)
{
Delay();
if(SENSOR==1)
{
while(SENSOR==1);
KEY_NUM=1;
}
}
}
void main()
{
while(1)
{
scanSensor();
if(KEY_NUM==1)
{
KEY_NUM=0;
{
dat[0]=count%10000/1000+0x30;
dat[1]=count%1000/100+0x30;
dat[2]=count%100/10+0x30;
dat[3]=count%10+0x30;
LED1=0;
P1=tab[dat[0]]+0x80;
Delay();
LED1=1;
LED2=0;
P1=tab[dat[1]];
Delay();
LED2=1;
LED3=0;
P1=tab[dat[2]];
Delay();
LED3=1;
LED4=0;
P1=tab[dat[3]];
Delay();
LED4=1;
}
count++;
if(state==2)
state=0;
}
}
}
|
|