51单片机测量脉冲宽度 30
#include<reg51.h>unsignedintwidth=0,count=0;unsignedinttable[10]={0xc9,0xf9,0xa4,0xb0...
#include<reg51.h>unsigned int width=0,count=0;unsigned int table[10]={0xc9,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80};void delay(int n){ int i,j; for(i=n;i>0;i--) for(j=1;j>0;j--);}void exint0() interrupt 2 { TH1=(65536-1000)/256; TL1=(65536-1000)%256; width=count; count=0;}void capture_init(void){ IT1=1; EX1=1; TMOD=0x90; TH1=(65536-1000)/256; TL1=(65536-1000)%256; TR1=1; ET1=1; EA=1;}void display(unsigned char num){ P0=0xff; P0=table[num/10]; P2=0xff; P2=table[num%10];}void main(){ capture_init(); while(1) { delay(20); display(width); }}void timer() interrupt 3 { TH1=(65536-1000)/256; TL1=(65536-1000)%256; count++; }想问一下这个程序问题在哪里,如果换路,它数值不会变。只有在启动之前,开关调到当前路才显示当前的宽度。
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询