#include<reg51.h> //頭文件
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;
unsigned char TempBuffer[10];
sbit lcde=P2^7; //使能端
sbit lcdrs=P2^6; //復位端
sbit lcdrw=P2^5; //寫數據端
void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
{
unsigned char a[5]; char i, j;
a[0]=(t/10000)%10; //取得整數值到數組
a[1]=(t/1000)%10;
a[2]=(t/100)%10;
a[3]=(t/10)%10;
a[4]=(t/1)%10;
for(i=0; i<5; i++) //轉成ASCII碼
a=a+'0';
for(i=0; a=='0' && i<=3; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; }
for(; i<5; i++)
{ *str=a; str++; } //加入有效的數字
*str='\0';
}
/*******************************************************************/
/* */
/* 延時子程序 */
/* */
/*******************************************************************/
void delay(uint z)
{
uint a,y;
for(a=z;a>0;a--)
for(y=110;y>0;y--);
}
main()
{
unsigned char i;
init();
while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
IntToStr(x, &TempBuffer[0], 5);
while(TempBuffer != '\0')
{
write_date(TempBuffer);
i++;
delay(300);
}
write_com(0x01);
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
TR1=1;
i = 0;
}
}
}
這個是我在網上找到的一個計數器程序,里面我有兩個地方沒有看懂,我用紅色的標注出來了的
for(i=0; i<5; i++) //轉成ASCII碼
a=a+'0'; 他這里是寫出計數的位 ,后面加一個 '0'是干什么的呢
for(i=0; a=='0' && i<=3; i++);
for(j=5-n; j<i; j++) //填充空格
{ *str=' '; str++; } 這個語句我沒有看懂, *str函數不怎么明白
for(; i<5; i++)
{ *str=a; str++; } //加入有效的數字
*str='\0';
第二個地方
x=T0count*65536+TH0*256+TL0; 這個X是表示計數值的大小,那怎么等式為什么要T0count*65536+TH0*256+TL0
IntToStr(x, &TempBuffer[0], 5); &TempBuffer[0]是什么意思呢
while(TempBuffer != '\0')
{
write_date(TempBuffer);
就這些地方不怎么明白,麻煩幫我解釋一下 不勝感激。。。
|