博客首页 | 排行榜 |

tage的博客

个人档案
博文分类
MC9S08LL16按键控制蜂鸣器频率程序,上图。  2009-04-22 20:12

/myspace/album/image.php?uid=115706&aid=862&pic=cd156d57&ext=jpg&screen=show

本程序利用4个按键来控制蜂鸣器的输出频率,

第一个按键为蜂鸣器鸣叫开始。

第二个按键为蜂鸣器鸣叫停止。

第三个按键为蜂鸣器鸣叫频率增加。

第四个按键为蜂鸣器鸣叫频率降低。

 

程序如下,,需要注意的是按键输入,外部没有上拉电阻,所以必须允许片内上拉电阻。

 #include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include <string.h> /* include peripheral declarations */

unsigned int temp=500;
int  begin=1;


void SYS_INIT(void)
{

  SOPT1 =    0x63; //disable cop. enable stop.
  SPMSC1 = 0x00; //LVD disabled
  IRQSC_IRQPE =1;
  TODC_TODCLKS = 0;
  TODC_TODPS = 1;
  TODC_TODEN =1;
 
       PTADD =0X00;
       PTBDD = 0x00;
      
       PTCDD = 0xFF;

       PTBD = 0xff;
       PTCD = 0xff;
      
       PTAPE=0XFF;   //允许上拉电阻
       PTBPE=0XFF;
       PTCPE=0XFF;
}
//----------------------------------
void DELAY(unsigned int i)
{
     while(i)i--;
}

//////////////// Main//////////////////////////////////////////////


void main(void)
 {
  SYS_INIT();
 
 
  for(;;)
    {
      if((PTAD&0x40)==0){begin=1;DELAY(5000);}  //KEY 1   BEGIN
      if((PTAD&0x80)==0){begin=0;DELAY(5000);}  //KEY 2   STOP
      if((PTAD&0x01)==0) {if(temp>200)temp-=20;DELAY(5000);}  //+
      if((PTBD&0X40)==0) {if(temp<800)temp+=20;DELAY(5000);} //-
     
      if(begin==1)
      {
       
        DELAY(temp);
        PTCD=~PTCD;
    
      }
    }

 

 }

 

|
上一篇:MC9S08LL16 时钟模块介绍及时钟软件仿真 | 下一篇:MC9S08LL16单片机最小系统板串口通信必须要交叉串口线才能通信。
以下网友评论只代表其个人观点,不代表本网站的观点或立场