复位程序怎么写

1. 单片机秒表复位程序如何写 归零吗?直接把累计的变量置零就可以了 希望帮到你,增加S4和复位标志Reset 我没有测试,相信你会调试好的,加油! #include#define uchar unsigned char sbit dula=P2^6; sbit wela=P2^7; sbit beep=P2^3; sbit S2=P3^0; sbit S3=P3^1; sbit S4=Px^x; unsigned char halt,j,k,a1,a0,b1,b0,c1,c0,s,f,m,n=255,Reset=0; unsigned int pp; unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; void delay(unsigned char i) { for(j=i;j>0;j--) for(k=125;k>0;k--); } void display(uchar shi2,uchar shi1,uchar fen2,uchar fen1,uchar miao2,uchar miao1) { dula=0; P0=table[shi2]; dula=1; dula=0; wela=0; P0=0xfe; wela=1; wela=0; delay(5); P0=table[shi1]|0x80; dula=1; dula=0; P0=0xfd; wela=1; wela=0; delay(5); P0=table[fen2]; dula=1; dula=0; P0=0xfb; wela=1; wela=0; delay(5); P0=table[fen1]|0x80; dula=1; dula=0; P0=0xf7; wela=1; wela=0; delay(5); P0=table[miao2]; dula=1; dula=0; P0=0xef; wela=1; wela=0; delay(5); P0=table[miao1]; dula=1; dula=0; P0=0xdf; wela=1; wela=0; delay(5); } void keyscan() { if(S2==0) delay(10); if(S2==0) { halt=1; } if(S3==0) halt=0; if(S4==0)//复位按键 { Reset=1; } } void main() { TMOD=0x01; TR0=1; TH0=(65536-46080)/256;// 由于晶振为11.0592,故所记次数应为46080,计时器每隔50000微秒发起一次中断 。
TL0=(65536-46080)%256;//46080的来历,为50000*11.0592/12 ET0=1; EA=1; while(1) { keyscan(); if(halt==0) { TR0=1; if(pp==20) { pp=0; m++; n--; P1=n;//闪烁灯 if(m==60) { m=0; f++; if(f==60) { f=0; s++; if(s==99) { s=0; } } } } a0=s%10; a1=s/10; b0=f%10; b1=f/10; c0=m%10; c1=m/10; display(a1,a0,b1,b0,c1,c0); } else if(Reset==1) { Reset=0; TR0=0; s=0; m=0; a0=s%10; a1=s/10; b0=f%10; b1=f/10; c0=m%10; c1=m/10; display(a1,a0,b1,b0,c1,c0); } else { TR0=0; display(a1,a0,b1,b0,c1,c0); } } } void time0() interrupt 1 {TH0=(65536-46080)/256; TL0=(65536-46080)%256; pp++; } 。
2. 单片机秒表复位程序如何写 归零吗?直接把累计的变量置零就可以了希望帮到你,增加S4和复位标志Reset 我没有测试,相信你会调试好的,加油! #include#define uchar unsigned charsbit dula=P2^6;sbit wela=P2^7;sbit beep=P2^3;sbit S2=P3^0;sbit S3=P3^1;sbit S4=Px^x;unsigned char halt,j,k,a1,a0,b1,b0,c1,c0,s,f,m,n=255,Reset=0;unsigned int pp;unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};void delay(unsigned char i){ for(j=i;j>0;j--) for(k=125;k>0;k--);}void display(uchar shi2,uchar shi1,uchar fen2,uchar fen1,uchar miao2,uchar miao1){ dula=0; P0=table[shi2]; dula=1; dula=0; wela=0; P0=0xfe; wela=1; wela=0; delay(5); P0=table[shi1]|0x80; dula=1; dula=0; P0=0xfd; wela=1; wela=0; delay(5); P0=table[fen2]; dula=1; dula=0; P0=0xfb; wela=1; wela=0; delay(5); P0=table[fen1]|0x80; dula=1; dula=0; P0=0xf7; wela=1; wela=0; delay(5); P0=table[miao2]; dula=1; dula=0; P0=0xef; wela=1; wela=0; delay(5); P0=table[miao1]; dula=1; dula=0; P0=0xdf; wela=1; wela=0; delay(5);}void keyscan(){ if(S2==0) delay(10); if(S2==0) { halt=1; } if(S3==0) halt=0; if(S4==0)//复位按键 { Reset=1; } }void main(){ TMOD=0x01; TR0=1; TH0=(65536-46080)/256;// 由于晶振为11.0592,故所记次数应为46080,计时器每隔50000微秒发起一次中断 。
TL0=(65536-46080)%256;//46080的来历,为50000*11.0592/12 ET0=1; EA=1; while(1) { keyscan(); if(halt==0) { TR0=1; if(pp==20) { pp=0; m++; n--; P1=n;//闪烁灯 if(m==60) { m=0; f++; if(f==60) { f=0; s++; if(s==99) { s=0; } } } } a0=s%10; a1=s/10; b0=f%10; b1=f/10; c0=m%10; c1=m/10; display(a1,a0,b1,b0,c1,c0); } else if(Reset==1) { Reset=0; TR0=0; s=0; m=0; a0=s%10; a1=s/10; b0=f%10; b1=f/10; c0=m%10; c1=m/10; display(a1,a0,b1,b0,c1,c0); } else { TR0=0; display(a1,a0,b1,b0,c1,c0); } }}void time0() interrupt 1{TH0=(65536-46080)/256; TL0=(65536-46080)%256; pp++;} 。
3. 电动机自锁程序用复位指令写程序 置位和自锁作用一样,都是将线圈保持在“得电”状态 区别是自锁的复位条件是将前面的闭合触点断开,置位的复位条件是要使用指令将线圈复位 。