커뮤니티>자료실
   
   
 
    부저(Buzzer) 제어 소스 - Samsung Micom의 예   2013.02.04
    부저(Buzzer) 제어 소스 - Samsung Micom의 예
   
 
#pragma language=extended
#include <ioS3F84YB.h>
#include <stdio.h>
#include <intrinsics.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "oneupsys.h"
__tiny unsigned int uiMelContinueTime;
void BuzzerProc(unsigned char kind);
void BuzzerToneCntl(void);
void BuzzerInit(void);
void PowerSaveProc(void);
void ActiveMainClk(void);
void ActiveMainClk(void)
{
 if(OSCCON & 0x08){
  SlectMainClock();
//    CLKCON &=0x08;
 }
}
void PowerSaveProc(void)
{
// __disable_interrupt();  //Disable globle interrupt
 SlectSubClock();
 TC0CON=0x00; //fxx/4
 P4=0xff;
 P4INTH=0x00; //P4 interrupt Enable
 P4INTL=0x00;
 P4CONH=0x55; //Schmitt trigger input mode, pull-up
 P4CONL=0x55; //Schmitt trigger input mode, pull-up
 P4INTH=0x55; //P4 interrupt Enable
 P4INTL=0x55;
 P2=0x3f;
 P2CONH=0xa5; //Schmitt trigger input mode, pull-up
 P2CONL=0x55; //Schmitt trigger input mode, pull-up
 P2INTH=0x05; //Disable interrupt
 P2INTL=0x55; //Disable interrupt
 P2PND=0x00;  //Clear pending bit
 WatchTimeInit();
 IMR =0xD0; //Irq7(Power On) disable ,irq4(watch),irq3(TD0) disbale
//// __enable_interrupt();
 P4PND=0;
// asm("NOP");
// asm("NOP");
 __idle();
 asm("NOP");
 asm("NOP");
 asm("NOP");
 asm("NOP");
}
void BuzzerInit(void)
{
 TACON=0xE0;  //Timer A input clock fxx/8,PWM mode
 TADATA=50;
 TACON_bit.bit2=1; //clear counter
 //High level when data > counter
 //Lower level whendata < counter
}
void BuzzerToneCntl(void)
{
 if(uiMelContinueTime){
  if(--uiMelContinueTime==0){
      Melody.PlayIndex++;
   if(Melody.PlayIndex>=Melody.PlayMaxIndex){
    Melody.PlayIndex=0;
    if(Melody.ReplayIndex!=0xffff){ //emer controll
      if(Melody.ReplayIndex) Melody.ReplayIndex--;
                    if(Melody.ReplayIndex==0){
                        BuzzerProc(BUZZ_OFF_MODE);   //melody paly stop
                    }
    }
   }
         uiMelContinueTime=Melody.ContinueTime[Melody.PlayIndex];
            if(Melody.ToneValue[Melody.PlayIndex]==0){
                TACON=0xE0;    //TA stop
                TADATA=0x00;
    TACON_bit.bit2=1; //clear counter
            }
            else  {
                if(FLAG.bBuzzerActive){
                 TADATA=Melody.ToneValue[Melody.PlayIndex];
     TACON=0x00;
     TACON |=0x60;
     TACON_bit.bit2=1; //clear counter
//        TACON_bit.bit1=1;
                }
            }
  }
 }
}

void BuzzerProc(unsigned char kind)
{
    unsigned char i;
 switch(kind){
     case BUZZ_KEY_BEEP:
   memset(&Melody.ToneValue[0],0,MAX_MELODY);
   memset(&Melody.ContinueTime[0],0,MAX_MELODY);
   Melody.ToneValue[0]=25;
   Melody.ContinueTime[0]=100;
   Melody.PlayMaxIndex=1;
   Melody.ReplayIndex=1;
   break;
  case BUZZ_DOUBLE:
   memset(&Melody.ToneValue[0],0,MAX_MELODY);
   memset(&Melody.ContinueTime[0],0,MAX_MELODY);
   Melody.ToneValue[0]=25;
   Melody.ContinueTime[0]=100;
   Melody.ToneValue[1]=0;
   Melody.ContinueTime[1]=50;
   Melody.ToneValue[2]=25;
   Melody.ContinueTime[2]=100;
   Melody.PlayMaxIndex=3;
   Melody.ReplayIndex=1;
   break;
  case BUZZ_KEY_BEEP_LONG:
   memset(&Melody.ToneValue[0],0,MAX_MELODY);
   memset(&Melody.ContinueTime[0],0,MAX_MELODY);
   Melody.ToneValue[0]=25;
   Melody.ContinueTime[0]=700;
   Melody.PlayMaxIndex=1;
   Melody.ReplayIndex=1;
   break;
  case BUZZ_OFF_MODE:
            for(i=0;i<MAX_MELODY;i++){
                Melody.ContinueTime[i]=0;
    Melody.ToneValue[i]=0;
            }
   Melody.PlayMaxIndex=0;
   Melody.ReplayIndex=0;
            TACON=0xE0;    //TA stop
   TACON_bit.bit2=1; //clear counter
            FLAG.bBuzzerActive=0;
   if(!ETCFLAG.bPowerOnSate){
    ETCFLAG.bSleepIntro=1;
   }
//   else{
//    PowerSaveProc();
//   }
   break;
 }
 Melody.PlayIndex=0;
 uiMelContinueTime=Melody.ContinueTime[Melody.PlayIndex];
 if(kind != BUZZ_OFF_MODE){
  SlectMainClock();
        FLAG.bBuzzerActive=1;
        if(TC0CON==0){
   TC0CON=0x04; //fxx/64
   TC0CON_bit.bit3=1; //Clear Count
   TC0CON_bit.bit1=1; //Interrupt enable
   TC0CON_bit.bit7=1; //timer run
   TC0DATA=0x1A;  //about 5msec
  }
  IMR |=0x04; //TC0 Run
     TADATA=Melody.ToneValue[0];
  TACON=0x00;  //interval mode
  TACON |=0x60;
  TACON_bit.bit2=1; //clear counter
 }
}

 
 
   
 
주소: 인천광역시 서구 봉수대로 141 가좌시범공단 B동 505호    대표자 : 김시석    전화번호 : 032)672-2966    팩스번호 : 032)672-2965
사업자등록 번호 : 225-14-00080    콘트롤러개발,전자제품개발 아테크