我想补充下
*******************************************/ #include <reg51.h> #include <intrins.h> unsigned char a; unsigned int b; sbit BEEP = P1^5; sbit RELAY = P1^4;//继电器 的线
sbit K1 = P0^0; sbit K2 = P0^1; sbit K3 = P0^2; sbit K4 = P0^3; sbit K5 = P0^4; sbit K6 = P0^5; sbit K7 = P0^7; sbit K0 = P0^6; void beep(); void number(); /*********************************************************/ main() { while(1) { P2 = 0xff; if(K1==0) P2 = 0xfe;
if (K0==0) P2 = 0x03;
if (K7==0) //这个可以延时的好软件 { P2 = 0x01; for (a=0; a<255; a++) { number(); for (b=0; b<11000; b++) P2 = a; } } if(K2 == 0) P2 = 0xfd;
if(!K3) P2 = 0xfb;
if(!K4) P2 = 0xf7;
if (!K5 ) beep(); //喇叭发声
RELAY = 1; if (!K6 ) { for ( b=0; b<63000; b++) RELAY =0; } } }
/**********************************************************/ void beep() { unsigned char i , j; for (i=0;i<100;i++) { BEEP=!BEEP; //BEEP取反 for (j = 0 ; j<250 ; j++) //需要产生方波 _nop_(); } BEEP=1; //关闭蜂鸣器 }
/************/
void number() { unsigned int a;
for ( a=0; a<23000; a++); P3=~0x3F&0X7f; for ( a=0; a<23000; a++); P3 = ~0X06; for ( a=0; a<23000; a++); P3 = ~0X5B; for ( a=0; a<23000; a++); P3 =~0X4F; for ( a=0; a<23000; a++); P3 =~0X66; for ( a=0; a<23000; a++); P3 =~0X6D; for ( a=0; a<23000; a++); P3 =~0X7D; for ( a=0; a<23000; a++); P3= ~0X07; for ( a=0; a<23000; a++); P3= ~0X7F; for ( a=0; a<23000; a++); P3 = ~0X6f; for ( a=0; a<23000; a++); P3 = ~0X77; for ( a=0; a<23000; a++); P3 = ~0X7C; }
这是源程序我的是89C55的CPU
|