程序如下:
#include<at89x52.h>
#define uchar unsigned char
#define uint unsigned uint
sbit k1=P3^2;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay10ms(uchar a)
{
uchar b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
void keyscan()
{
uint flag=0;
if(k2==0X00)
{
delay10ms(1);
if(k2==0X00)
{
P2=0xFF;
flag=!flag;
}
}
}
void main()
{
TMOD=0x02;
TH0=0xf6;
TL0=0xf6;
ET0=1;EA=1;
TR0=1;
while(1);
}
void time() interrupt 1 using 0
{
uint flag=0;
uchar temp;
uchar i;
if(flag==1)
{
temp=0x80;
for(i=0;i<4;i++)
{
P0=tab[i+1];
P2=~temp;
temp=temp>>1;
P2=0xff;
}
}
编译结果:
Build target 'Target 1'
assembling STARTUP.A51...
compiling 外部中断和定时器中断显示数码管(1234).c...
外部中断和定时器中断显示事牍埽?234).C(17): error C141: syntax error near 'flag'
外部中断和定时器中断显示事牍埽?234).C(39): error C141: syntax error near 'flag'
Target not created |