#include <reg51.H>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //位碼
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66, 0x3F,/*0*/
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) //主函數(shù)
{
unsigned char i;
TMOD=0x15; //T0T1方式1,T0計數(shù)
TH0=0;
TL0=0;
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
TR1=1; //啟動定時器1
TR0=1; //啟動定時器0
ET0=1; //允許定時器0中斷
ET1=1; //允許定時器1中斷
EA=1; //啟動總中斷
while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<8;i++)
{
temp=0;
}
i=0;
while(x/10)
{
temp=x%10;
x=x/10;
i++;
}
temp=x;
for(i=0;i<6;i++)
{
dispbuf=temp;
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
}
}
void t0(void) interrupt 1 using 0 //中斷1次計數(shù)值為65536
{
T0count++;
}
void t1(void) interrupt 3 using 0 //每4ms中斷1次
{
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
timecount++; //中斷250次即1s采集一次數(shù)據(jù)
if(timecount==250)
{
TR0=0;
timecount=0;
flag=1;
} //中斷250次即1s采集一次數(shù)據(jù)
P0=dispcode[dispbuf[dispcount]]; //P0口段輸出
P2=dispbit[dispcount]; //P2口位輸出
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
小弟初學單片機C,很多都不懂,哪位大哥大姐能幫我分析一下這個程序,寫出其流程圖
下面是圖
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |