#include<reg52.h> #include<intrins.h> #define unit unsigned int #define unchar unsigned char void delay(unit); void beep(); sbit BEEP=P1^5; void main() { while(1) { unit LED=0xe7; P2=LED; delay(600); P2=0xc3; delay(600); P2=0x81; delay(600); P2=0x00; delay(600); P2=0x81; delay(600); P2=0xc3; delay(600); P2=0xe7; delay(600); P2=0xff; delay(600); BEEP=0; beep(); BEEP=0; delay(200); } } void delay(unit z) { unit i,j; for(i=z;i>0;i--) for(j=100;j>0;j--); } void beep() { unit BEEP,i,j; /*for(i=20;i>0;i--) for(j=10;j>0;j--) BEEP=0;*/ for (i=0;i<100;i++) { BEEP=!BEEP; //BEEP取反 for (j = 0 ; j<250 ; j++) //需要产生方波 _nop_(); } BEEP=1; } |