一个单片机的仿真程序,哪位大神帮帮我解释下每步骤的含义是什么,押上全部财富

#include <AT89X52.H>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;

void main(void)
{
unsigned char i;

TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;

while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<8;i++)
{
temp[i]=0;
}
i=0;
while(x/10)
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;
for(i=0;i<6;i++)
{
dispbuf[i]=temp[i];
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
}
}

void t0(void) interrupt 1 using 0
{
T0count++;
}

void t1(void) interrupt 3 using 0
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
timecount++;
if(timecount==200)
{
TR0=0;
timecount=0;
flag=1;
}
P2=0xff;
P0=dispcode[dispbuf[dispcount]];
P2=dispbit[dispcount];
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
这个是个数字频率计的仿真程序,可是我不懂每步是什么意思呀

第1个回答  2014-05-06
unsigned char code dispbit[] 定义数组 dispbit 且存放到CODE 内存空间
bit 位变量

主程序中

TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;

设置定时器 开中断
for(i=0;i<8;i++)
{
temp[i]=0;
}
i=0;
初始化TEMP数组
while(x/10)
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;

举例 如果X=5462 那么tempp[0]=2 tempp[1]=6 tempp[2]=4 tempp[3]=5 .......
for(i=0;i<6;i++)
{
dispbuf[i]=temp[i];
}
把要显示的TEMP 赋值到 dispbuf 中、
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
初始化定时器 且启动 定时

T0count++; 进入中断 计数器加一

void t1(void) interrupt 3 using 0
{
TH1=(65536-5000)/256; //
TL1=(65536-5000)%256; //
//设置定时器1
timecount++;//定时计数
if(timecount==200) //中断200次以后 停止定时器0
{
TR0=0;
timecount=0;
flag=1;
}
//以下是将数字 显示到数码管 或什么别的地方
P2=0xff;
P0=dispcode[dispbuf[dispcount]];
P2=dispbit[dispcount];
dispcount++;
if(dispcount==8) // 8位的
{
dispcount=0;
}
}本回答被提问者采纳
相似回答