//*************************************************************************** #include "inc44b.h" #include "incoption.h" //*************************************************************************** #define rPCONE (*(volatile unsigned *)0x1d20028) #define rPDATE (*(volatile unsigned *)0x1d2002c) #define rPUPE (*(volatile unsigned *)0x1d20030)
void Delay(int time) { int i; int Count=400; for(;time>0;time--) for(i=0;i<Count ;i++); } void port_init(void) { rPCONE = 0x400; rPDATE = 0xfff; rPUPE = 0x0; }
void Beep(int state) { //PE5 Low available. if(state==0) rPDATE = rPDATE&0x1df;//停止蜂鸣 else rPDATE = rPDATE&0x020;//开始蜂鸣 }
void Main(void) { port_init(); while(1) { Delay(20000); Beep(0); Delay(20000); Beep(1); } } 这个程序是我按书上写的,但是翁鸣器不响,不知道为什么? |