下面是我編的讀icl7135的源程序,是串行接法,晶振6M,icl7135是種頻是從單片機(jī)ALE端引出后四分之一分頻得到的頻率.
#include
#include
#define uchar unsigned char
#define unit unsigned int
sbit p32=P3^2;
uchar code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef}; // 定義位選
uchar code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//定義段碼
uchar dispbuf[5]={0,0,0,0,0,}; //顯示緩沖
uchar dispcount,t;
unit x,y;
bit flag;
void main()
{
TMOD=0x9;
TH0=0;
TL0=0;
TR0=1;
ET0=1;
IT0=1;
EX0=1;
EA=1;
while(1)
{
x=y;
dispbuf[4]=x/10000;
x=x%10000;
dispbuf[3]=x/1000;
x=x%1000;
dispbuf[2]=x/100;
x=x%100;
dispbuf[1]=x/10;
x=x%10;
dispbuf[0]=x;
P0=dispcode[dispbuf[dispcount]];
P2=dispbit[dispcount];
dispcount++;
if(dispcount==4)
{
dispcount=0;
}
for(t=0;t<50;t++);
}
}
void int0(void) interrupt 0
{
if(flag==0)
{
flag=1;
TH0=0;
TL0=0;
TR0=1;
}
else
{
flag=0;
TR0=0;
y=TH0*256+TL0;
y=y-10001;
TH0=0;
TL0=0;
}
}