Ashinchen123452 发表于 2020-11-22 10:01 按键程序含2ms延时程序放在1ms中断程序中能正常吗? #include<reg52.h> typedef unsigned int uint; typedef unsigned char uchar; sbit K1=P3^2; sbit K2=P3^3; uint t=0; uint a=500; uint x=0; uint display[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; uint flag=0; void delay(int ms) { uint i; while(ms--) { for(i=0;i<120;i++); } } void Init() { TMOD = 0x10; TH1 = (65536-1000)/256; TL1 = (65536-1000)%256; EA = 1; ET1 = 1; TR1 = 1; } void ZQ() interrupt 3 { TH1 = (65536-1000)/256; TL1 = (65536-1000)%256; t++; if(t>=a) { P1=display[x]; x++; if(x>7) x=0; t=0; } } void main() { Init(); while(1) { if(K1==0)//减速 { delay(10);//消抖 if(K1==0) { if(a<2000) a+=100; while(!K1); } } if(K2==0)//加速 { delay(10); if(K2==0) { if(a>100) a-=100; while(!K2); } } } } |
拜托大家帮忙看下哪里有问题 |