示例#1
0
// PLL初始化子程序   BUS Clock=16M
void setbusclock(void)
{   
    CLKSEL=0X00;				// disengage PLL to system
    PLLCTL_PLLON=1;			// turn on PLL
    SYNR=0x00 | 0x01; 	// VCOFRQ[7:6];SYNDIV[5:0]
                        // fVCO= 2*fOSC*(SYNDIV + 1)/(REFDIV + 1)
                        // fPLL= fVCO/(2 × POSTDIV) 
                        // fBUS= fPLL/2 
                        // VCOCLK Frequency Ranges  VCOFRQ[7:6]
                        // 32MHz <= fVCO <= 48MHz    00
                        // 48MHz <  fVCO <= 80MHz    01
                        // Reserved                  10
                        // 80MHz <  fVCO <= 120MHz   11				
    REFDV=0x80 | 0x01;  // REFFRQ[7:6];REFDIV[5:0]
                        // fREF=fOSC/(REFDIV + 1)
                        // REFCLK Frequency Ranges  REFFRQ[7:6]
                        // 1MHz <= fREF <=  2MHz       00
                        // 2MHz <  fREF <=  6MHz       01
                        // 6MHz <  fREF <= 12MHz       10
                        // fREF >  12MHz               11                         
                        // pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
    POSTDIV=0x00;       // 4:0, fPLL= fVCO/(2xPOSTDIV)
                        // If POSTDIV = $00 then fPLL is identical to fVCO (divide by one).
    _asm(nop);          // BUS CLOCK=16M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));	  //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;		        //engage PLL to system; 
}
示例#2
0
//main routine for ADC (linear) calibration testing
void TestADCCalibration(void)
{
  unsigned int * ADCBuffer;
  double * ADCRealValues;
  double P, Q;
  unsigned int i;
  unsigned int NumOfData;
  volatile double diffOrig;
  volatile double diffCalib;
  unsigned char DEBUG_STRING[30];

  //set external clock (16MHz XTALL required)
  SetCPUClock(0);

  //allocate buffer space
  if ((ADCBuffer = malloc(ADC_BUFFER_SIZE * sizeof(ADCBuffer[0]))) == NULL)
    _asm("trap\n");
  if ((ADCRealValues = malloc(ADC_BUFFER_SIZE * sizeof(ADCRealValues[0]))) == NULL)
    _asm("trap\n");

  //main test
  {
    //collect data
    NumOfData = ADCCollectDataCalib(ADCBuffer, ADCRealValues);
    P= GetMultiplierCalib(ADCBuffer, ADCRealValues, NumOfData);
    diffOrig = GetErrorCalib(ADCBuffer, ADCRealValues, NumOfData, P, 0);

    //calib data
    ADCCalibratePQ(ADCBuffer, ADCRealValues, NumOfData, &P, &Q);
    diffCalib = GetErrorCalib(ADCBuffer, ADCRealValues, NumOfData, P, Q);

    //print errors
    sprintf(DEBUG_STRING, "Orig = %f", diffOrig);
    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, DEBUG_STRING);
    sprintf(DEBUG_STRING, "Calib= %f", diffCalib);
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, DEBUG_STRING);
    delay(500000l);//to show results
  }
  
  //see real values after ADC calibration - for checking calibration
  LCD_Clear();
  LCD_PrintString(LCD_LINE1, DISABLE, ENABLE, "Real calibrated U");  
  while(!JOY_SEL)
  {
    //start single conversion
    ADC2_StartConversion();
    while (!ADC2_GetFlagStatus());
    //clear end of conversion bit
    ADC2_ClearFlag();
    //collect ADC value and display
    LCD_SetCursorPos(LCD_LINE2, 4);//set cursor position
    LCD_PrintDec4((P*ADC2_GetConversionValue() + Q)*1000);
  }
  
  //unallocate buffer
  free(ADCBuffer);
}//TestADCCalibration
/*****************************************************************************
Name:          DisplayDelay 
Parameters:    unit                   
Returns:       none 
Description:   Delay routine for LCD display.   May be used for setup and 
			   hold times.
*****************************************************************************/
void DisplayDelay(unsigned long int units){

	unsigned long int counter = units * 0x100;

	while(counter--){
		_asm ("NOP");
		_asm ("NOP");
		_asm ("NOP");
	}
}
示例#4
0
文件: main.c 项目: danbao/SmartCar
void setbusclock(void)   //PLL setting
{   
    CLKSEL=0X00;    //disengage PLL to system
    PLLCTL_PLLON=1;   //turn on PLL
    SYNR=1;          
    REFDV=1;          //pllclock=2*osc*(1+SYNR)/(1+REFDV)=32MHz;
    _asm(nop);          //BUS CLOCK=16M
    _asm(nop);
    while(!(CRGFLG_LOCK==1));   //when pll is steady ,then use it;
    CLKSEL_PLLSEL =1;          //engage PLL to system; 
}
示例#5
0
文件: main.c 项目: jerryfree/DG128C
void setbusclk() 
{
 CLKSEL=0x00;           //clodk=oscclk/2   use OSC clock
 PLLCTL_PLLON=1;        //turnPLL
 SYNR=0xc0|9;           
 REFDV=0xc0|1;          //PLLCLK=2*osc*(1+SYN)/(1+REFDIV)=160
 POSTDIV=0x00;           //busclk=PLLCLK/OSDIV/2=80
 _asm(nop);
 _asm(nop);
 _asm(nop);
 while(!(CRGFLG_LOCK==1));   //wait is to be steady
 CLKSEL_PLLSEL=1;            //use PLL clock
}
/**
  * @brief  Utility function used to read CC register.
  * @param  None
  * @retval CPU CC register value
  */
uint8_t ITC_GetCPUCC(void)
{
#ifdef _COSMIC_
  _asm("push cc");
  _asm("pop a");
  return; /* Ignore compiler warning, the returned value is in A register */
#elif defined _RAISONANCE_ /* _RAISONANCE_ */
  return _getCC_();
#else /* _IAR_ */
  asm("push cc");
  asm("pop a"); /* Ignore compiler warning, the returned value is in A register */
#endif /* _COSMIC_*/
}
示例#7
0
文件: main.c 项目: tglgg/STM8-4432--
/********************************************************
用TIM2产生0.01S的时钟~然后循环100次产生1S的延迟~用PD显示
********************************************************/
void main(void)
{
	Init_GPIO();
	Init_Tim2();
	_asm("rim");      //开启全局中断
	while (1);
}
示例#8
0
文件: main.c 项目: mike-audi/m-audi
main()
{
	unsigned int x=0;
	setupIO();
	_asm("rim\n");
	PB_ODR |= 0x20;
	
	while(1){
		sendStandby();
		sendByte(0x55);
		sendByte(0xa0);
		sendByte(0x03);
		sendByte(0x00);
		sendByte(0x00);
		b1 = readByte();
		b2 = readByte();
		b3 = lastRead();
	
		for(x=0;x<60000;x++);
		for(x=0;x<60000;x++);
		for(x=0;x<60000;x++);
		for(x=0;x<60000;x++);
		for(x=0;x<60000;x++);
	}

}
示例#9
0
void System_init(void)
{
	System_Clock_init();
	UART1_Init();
	delay_init(16);
	HekrInit(UART1_SendChar);
	_asm("rim");
}
示例#10
0
uint8_t ITC_GetCPUCC(void)
{
#ifdef _COSMIC_
    _asm("push cc");
    _asm("pop a");
    return; /* Ignore compiler warning, the returned value is in A register */
#endif
    
#ifdef _RAISONANCE_
    return _getCC_();
#endif

#ifdef _IAR_SYSTEMS_
    __asm("push cc");
    __asm("pop a");
#endif
}
示例#11
0
文件: Global.c 项目: zigaobj/jkelife
//=============================================================================================
//说明:软件延时//系统时钟72M 情况下
//输入:time延时时间,单位ms
//输出:void
//调用:void
//修改:2011-01-20			KEN			初定
//=============================================================================================
void DelayMs_Soft(u16 time)
{    
   u16 i=0;  
   while(time--)
   {
      for(i=0;i<490;i++)	
      _asm("");			
   } 
}
示例#12
0
void TIM2_Init(void)
{
  _asm("sim");       //sim是禁止中断
  TIM2_IER  = 0x00;  //禁止中断
 
  TIM2_EGR  =0x01;   // 允许产生更新标志
  TIM2_PSCR =0x01;   // 设置时钟分频 2M/2=1MHz---1us
  TIM2_ARRH = 0x27;  // 0x2710=10000;  每10ms复位一次定时器2
  TIM2_ARRL = 0x10;  // ARR自动装载值,每1us递减1          
 
  TIM2_CNTRH=0x00;   //初值
  TIM2_CNTRL=0x00;
 
  TIM2_CR1 |= 0x81;  //开启定时器
  TIM2_IER |= 0x01;  //允许中断 
  _asm("rim");       //rim使能中断
 
}
/*..........................................................................*/
void BSP_init(void) {
    uint16_t volatile delay;
                                                 /* initialize the clock... */

    prc0 = 1;                   /* allow writing to clock control registers */
    cm07 = 0;    /* clock selected by cm21 in CM2 (oscillation stop detect) */
    cm21 = 0;    /* clock selected by cm17 in CM1 (system clock select reg) */
    cm17 = 0;                                 /* clock source is main clock */
    mcd  = 0x12;                      /* set divide for BCLK to divide by 1 */

                               /* configure and switch main clock to PLL... */
    /* set PLL to multiply by 6 and divide by 2 giving 30MHz when writing PLL
    * control registers write to both plc0 and plc1 (addresses 0026 and 0027)
    * using a word write command. Set divide ratio with the PLL off
    */
    *(uint16_t *)&plc0 = 0x0253;
    _asm("nop");
    *(uint16_t *)&plc0 = 0x02D3;                         /* turn the PLL on */
    for (delay = 0; delay < 0x4000; ++delay) {          /* delay for 20msec */
    }
    cm17 = 1;                         /*  make the PLL the CPU clock source */
    prc0 = 0;                            /* protect clock control registers */


    pd6 |= 0x0F;   /* port 6 is used by E8 do not modify upper half of port */

                                                  /* enable the User Button */
    SW1_DDR = 0;

                                               /* LED port configuration... */
    LED0_DDR = 1;
    LED1_DDR = 1;
    LED2_DDR = 1;
    LED3_DDR = 1;
    LED0     = LED_OFF;
    LED1     = LED_OFF;
    LED2     = LED_OFF;
    LED3     = LED_OFF;

    /* start the 32kHz crystal subclock (remove if 32kHz clock not used)... */
    prc0  = 1;    /* unlock CM0 and CM1 and set GPIO to inputs (XCin/XCout) */
    pd8_7 = 0;
    pd8_6 = 0;
    cm04  = 1;                                   /* start the 32kHz crystal */

                                      /* setup Timer A running from fc32... */
    ta0mr = 0xC0;                      /* Timer mode, fc32, no pulse output */
    ta0   = (int)((fc_CLK_SPEED/32 + BSP_TICKS_PER_SEC/2)
                  / BSP_TICKS_PER_SEC) - 1;                       /* period */
    ta0ic = TICK_ISR_PRIO;   /* set the clock tick interrupt priority level */

    if (QS_INIT((void *)0) == 0) {    /* initialize the QS software tracing */
        Q_ERROR();
    }
}
/*..........................................................................*/
void QF_onIdle(void) {
#ifdef Q_SPY
    if (ti_u0c1 != 0) {
        uint16_t b = QS_getByte();
        QF_INT_UNLOCK(dummy);                          /* unlock interrupts */
        if (b != QS_EOD) {
            u0tb = b;                    /* stick the byte to the TX buffer */
        }
    }
    else {
        QF_INT_UNLOCK(dummy);                          /* unlock interrupts */
    }
#elif (defined NDEBUG)          /* low-power mode interferes with debugging */
    /* stop all peripheral clocks that you can in your applicaiton ... */
    _asm("FSET I");            /* NOTE: the following WAIT instruction will */
    _asm("WAIT");          /* execute before entering any pending interrupt */
#else
    QF_INT_UNLOCK(dummy);                         /* just unlock interrupts */
#endif
}
示例#15
0
文件: init.c 项目: lihebi/freescale
/*把总线时钟设置为24MHz,相当于锁相环*/
void initPLL(void){			//32M
	CPMUPROT = 0x26;            //保护时钟配置寄存器   
	CPMUCLKS_PSTP = 0;          //禁用PLL   
	CPMUCLKS_PLLSEL = 1;        //选择PLL作为系统时钟源   
	CPMUOSC_OSCE = 1;           //外部晶振使能   
		    
	CPMUSYNR = 0x07;            //fVCO= 2*fOSC*(SYNDIV + 1)/(REFDIV + 1)   fosc=16MHZ                     
	CPMUREFDIV = 0x03;            
		      
	CPMUPOSTDIV = 0x00;         // PLL CLOCK = VCO CLOCK / (POSTDIV + 1)    
		                              //BUS CLOCK = PLL CLOCK/2   
	_asm(nop);  
	_asm(nop);  
	_asm(nop);
	_asm(nop);	 
  
	CPMUPLL=0x10;               //锁相环调频启用,用以减少噪音   
		      
	while(CPMUFLG_LOCK == 0);   //等待PLL稳定      
	CPMUPROT = 0x00;            //关闭保护时钟   
}
示例#16
0
 //-----------------------------------------------------------------------*
 //函数名: Light_Init时钟设置函数定义                                     *
 //功  能: 基于16MHz的外部晶振,设置总线时钟频率                          *
 //参  数: fbus为目标总线频率值,推荐值为16、20、32、40、48、60MHz        *
 //返  回: 无                                                             * 
 //-----------------------------------------------------------------------*
 void SetBusCLK_M(uint8 fbus)
 {   
      CLKSEL=0x00;          // 不加载IPLL到系统
      REFDV=0x00 | 0x07;    // REFFRQ[1:0];REFDIV[5:0]
      switch(fbus)          // BUS CLOCK
      {
        case 16: SYNR =0x00 | 0x07;break;
        case 20: SYNR =0x00 | 0x09;break;
        case 32: SYNR =0x40 | 0x0F;break;
        case 40: SYNR =0x40 | 0x13;break;
        case 48: SYNR =0xC0 | 0x17;break;
        case 60: SYNR =0xC0 | 0x1D;break;
        default: break;
      }  
      PLLCTL_PLLON=1;           //启动IPLL
      _asm(nop);            
      _asm(nop);
      while(!(CRGFLG_LOCK==1)); //等待IPLL稳定
      POSTDIV=0x00;             //POSTDIV[4:0], fPLL= fVCO/(2xPOSTDIV)
                                //若POSTDIV = 0x00,则fPLL = fVCO 
      CLKSEL_PLLSEL =1;         //加载IPLL到系统 
 }
示例#17
0
//8-bit AD convertor
u8 ADC_8BIT(u8 ch)
{
    u16 Adc;
    u8 i;
    ADC.CR2=0;
    ADC.CSR =ch &0x0F;
    ADC.CR1 |=0x1; // 启动ADC
    _asm("nop");
    ADC.CR1 |=0x1; // 开始转换
    for(i=0;(i<100)&&((ADC.CSR &ADC_CSR_EOC)==0);i++)
        Delay(1);
    Adc = ADC.DRH; //READ DATA 因为是右对齐所以先读低位
    ADC.CR1 &=0xfe; // 关闭ADC
    return(Adc);
}
示例#18
0
static NO_REG_SAVE void krn_thread_shell (void)
{
//enable interrupts before thread start
#if defined(__CSMC__)
	_asm("rim");
#elif defined(__IAR_SYSTEMS_ICC__)
	__enable_interrupt();
    //rim();
#elif defined(__RCSTM8__)
	_rim_();
#endif
	//thread entry
	if (krn_thread_first && krn_thread_first->func) {
		krn_enter_thread(krn_thread_first->func);
	}
}
示例#19
0
void System_init(void)
{
	//系统时钟初始化 内部16M
	System_Clock_init();
  //串口初始化 9600
	UART1_Init();
	//串口发送函数绑定
	HekrInit(UART1_SendChar);
	//16M主频延迟初始化
	delay_init(16);
	//通过上电次数选择模式 必须先初始化延迟 串口
	Bright_ModeInit();

	//PWM 初始化
	TIM2_Init();
	//亮度调整定时器
	TIM1_Init();
	_asm("rim");
}
示例#20
0
void interrupt 8 Port0_interrupt(void) // HS interrupt
{
    static unsigned int i;

    TFLG1 = 0x01; // Clear HS flag
    if( g_SampleFlag == 0 ) // 不用这么搞,提前关行终中断就可以
    {
        return;
    }
    row_counter++;
    
    if( row_counter % SAMPLE_INTERVAL == 0 )
    {                                                                                                         
        app = &buff[row][0];
        row++;
        if( row_counter > 200 )
        {
            g_SampleFlag = 0;
            TIE_C0I = 0;
            flag = 1;
            return; //test
            
        }
            
        for( i = 0; i < COLUMN_VALUE; i++ ) 
        {
            _asm(nop);_asm(nop);_asm(nop);
            _asm(nop);_asm(nop);_asm(nop);
            _asm(nop);_asm(nop);_asm(nop);
            _asm(nop);_asm(nop);_asm(nop);
            _asm(nop);_asm(nop);_asm(nop);
            _asm(nop);_asm(nop);_asm(nop);
            //for 80Mhz
            *app++ = PORTB;
        }
    }
}
///////////////////////////////////////////////////////////////////////////////
//> Name:        PlayerLib_SetState
//
//  Type:        Function
//
//  Description: Use the function to set the decoder to a specified state:
//                  STOP, PLAY, PAUSE, TOGGLE (switches between PLAY & PAUSE,
//                                             PLAYs if STOPPED)
//
//  Inputs:      iState = state to set decoder to
//               bWait  = if TRUE, function will not return until state is set
//  Outputs:     Success returned if successful, Error if not.
//
//  Notes:
//<
///////////////////////////////////////////////////////////////////////////////
RETCODE _reentrant PlayerLib_SetState (int iState,int bWait,int*ignored)
{
    RETCODE rtn=PLAYERLIB_SUCCESS;
    ignored;
    switch (iState)                              // switch on the desired decoder state
    {
    case DECODER_STATE_STOP:                     // set Decoder to STOP state
      if(!(g_wDecoderSR & DECODER_STOPPED))      // if Decoder NOT stopped-->
      {
#ifdef SYNC_LYRICS
          SysCallFunction(RSRC_LYRICS_API_CODEBANK,LyricsStop,0,0,0);
#endif
          SysPostMessage(2,DECODER_STOP);        // -->then post a message to STOP
          if(bWait)                              // check if we need to WAIT for STOP to occur
          {
            while(!(g_wDecoderSR & DECODER_STOPPED))
              SysWaitOnEvent(EVENT_TIMER,0,10);  // wait, 10ms ...
          }
      }
	  // For fix FF hang
      DecoderForceInit();                               // update decoder and force init
      SysPostMessage(2,DECODER_RESET);
#ifdef AUDIBLE
		  if( (DecoderResourcePtr != RSRC_AUDIBLE_ACELPDEC_CODE) && (DecoderResourcePtr != RSRC_AUDIBLE_DECMOD_CODE) ) {
			DecSetSongPosZero();                       // reset byte positions to beginning of file
		  }
#else
        DecSetSongPosZero();                       // reset byte positions to beginning of file
#endif

#ifdef WOW
	  SysSpeedClockFree(SPEED_CLIENT_MENU_WOW);  // let speed return to IDLE if not playing
#endif

      break;

    case DECODER_STATE_PLAY:                     // set Decoder to PLAY state
      //it is possible that the player is already heading into play state and our play message will cause it to
      //go to pause state.   The decoder should be fixed to avoid this problem. See decoder settling interval.
      g_iPlayerState = DECODER_PLAYING;

      // Wait decoder settling interval (ms), before checking decoder status.
      SysWaitOnEvent(EVENT_TIMER,0,100); // Prevents hang by keeping playerlib & decoder synchronized.
      // Now check the Decoder's updated status.

      if(!(g_wDecoderSR & DECODER_PLAYING))      // if Decoder NOT playing-->
      {
#ifdef WOW
        // Calling SysSpeedIncrease() will decrease battery life,
        // so only call for WOW to increase battery life. (Stmp00008309)
        // But inter-song delay will be increased if speed is not increased.
        SysSpeedIncrease(SPEED_MAX,SPEED_CLIENT_MENU_WOW);  // boost speed on MP3s
#endif
#ifdef SYNC_LYRICS
		SysCallFunction(RSRC_LYRICS_API_CODEBANK,LyricsStart,0,0,0);
#endif

#ifndef USE_PLAYLIST5
        SysPostMessage(2,DECODER_PLAY);          // -->then post a message to PLAY
#else        
		if((!g_bWait)|| filest_bHasDRM || filest_bHasJanusDRM)
			bWait = FALSE;

        SysPostMessage(2,DECODER_PLAY);          // -->then post a message to PLAY
//         bWait = FALSE;
#endif
#ifdef MOTION_VIDEO
#ifdef USE_PLAYLIST3
        if(iJpegPlaySet == PLAYSET_MVIDEO)              bWait = FALSE;
#else
#ifndef USE_PLAYLIST5
        if(Playlist_GetPlaySet() == PLAYSET_MVIDEO) bWait = FALSE;
#endif		
#endif
#endif
        if(bWait)                                // check if we need to WAIT for PLAY to occur
        {
          while(!(((g_wDecoderSR & (DECODER_PLAYING|DECODER_BAD_FILE))||g_wCurrentSongBad)))
          {   SysWaitOnEvent(EVENT_TIMER,0,10);    // wait, 10 ms ...
#ifdef USE_PLAYLIST5          
                if (bDRMLicExpired || filest_bHasDRM || filest_bHasJanusDRM)
                    break;
#endif
          }
          if((g_wDecoderSR & DECODER_BAD_FILE) || g_wCurrentSongBad)
          {
              g_iPlayerState = DECODER_STOPPED;
              rtn = PLAYERLIB_BAD_FILE;          // return error code if file will not play
          }
          else // else, mark the current song as played in playlist
          {   SysCallFunction(RSRC_PLAYLIST_CODEBANK,Playlist_MarkCurrentSongPlayed,0,0,0);
          }
        }
      }
      break;

    case DECODER_STATE_PAUSE:
      //it is possible that the player is already heading into pause state and our play message will cause it to
      //go to play state.   The decoder should be fixed to avoid this problem.

#ifdef SYNC_LYRICS
      SysCallFunction(RSRC_LYRICS_API_CODEBANK,LyricsPause,0,0,0);
#endif
      // Decoder settling time wait (ms) prevents hang after PLAY, PR_FF, quickly followed by PH_FF.
      // Keeps playerlib & decoder synchronized. Stmp00003027/2947  Verified with decoder bitrate limits.
      // Note: Decoder settling time of 30 ms is insufficient for some MPEG rates. 100 ms prevents hang.
      if (bWait)  // If we haven't yet waited for decoder settling time to expire, do so now.
      {  SysWaitOnEvent(EVENT_TIMER,0,100);
      }

      if(!(g_wDecoderSR & DECODER_PAUSED))       // if Decoder NOT paused-->
      {
        if(g_wDecoderSR & DECODER_STOPPED)       // if Decoder stopped==>
          SysPostMessage(2,DECODER_PLAY);        // ==>then post a message to PLAY
        SysPostMessage(2,DECODER_PLAY);          // -->then post a message to PLAY/PAUSE
        if(bWait)                                // check if we need to WAIT for PAUSE to occur
        {
          while(!((g_wDecoderSR & (DECODER_PLAYING|DECODER_BAD_FILE)||g_wCurrentSongBad)))
            SysWaitOnEvent(EVENT_TIMER,0,10);    // wait, 10 ms ...
          if(g_wDecoderSR & DECODER_BAD_FILE)
            rtn = PLAYERLIB_BAD_FILE;            // return error code if file will not play
        }
      }
      break;

    case DECODER_STATE_TOGGLE:                  // this function simply toggles between PLAY and PAUSE
#ifdef SYNC_LYRICS
      if(!(g_wDecoderSR & DECODER_PAUSED))       // if Decoder NOT paused-->
         SysCallFunction(RSRC_LYRICS_API_CODEBANK,LyricsPause,0,0,0);
      else
         SysCallFunction(RSRC_LYRICS_API_CODEBANK,LyricsStart,0,0,0);
#endif
      // As with state pause, decoder settling time wait (ms) prevents hang. Keeps playerlib & decoder synchronized.
      // Note: See comments for case decoder state pause above.
      SysWaitOnEvent(EVENT_TIMER,0,100);
      SysPostMessage(2,DECODER_PLAY);           // if STOPPED -- toggle will cause a play
      if(bWait)
      {
        //ignoring wait for now.
      }
      break;
    default:
        _asm ( " debug");
        break;
    }
    return PLAYERLIB_SUCCESS;
}
示例#22
0
int main() {
	unsigned long T_LED = 0L;  // time of last digit update
	unsigned long T_time = 0L; // timer
	int i = 00, j = 00;
	U8 beep_delay = 0;
	int show_time_delay = 0;
	U8 counter_enabled = 0;
	key_state = 0;
	work_hours = (work_hours_t*)EEPROM_START_ADDR;	

	keys_scan_buffer[0] = keys_scan_buffer[1] = keys_scan_buffer[2] = keys_scan_buffer[3] = 0;
	Global_time = 0L; // global time in ms
	ADC_value = 0; // value of last ADC measurement
	LED_delay = 1; // one digit emitting time

	// Configure clocking
	CLK_CKDIVR = 0; // F_HSI = 16MHz, f_CPU = 16MHz
	// Configure pins
	CFG_GCR |= 1; // disable SWIM
	LED_init();
	// Configure Timer1
	// prescaler = f_{in}/f_{tim1} - 1
	// set Timer1 to 1MHz: 1/1 - 1 = 15
	TIM1_PSCRH = 0;
	TIM1_PSCRL = 15; // LSB should be written last as it updates prescaler
	// auto-reload each 1ms: TIM_ARR = 1000 = 0x03E8
	TIM1_ARRH = 0x03;
	TIM1_ARRL = 0xE8;
	// interrupts: update
	TIM1_IER = TIM_IER_UIE;
	// auto-reload + interrupt on overflow + enable
	TIM1_CR1 = TIM_CR1_APRE | TIM_CR1_URS | TIM_CR1_CEN;
	// configure ADC
  BEEP_CSR = 0x1e; // Configure BEEP

	_asm("rim");    // enable interrupts
		
	display_int(i);
	
	show_next_digit(); // show zero
	
	// Loop
	do 
	{
		U8 *test = (U8*)0x4010;
		U8 result;		
		if(((unsigned int)(Global_time - T_time) > DIGIT_PER) || (T_time > Global_time)) // set next timer value
		{
			T_time = Global_time;
			if(i && counter_enabled == 2)
			{
				PA_ODR |= (1<<2); // Relay is on
				i--;
				if(!i)
				{
					counter_enabled = 0;					
				}
			}
			else
			{
				PA_ODR &= ~(1<<2); // Relay is off
			}
			if((i % 100) > 59)
			{
				i -= 40;
			}
			if(counter_enabled == 1)
			{
				if(j)
				{
					j--;
					if(!j)
				  {
						i++;
					}
					if((j % 100) > 59)
					{
						j -= 40;
					}
				}
				if(!j)
				{
					counter_enabled = 2;
					add_minutes_to_eeprom(i/100);
				}
		  }
			if(counter_enabled == 1)
			{
				display_int(-j);
			}
			else
			{
				display_int(i);
			}
			
			//if(i > 9999) i = -1200;
			// check ADC value to light up DPs proportionaly
		
			// values less than 206 == 0
		}
		if((U8)(Global_time - T_LED) > LED_delay)
		{
			T_LED = Global_time;
			show_next_digit();	
			if(beep_delay)
			{
				beep_delay--;
				if(!beep_delay)
				{
					BEEP_CSR = 0x1e; // Configure BEEP
				}
			}
			if(show_time_delay)
			{
			  show_time_delay--;
				if(!show_time_delay)
				{
					i = 0; // Stop show time
				}
				
			}
		}
		result = scan_keys();		
		
		if(result & KEY_0_PRESSED) // Start
		{
			if(counter_enabled == 1 && j < 859) // 859 - wait 3 sec from 1-st start press
			{
				BEEP_CSR = 0xbe;
				beep_delay = 200;
				counter_enabled = 2;
				add_minutes_to_eeprom(i/100);
				i++;
				j = 0;
			}
			if(!counter_enabled)
			{
				BEEP_CSR = 0xbe;
				beep_delay = 10;
				if(show_time_delay == 0 && i>0)
				{
					counter_enabled = 1;
					j = 901; // 6 minutes pre time 
				}
				else
				{
					// Show Time
					i = work_hours->minutes + (int)(work_hours->hours_L) * 100 + (int)(work_hours->hours_H) * 10000;
					show_time_delay = 2450;
				}
		  }
		}
		else 
		{			
			if(result && show_time_delay)
			{
				i = 0;
				show_time_delay = 0;
			}			
			if(!counter_enabled)
			{
				if(result & KEY_3_PRESSED)
				{
					i+=100;
					display_int(i);
					BEEP_CSR = 0xbe;
					beep_delay = 10;
				}
				if(result & KEY_2_PRESSED)
				{
					if(i >= 100)
					{
						i-=100;
						display_int(i);
					}
					BEEP_CSR = 0xbe;
					beep_delay = 10;
				}
			}
		}
		
		if(result & KEY_1_PRESSED) //Stop
		{
			counter_enabled = 0;
			j = i = 0;
			display_int(i);
			BEEP_CSR = 0xbe;
			beep_delay = 40;
			show_time_delay = 0;			
		}
		if((result & KEY_PRESSED) == KEY_PRESSED && Global_time < 1000)
		{
			BEEP_CSR = 0xbe;
			beep_delay = 40;		
			clear_eeprom();
		}
		
		
	} while(1);
}
示例#23
0
文件: init.c 项目: lihebi/freescale
void select_plan() {
  unsigned long i;
  DDRB = 0xFF;
  DDRT = 0x04;
  PORTB = 0xFF;
  for (i=0; i<6000000; i++) {
    if (PORTA>100) {
      PTT_PTT2 = 1;
      PORTB_PB7 = ~PORTB_PB7;
      plan ++;
     _asm(nop);  
    	_asm(nop);  
    	_asm(nop);
   	_asm(nop);
   	    	_asm(nop);
   	_asm(nop);
   	    	_asm(nop);
   	_asm(nop);
   	    	_asm(nop);
   	_asm(nop);
   	    	_asm(nop);
   	_asm(nop);
    PTT_PTT2 = 0;
    }
  }
  for (i=0; i<1000000; i++) PORTB = 0;
}
uint8_t FlashEraseEW0( uint8_t block )
{
	volatile FLASH_PTR_TYPE flash_addr;
    uint8_t i, ret_value;

#if (STATIC_RAM_CODE == 0)
	/* Allocate RAM space to hold the CPU-Rewrite code on the stack. */
	uint8_t EW0_RAM_CODE[ RAM_CODE_SIZE ];
#endif

    /* Check if the RAM space is big enough to hold our re-write code */
   	asm("mov.w #((ERASE_CODE_END-ERASE_CODE_START+1)), _reflash_code_size");
    if( RAM_CODE_SIZE < reflash_code_size )
    {
        return 3;
    }

	/* Get highest even block address*/
	flash_addr = (FLASH_PTR_TYPE) block_addresses[ block ];

	/* Turn off maskable interrupts*/
	DISABLE_INTERRUPTS;	

	/* Specify to the assemble code below the RAM code address */
	EW0_RAM_CODE_ptr = (int32_t) EW0_RAM_CODE;

	/* Copy code to RAM using SMOVF instruction (faster than a loop in 'C') */
	/* Can use debugger to determine how big your RAM space needs to be */
	/* R8C and M16C */
#pragma ASM
	pushm	R1,R3,A0,A1
	/* transfer count (number of words ) */
	mov.w	#((ERASE_CODE_END-ERASE_CODE_START+1) / 2 ),R3	;
	/* source address */
	mov.b	#((ERASE_CODE_START >> 16) & 0FFh),R1H	;
	/* source address */
	mov.w	#(ERASE_CODE_START & 0FFFFh),A0			;
	/* destination address (stored in EW0_ARM_CODE_ptr)  */
	mov.w	_EW0_RAM_CODE_ptr,A1					;
	/* copy 16 bits at a time */
	smovf.w											;
	popm	R1,R3,A0,A1
#pragma ENDASM

	/* Set EW0 select bit */
	fmr01 = 0;
	fmr01 = 1;			

	/* !! DISABLE ALL FLASH MEMORY LOCK AND PROTECT FUNCTIONALITY !!
	 * NOTE: In order to use lock/protect bit functionality, please refer to
	 * the Flash Memory section in the data sheet for your specific device.
	 * Also note the that following bits clear back to 0 every time you enter
	 * CPU Rewrite Mode.
	 * Note that for some MCUs, if the lock bit is disabled, the error bits
	 * do not function.
	*/
#if R8C_FLASH == 1
	/* R8C/M12A Series */
	/* Lock bit disable select bit */
	fmr13 = 0;		
	/*   Must write a 0 then a 1 in succession to SET */
	fmr13 = 1;		
	/* Data flash block A rewrite enabled */
	fmr16 = 0;		
	/* Data flash block B rewrite enabled */
	fmr17 = 0;		

#endif 	

	/* Jump into RAM routine spcified by EW0_RAM_CODE_ptr */
	_asm("jmpi.a _EW0_RAM_CODE_ptr");	
	/* Create an address label so we know where copy code from	*/
	_asm("ERASE_CODE_START:");		
    /* Attempt to erase flash up to 3 times before returning failed */
    for( i = 0; i<3; i++)
    {
    	/* Clear status register	*/
		*flash_addr = 0x50;		
    	/* Send erase command	*/
		*flash_addr = 0x20;		
    	/* Send erase confirm command	*/
		*flash_addr = 0xD0;		

    	/* Note: In EW0 Mode, we need to poll the Ready/Busy bit until the operation completed */
        /* Wait for ready bit if executing in RAM for EW0 mode.*/
		/* Perform other time critical operations such as "kicking" the watchdog timer.*/
#if R8C_FLASH == 1
		/* R8C/M12A Series */
    	while(!fst7) 
		{ 
		}
#endif

    	/* Check if operation was successful */
#if R8C_FLASH == 1
		/* R8C/M12A Series */
		/* Erasing Successful?*/
    	if( !fst5 )     	
#endif
        {
            break;
        }
    }

   	/* Send Read Array command in order to tell flash controller
	   to go back into Flash Read mode (as opposed to Read Status mode) */
	*flash_addr = 0xFF;		

	/* Disable CPU rewriting commands by clearing EW entry bit */
	fmr0 = 0;
	_asm("nop");

	/* If in RAM, this will jump you back to flash memory */
	_asm("jmp.a ERASE_CODE_END");	
	_asm("ERASE_CODE_END:");
	

#if R8C_FLASH == 1
	/* R8C/M12A Series */
    /* Command Sequence Error?*/
	if( fst4 && fst5 )	
    {
        ret_value =  2;
    }
	/* Erasing error?*/
	else if( fst5 )		
	{
		ret_value =  1;
	}
    
	/* Erase Pass!!*/
	else                    
    {
        ret_value =  0;          
    }
#endif

	/* Restore I flag to previsous setting*/
	RESTORE_INTERRUPTS;         
	return ret_value;
}
uint8_t FlashWriteEW0(FLASH_PTR_TYPE flash_addr,
							BUF_PTR_TYPE buffer_addr,
							uint16_t bytes)
{
	uint8_t ret_value = 0;

#if (STATIC_RAM_CODE == 0)
	/* Allocate RAM space to hold the CPU-Rewrite code on the stack. */
	uint8_t EW0_RAM_CODE[ RAM_CODE_SIZE ];
#endif

    /* Check if the RAM space is big enough to hold our re-write code */
   	asm("mov.w #((WRITE_CODE_END-WRITE_CODE_START+1)), _reflash_code_size");
    if( RAM_CODE_SIZE < reflash_code_size )
    {
        return 4;
    }
	/* Turn off maskable interrupts*/
	DISABLE_INTERRUPTS;	

	/* Specify to the assemble code below the RAM code address */
	EW0_RAM_CODE_ptr = (int32_t) EW0_RAM_CODE;

	/* Copy code to RAM using SMOVF instruction (faster than a loop in 'C') */
	/* Can use debugger to determine how big your RAM space needs to be */
	/* R8C and M16C */
#pragma ASM
	pushm	R1,R3,A0,A1
	/* transfer count (number of words )*/
	mov.w	#((WRITE_CODE_END-WRITE_CODE_START+1) / 2 ),R3	;
	/* source address*/
	mov.b	#((WRITE_CODE_START >> 16) & 0FFh),R1H	;
	/* source address*/
	mov.w	#(WRITE_CODE_START & 0FFFFh),A0			;
	/* destination address (stored in EW0_RAM_CODE_ptr) */
	mov.w	_EW0_RAM_CODE_ptr,A1					;
	/* copy 16 bits at a time*/
	smovf.w											;
	popm	R1,R3,A0,A1
#pragma ENDASM

	fmr01 = 0;
	/* Set EW0 select bit*/
	fmr01 = 1;				

	/* !! DISABLE ALL FLASH MEMORY LOCK AND PROTECT FUNCTIONALITY !!
	 * NOTE: In order to use lock/protect bit functionality, please refer to
	 * the Flash Memory section in the data sheet for your specific device.
	 * Also note the that following bits clear back to 0 every time you enter
	 * CPU Rewrite Mode.
	 * Note that for some MCUs, if the lock bit is disabled, the error bits
	 * do not function.
	 */
#if R8C_FLASH == 1
	/* R8C/M12A Series */
	/* Lock bit disable select bit*/
	fmr13 = 0;		
	/* Must write a 0 then a 1 in succession to SET*/
	fmr13 = 1;		
	/* Data flash block A rewrite enabled*/
	fmr16 = 0;		
	/* Data flash block B rewrite enabled*/
	fmr17 = 0;		
#endif 	

	/* Jump into RAM routine spcified by EW0_RAM_CODE_ptr*/
	_asm("jmpi.a _EW0_RAM_CODE_ptr");	
	/* Create an address label so we know where copy code from*/
	_asm("WRITE_CODE_START:");			
	/* Clear status register*/
	*flash_addr = 0x50;		
	while(bytes)
	{
		/* Write to the flash sequencer by writting to that area of flash memory */
		/* Send write command	*/
		*flash_addr = 0x40;				
		/* Write next word of data	*/
		*flash_addr = *buffer_addr;		

    	/* Note: In EW0 Mode, we need to poll the Ready/Busy bit until the operation completed */
        /* Wait for ready bit if executing in RAM for EW0 mode.*/
		/* Perform other time critical operations such as "kicking" the watchdog timer.*/
#if R8C_FLASH == 1
		/* R8C/M12A Series */
    	while(!fst7) 
		{ 
		}
#endif

	#if R8C_FLASH == 1
		/* R8C/M12A Series */
		/* Read flash program status flag */
		/* Write error?*/
		if( fst4 )		
		{
            /* Command Sequence error ?*/
			if( fst5 ) 
    		{
				/* Signal a Command Sequence error*/
				ret_value = 3;		
			}	
			else
    		{
				/* Signal the flash would not write*/
				ret_value = 1;		
			}	
				
			/* Break out of while loop*/
			break;				
		}
	#endif

		/* Advance to next flash write address*/
		flash_addr++;			
		/* Advance to next data buffer address*/
		buffer_addr++;			

		/* NOTE: The R8C writes to flash a 8 bits at a time where as the M16C
		 * writes to flash 16 bits at a time. */
		/* Subract 1 from byte counter */ 
		bytes--;				
	}

	/* Send Read Array command in order to tell flash controller*/
	*flash_addr = 0xFF;		
	/* to go back into Flash Read mode (as opposed to Read Status mode)*/
	/* disable EW mode by clearing EW entry bit*/
	fmr0 = 0;				
	_asm("nop");
	/* If in RAM, this will jump you back to flash memory*/
	_asm("jmp.a WRITE_CODE_END");	
	_asm("WRITE_CODE_END:");
	/* Restore I flag to previous setting */
	RESTORE_INTERRUPTS;     
	/* Return Pass/Fail*/
	return ret_value;		
}
示例#26
0
static TARGET_INLINE void KERNEL_vEnterCriticalCode(void)
{
   ubStoredCCValue = (UBYTE)_asm("PUSH CC\nPOP A\nPUSH #0\nPOP CC");
   blKernelUpdateBlocked=TRUE;
}
示例#27
0
文件: main.c 项目: LiosonLiu/LoRa
//=====================================
void main()
//=====================================
{
	u16 i,j,k=0,g;
	SysTime 				= 0;
	SystemFlag 			= 0x00;
	mode 						= 0x01;//lora mode
	Freq_Sel 				= 0x00;//433M
	Power_Sel 			= 0x00;//
	Lora_Rate_Sel 	= 0x06;//
	BandWide_Sel 		= 0x07;
	Fsk_Rate_Sel 		= 0x00;
	
	_asm("sim");               //Disable interrupts.
	mcu_init();
	ITC_SPR4 = 0xf3;//time2 interrupt priority 2¡¢level13
	ITC_SPR5 = 0x3c;//UART1_RX ¡¢UART_TX interrupt priority 2
	ITC_SPR6 = 0x00;//UART3_RX ¡¢UART_TX interrupt priority 2
	_asm("rim");              //Enable interrupts.
	
	GREEN_LED_L();
	RED_LED_L();
	delay_ms(500);
	GREEN_LED_H();
	RED_LED_H();
	sx1278_Config();
  sx1278_LoRaEntryRx();
	TIM1_CR1 |= 0x01;			//enable time1
	MasterModeFlag=0;
	while(1)
	{
	if(GetOption())	//Slave
		{
		if(SystemFlag&PreviousOptionBit)
			{
			sx1278_LoRaEntryRx();
			SystemFlag&=(!PreviousOptionBit);
			}
		if(sx1278_LoRaRxPacket())
			{
			GREEN_LED_L();
			delay_ms(100);
			GREEN_LED_H();
			RED_LED_L();
			sx1278_LoRaEntryTx();
			sx1278_LoRaTxPacket();
			RED_LED_H();
			sx1278_LoRaEntryRx();
			}		
		}
	else					//Master
		{
		if((SystemFlag&PreviousOptionBit)==0)
			{
			MasterModeFlag=0;
			SystemFlag|=PreviousOptionBit;
			}			
		switch(MasterModeFlag)
			{
			case 0:
				if(time_flag==1)
				{
				time_flag=0;
				RED_LED_L();
				sx1278_LoRaEntryTx();
				sx1278_LoRaTxPacket();
				RED_LED_H();
				MasterModeFlag++;
				}
				break;
			case 1:
				sx1278_LoRaEntryRx();
				for(i=0;i<30;i++)
					{
					delay_ms(100);
					if(sx1278_LoRaRxPacket())
						{
						i=50;
						GREEN_LED_L();
						delay_ms(100);
						GREEN_LED_H();			
						}
					}
				MasterModeFlag++;
				break;
			case 2:
				if(time_flag==1)
					{
					time_flag=0;
					MasterModeFlag=0;
					}
				break;
			}
		}
	}
}
示例#28
0
void iduBarrier()
{
#if defined(HP_HPUX)
    _asm("SYNC");
#endif
}
示例#29
0
文件: delay.c 项目: RockyZ89/XS128
/******************
      ÑÓʱus
******************/
void delay_us(int n)         //10us 
{        
	while(n--){
	    _asm(nop);
	}
} 
示例#30
0
static TARGET_INLINE void KERNEL_vLeaveCriticalCode(void)
{
  blKernelUpdateBlocked=FALSE;
  _asm("PUSH A\nPOP CC\n", ubStoredCCValue);
}