一个单片机发送脉冲,通过T0外部计数完全没有问题,是楼主程序有问题。
- #include<reg51.h>
- sbit x=P2^0;
- sbit z=P1^0;
- void delay(unsigned int z)
- {
- unsigned int m,n;
- for(m=z;m>0;m--)
- for(n=110;n>0;n--);
- }
- void main(void)
- {
- unsigned char a[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- unsigned char i,j;
- x=1;
- z=0;
- TMOD=0x06;
- TL0=0x00;
- TH0=0x00;
- TR0=1;
- while(1)
- {
- for(i=0;i<(j*2);i++)
- {
- z=~z;
- delay(1);
- }
- P0=a[TL0];
- TL0=0x00;
- delay(1000);
- j++;
- if(j>9)
- j=0;
- }
- }
复制代码
|