按P3.5 P3.6 上开关,数码管+-1:
用DO WHILE去抖动。
#include <reg51.h> code unsigned char sz []={0xc0,0xf9,0xa4,0xb0,0x99, 0x92,0x82,0xf8,0x80,0x90}; void delay(); sbit P10=P1^0; sbit sw0=P3^5; sbit sw1=P3^6;
void main () { char mun=0; P10=0; while(1) { if (sw0==0) { delay(); if (sw0==0) { do { while (sw0==0); delay(); } while (sw0==0); mun--; if (mun<0) mun=0x09; P0=sz [mun]; } } if (sw1==0) { delay(); if(sw1==0) { do { while(sw1==0); delay(); } while (sw1==0); mun++; if (mun>0x09) mun=0; P0=sz [mun]; } } }
}
void delay() { unsigned int i; i=10000; while(i--); }
|