高手帮我解答下单片机C语言每个语句的意思

具体程序如下
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
uchar bai,shi,ge,n,temp=120;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
void chushi()
{
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
P1=table[bai];
P2=table[shi];
P0=table[ge];
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;

}
void zhongduan() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
n++;
}
void xianshi(uchar bai,uchar shi,uchar ge)
{
P1=table[bai];
P2=table[shi];
P0=table[ge];
}

void main()
{

chushi();
while(1)
{
if(n==20)
{
n=0;
temp--;
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
if(temp<=0)
{
temp=120;
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
P1=table[bai];
P2=table[shi];
P0=table[ge];
}

}
xianshi(bai,shi,ge);
}
}

#include "reg51.h" //调用头文件reg51.h(内含有关单片机寄存器,端口的定义)
#define uchar unsigned char //宏定义 uchar表示unsigned char
#define uint unsigned int //宏定义 uint 表示unsigned int
uchar bai,shi,ge,n,temp=120; //定义 bai,shi,ge,n,temp 5个无符号字符型变量,初始值为120
uchar code table[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e}; //定义一个数组 LED数码管译码用的码表
void chushi() //定义初始化操作函数 (名称不太规范哦)
{
bai=temp/100; //bai 为temp除以100(取百位,因为temp是unsigned char数值范围0~255)
shi=temp/10%10; //shi 为temp处以10后再和10取余(先把十位搞到各位去,然后提取出个位)
ge=temp%10; //ge 为temp与10取余 (提取其个位)
P1=table[bai]; //查表法 把bai对应的段码送P1口
P2=table[shi]; //查表法 把shi对应的段码送P2口
P0=table[ge]; //查表法 把ge对应的段码送P0口
EA=1; //开总中断
ET0=1; //允许定时器中断
TMOD=0x01; //定时器1设置工作方式1
TH0=(65536-50000)/256; //设定定时器初始值高位
TL0=(65536-50000)%256; //设定定时器初始值低位 (12M晶振时约20ms)
TR0=1; //开始定时器

}
void zhongduan() interrupt 1 //中断服务程序 ,定时器中断
{
TH0=(65536-50000)/256; //设定定时器初始值高位 (定时器重新装载)
TL0=(65536-50000)%256; //设定定时器初始值低位 (12M晶振时约20ms)
n++; //计数值n自增
}
void xianshi(uchar bai,uchar shi,uchar ge) //数码管显示函数 (静态显示)
{
P1=table[bai]; //查表法 把bai对应的段码送P1口
P2=table[shi]; //查表法 把shi对应的段码送P2口
P0=table[ge]; //查表法 把ge对应的段码送P0口
}

void main() //主函数
{

chushi(); //掉用chushi函数进行初始化
while(1) //主循环
{
if(n==20) //判断n是否等于20 (50ms*20=1秒!)
{ //当n=20时
n=0; //n清零
temp--; //计数值temp自减
bai=temp/100; //bai 为temp除以100(取百位)
shi=temp/10%10; //shi 为temp处以10后再和10取余(取十位)
ge=temp%10; //ge 为temp与10取余 (取个位)
if(temp<=0) //如果temp 小于等于0 (好像不可能小于最多等于吧)
{
temp=120; //temp赋值为120(兄弟你是不是在作120秒篮球计时器那道题?)
bai=temp/100; //bai 为temp除以100(取百位)
shi=temp/10%10; //shi 为temp处以10后再和10取余(取十位)
ge=temp%10; //ge 为temp与10取余 (取个位)(又来了一遍,直接把if语句放在前面if(temp==255))temp=120不行么?)
P1=table[bai]; //查表法 把bai对应的段码送P1口
P2=table[shi]; //查表法 把shi对应的段码送P2口
P0=table[ge]; //查表法 把ge对应的段码送P0口
}

}
xianshi(bai,shi,ge); //调用显示函数显示数值
}
}

好吧我承认我是无聊,没心情看书。。。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-06-02
一分没有,大段的简单程序,一看就是做毕设的。楼上两位还真有闲,居然真给回答。
第2个回答  2010-06-02
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
uchar bai,shi,ge,n,temp=120;

// 共阳数码管0~F的显示编码
uchar code table[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};

void chushi()
{
// 把数分开,开始时temp为120
// 经过下面3条语句,后bai=1;shi=2;ge=0
bai=temp/100;
shi=temp/10%10;
ge=temp%10;

// 在数码管上显示百位
P1=table[bai];
// 在数码管上显示十位
P2=table[shi];
// 在数码管上显示个位
P0=table[ge];

// 开总中断
EA=1;
// 开定时器0中断
ET0=1;

// 设定定时器0为工作模式1
TMOD=0x01;

// 装计时初值
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
// 启动定时器0
TR0=1;

}
void zhongduan() interrupt 1
{
// 定时器计数溢出,重新装初值
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
n++;
}
void xianshi(uchar bai,uchar shi,uchar ge)
{
// 这个和上面一样,不用讲了
P1=table[bai];
P2=table[shi];
P0=table[ge];
}

void main()
{
// 后面的和上面的都差不多~~~~
chushi();
while(1)
{
if(n==20)
{
n=0;
temp--;
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
if(temp<=0)
{
temp=120;
bai=temp/100;
shi=temp/10%10;
ge=temp%10;
P1=table[bai];
P2=table[shi];
P0=table[ge];
}

}
xianshi(bai,shi,ge);
}
}