#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uint l,k,Count;
uchar sd,fx,df,a,b;
uchar LED_Buffer[2] = {0};
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void yan(i)//延时1us
{
while(i--);
}
void Delay(uint i)//延时1ms
{
uchar x,j;
for(j=0;j<i;j++)
for(x=0;x<=148;x++);
}
void
time0_Init()//定时器2
{
RCAP2H = (65536-50000)/256;//晶振12M 50ms 16bit 自动重载
RCAP2L = (65536-50000)%256;
ET2=1; //打开定时器中断
EA=1; //打开总中断
TR2=1; //打开定时器开关
}
void Time0_Int() interrupt 5 using 1
{
TF2=0;
Count++; //长度加1
}
void jishu()//计数器0
{
TMOD = 0x06;
TH0 = 0xff;
TL0 = 0xff;
ET0=1;
EA=1;
TR0 = 1;
}
void ji() interrupt 1 using 1
{
k++;
}
void chuan() interrupt 4
{
static uchar i = 1;
EA = 0;
if(RI == 1)
{
LED_Buffer
= SBUF ;
RI = 0;
if(i==0) i = 2;
i--;
}
EA = 1;
}
void chuankou()//串口
{
TMOD = 0x20; //定时器1,工作方式2
PCON = 0x00;
SCON = 0x50;
TH1 = 0xFd; //设置波特率 9600
TL1 = 0xFd;
TR1 = 1; //启动定时器1
ES = 1; //开串口中断
EA = 1; //开总中断
}
void main()
{
Time0_Init();
chuankou();
jishu();
while(1)
{
P1=0X10;
Delay(5);
P1=0X00;
Delay(5);
if( Count==20)
{
Count=0;
l=k;
k=0;
}
P0=table[(l%10000)/1000];
P2=4;
yan(10);
P0=table[(l%1000)/100];
P2=5;
yan(10);
P0=table[(l%100)/10];
P2=6;
yan(10);
P0=table[l%10];
P2=7;
yan(10);
df=LED_Buffer[0];
fx=LED_Buffer[1];
sd=15/df;
a=df/10;
b=df%10;
P0 = table[a];
P2 = 0;
yan(10);
P0 = table;
P2 = 1;
yan(10);
}
}
为什么这个程序主函数中引用子函数时chuankou(); jishu(); 只有放在后面的一个能起作用,前面的一个不起作用
一周热门 更多>