T0设为计数器,P2.0产生脉冲,计数到1000后清零计数值并关掉计数器,关不掉也不能清零,请高手指教//the purpose of the program is to verify the counter of T0 generated by P2.0,
//T0 is counter, T1 decided the serail port rate and T2 is timer
#include <reg52.h>
#include <lcd1602.h>
#include <serial.h>
#include <timer.h>
#define uint unsigned int
#define uchar unsigned char
uint rd_t0=0;
uint disp[4];
sbit pulse=P2^0;
void main()
{
uint i,j;
serial_init();
//timer0_init();
lcd1602_init();
while(1)
{
for(j=0;j<9;j++)
{
pulse=0;
delay10us(10);
pulse=1;
delay10us(10);
}
rd_t0=TH0*0x100+TL0;
disp[0]=rd_t0/10000;
disp[1]=(rd_t0-disp[0]*10000)/1000;
disp[2]=(rd_t0-disp[0]*10000-disp[1]*1000)/100;
disp[3]=(rd_t0-disp[0]*10000-disp[1]*1000-disp[2]*100)/10;
disp[4]=rd_t0-disp[0]*10000-disp[1]*1000-disp[2]*100-disp[3]*10;
if(rd_t0<1000)
{
for(i=0;i<5;i++)
{
senddatabyte(disp[i]+'0');
delay10us(10);
}
delay10us(6000);
//delay10us(60000);
sendcmdbyte(0x0c);
sendcmdbyte(0x01);
sendcmdbyte(0x06);
}
else
{
TMOD=0x27;
TR0=0;
TH0=0;
TL0=0;
rd_t0=0;
for(j=0;j<5;j++)
{
*(disp+j)=0;
}
//TR0=1;
//break;
}
}
}
|