コード例 #1
0
ファイル: main.c プロジェクト: pliable3/STM32-Logic-Analyzer
/**
 * @brief  Program entry point.
 * @param  none
 * @retval 0
 */
int main(void) {
	RCC_ClocksTypeDef RCC_Clocks;

	SystemInit();

	// Get the clock rate so we can set the sampling rate correctly.
	RCC_GetClocksFreq(&RCC_Clocks);
	ClockRate = RCC_Clocks.HCLK_Frequency;

	// NOTE: STM generic

	// Our timer (TIM2) uses the APB1 (PCLK1) clock.
	TimerBaseClockRate = RCC_Clocks.PCLK1_Frequency;

	// Set the SysTick interrupt to fire once every millisecond.
	SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 1000);

	LedInit();

	// Turn the Orange LED on, signifying WAIT...
	LedSet(LED_ORANGE, LED_MODE_ON);

	UsartInit();
	Copyright();

	uint32_t commandTicks = Ticks;

	LedSet(LED_ORANGE, LED_MODE_OFF);

	// Loop forever...
	while (1) {
		if (SamplingActive) {
			LedSet(LED_RED, LED_MODE_OFF);

			// Turn the Blue LED on when sampling.
			LedSet(LED_BLUE, LED_MODE_ON);
			SampleLoop();
			LedSet(LED_BLUE, LED_MODE_OFF);
		}

		// Check for commands every 1/10 second.
		if ((Ticks - commandTicks) >= 100) {
			ProcessCommands();
			commandTicks = Ticks;
		}
	}
	return 0;
}
コード例 #2
0
ファイル: Led.c プロジェクト: dh-linghaibin/PL_Grst_Mini
/**********************************************函数定义***************************************************** 
* 函数名称: void LedInit(void) 
* 输入参数: void 
* 返回参数: void  
* 功    能: csh  
* 作    者: by lhb_steven
* 日    期: 2016/4/15
************************************************************************************************************/ 
void LedInit(void) { 
    PD_DDR_DDR4 = 1;
    PD_CR1_C14 = 1;
    PD_CR2_C24 = 0;
    
    LedSet(1);
}
コード例 #3
0
ファイル: Control.c プロジェクト: LIKAIMO/newLBR
/****** press key to unlock crazepony****/
void KeyLockcrazepony(void)
{
	u8 i;
	
	if(0 == ++cnt){
		//防止数据溢出
		cnt = 3;
	}
	
	switch( Lockflag )
	{
		case 1:
				//解决按键连按的毛刺
				//本函数会被主循环10Hz调用,测试发现cnt为1或者2的时候,(200ms以下),属于按键毛刺,应该剔除
				if(cnt < 3){
					//printf("invalid key press:%d\n",cnt);
					cnt = 0;
					Lockflag = 0;
					break;
				}else{
					cnt = 0;
				}
		
				if(Locksta == 0xa5) 
				{
					for(i=0;i<5;i++)         
					CommUAVUpload(MSP_ARM_IT);   //unlock Crazepony
					Locksta = 0x5a;
					Lockflag = 0;
				}
					
				else if(Locksta == 0x5a )
				{
					for(i=0;i<5;i++)         
					CommUAVUpload(MSP_DISARM_IT);	//lock Crazepony
					Locksta = 0xa5;
					Lockflag = 0;
				}
			break;
		case 0:
			if(Locksta == 0x5a)   LedSet(led5,1);
			else if(Locksta == 0xa5) LedSet(led5,0);
			break;
	}	
}
コード例 #4
0
ファイル: Control.c プロジェクト: LIKAIMO/newLBR
/*IMUcalibrate  */
void IMUcalibrate(void)
{
	  LedSet(led4,IMUcalibratflag);
	  if(IMUcalibratflag) 
			{
				CommUAVUpload(MSP_ACC_CALI);
				IMUcalibratflag = 0;
			}
}
コード例 #5
0
__irq __arm void IRQ_Handler(void)
{
   switch((0xff & IRQIVEC)-1)
  {
   case CIM_MIBADCE1  :                   // channel 27 (AD1) interrupt?
      LedSet(ADDR0);
      break;
  }
}
コード例 #6
0
void DispatcherTask ( void * pvParameters )
{
	struct ADispatcherMessage *pxDispatcherMessage;
	struct ALCDMessage xLCDMessage, *pxLCDMessage = & xLCDMessage;

	UB_RTC_Init ( );
	LedInit ( );

	xDispatcherQueue = xQueueCreate ( 8, sizeof ( unsigned long ) );

	while ( 1 )
	{
		SendTimeToLCD ( pxLCDMessage );

		if ( xQueueReceive ( xDispatcherQueue, & ( pxDispatcherMessage ), 250 / portTICK_RATE_MS ) )
		{
			if ( !strnicmp ( pxDispatcherMessage->Domain, "HELP", 3 ) )
			{
				PrintHelp ( );
			}
			else if ( !strnicmp ( pxDispatcherMessage->Domain, "RTC", 3 ) )
			{
				if ( !strnicmp ( pxDispatcherMessage->Command, "SET", 3 ) )
				{
					SetRTCTime ( pxDispatcherMessage->Parameter );
				}
				else if ( !strnicmp ( pxDispatcherMessage->Command, "GET", 3 ) )
				{
					GetRTCTime ( );
				};
			}
			else if ( !strnicmp ( pxDispatcherMessage->Domain, "AUDIO", 5 ) )
			{
				ForwardAudioMessage ( pxDispatcherMessage->Command, pxDispatcherMessage->Parameter );
			}
			else if ( !strnicmp ( pxDispatcherMessage->Domain, "LED", 3 ) )
			{
				if ( !strnicmp ( pxDispatcherMessage->Command, "SET", 3 ) )
				{
					LedSet ( pxDispatcherMessage->Parameter );
				}
				else if ( !strnicmp ( pxDispatcherMessage->Command, "GET", 3 ) )
				{
					LedGet ( pxDispatcherMessage->Parameter );
				};
			}
			else
			{
			};
		};
	};
};
コード例 #7
0
ファイル: Control.c プロジェクト: LIKAIMO/newLBR
void controlClibra(void)
{
	static u8 i;
	uint16_t sum[4]={0,0,0,0};
	static int8_t lednum=1;
  static int8_t clibrasumNum = 20;

	if((ClibraFlag == FAIL))//校准失败
	{

		for(i=0;i<clibrasumNum;i++)
		{
			#ifdef AMERICAN_RC_MODE
			sum[0] += 1000 + (1000 - (1000*Get_Adc_Average(3,15))/4096);
			sum[1] += 1000 + (1000*Get_Adc_Average(1,15))/4096;
			#else
			sum[0] += 1000 + (1000*Get_Adc_Average(1,15))/4096;
			sum[1] += 1000 + (1000 - (1000*Get_Adc_Average(3,15))/4096);
			#endif
			sum[2] += 1000 + (1000*Get_Adc_Average(0,15))/4096;
			sum[3] += 1000 + (1000*Get_Adc_Average(2,15))/4096;
			delay_ms(100);
			
			if(++lednum == led5 + 2)lednum = 2;
			LedSet(lednum - 1,0);
			LedSet(lednum ,1);
		}
		
		Throttle_Calibra = sum[0]/i;
		Pitch_Calibra    = sum[1]/i;
		Roll_Calibra     = sum[2]/i;
		Yaw_Calibra      = sum[3]/i;

		
// 		Throttle_Calibra = 1500;
// 		Pitch_Calibra    = 1500;
// 		Roll_Calibra     = 1500;
// 		Yaw_Calibra      = 1500;

		LoadRCdata();               //摇杆赋值
		if((Throttle>=1510)||(Throttle<1490)||(Pitch>=1510)||(Pitch<=1490)||(Roll>=1510)||(Roll<=1490)||(Yaw>=1510)||(Yaw<=1490))
						ClibraFlag       = FAIL;//校准失败
		else 		ClibraFlag       = OK;//校准成功标志
		
					
		
		SaveParamsToEEPROM();
		LedSet(led2,0);LedSet(led3,0);LedSet(led4,0);LedSet(led5,0);
	 }	
	
}
コード例 #8
0
ファイル: main.c プロジェクト: dh-linghaibin/Eds_Watch
int main( void ) {
    SysInit();
    EeepromInit();
    TimerInit();
    ComInit();
    Ds1302Init();
    HtlcdInit();
    BottonInit();
    LedInit();
    MenuInit();
    INTEN
    while(1) {
        u8 botton_bit = 0;
        if(TimerGetSec() > 20) {
            TimerSetSec(0);
            SysSleep();
        }
        if(TimerGetTimeFlag() > 0x01) {
            TimerSetTimeFlag(0);
            MenuRefreshTime();
        }
        MenuFlickerServerTime();
        botton_bit = BottonRead();
        if(botton_bit > 0x01) {
            TimerSetSec(0);
            SysOpen();
        }
        switch(botton_bit) {
            case 0x01:
                MenuSetFeatures(7);
            break;//后减档
            case 0x02:
                MenuSetFeatures(5);
            break;//后加档
            case 0x03:
                MenuSetFeatures(4);
            break;//前换挡
            case 0x11:
                MenuSetFeatures(1);
            break;//区域3
            case 0x12:
                MenuSetFeatures(6);//1
            break;//区域2
            case 0x13:
                MenuSetFeatures(8);
            break;//区域1
            case 0x14:
                MenuSetFeatures(2);
            break;//区域1
            case 0x15:
                MenuSetFeatures(3);
            break;//放开信号
        }
        
        if(ComGetFlag() == 0x80) {
            ComClearFlag();
            LedSet(0);
            switch(ComGetData(0)) {
                case front:
                    switch(ComGetData(1)) {
                        case dce_gear:
                            MenuSetStalls(front,ComGetData(2)+1);
                            MenuSetBattery(ComGetData(3));
                        break;
                    }
                break;
                case behind: 
                    switch(ComGetData(1)) {
                        case dce_gear:
                            MenuSetStalls(behind,ComGetData(2));
                            MenuSetBattery(ComGetData(3));
                        break;
                    }
                break;
                case dce_powe:
                    MenuSetBattery(ComGetData(1));
                break;
            }
        }
    }
}
コード例 #9
0
void LedOff(byte x, byte y, byte z) {
    LedSet(x, y, z, 0);
}
コード例 #10
0
void LedOn(byte x, byte y, byte z) {
    LedSet(x, y, z, 1);
}
コード例 #11
0
ファイル: main.c プロジェクト: pliable3/STM32-Logic-Analyzer
/**
 * @brief  Get samples from the input pins and queue them for output via USART.
 *         The loop continues even after the sampling time is over in order to
 *         clear the queue.
 * @param  none
 * @retval none
 */
static void SampleLoop() {
	uint32_t startTicks;

	// In compression mode, initialize and send a "start compression" marker.
	if (SamplingCompression) {
		// Initialize compression, sending a pointer to the callback
		// function below that will receive the compressed data.
		if (CompressInit(&SendCompressedByte) < 0) {
			LedSet(LED_RED, LED_MODE_ON);
			return;
		}
		UsartSendString("<cmp>");
	}

	// Clear the output queue and set the timer to send an interrupt at our
	// current sampling rate.
	ClearSampleQueue();
	TimerInit(TimerBaseClockRate, SamplingRate);

	// Get our start time.
	startTicks = Ticks;

	// Loop until our time is up.
	while (1) {
		if (!SampleQueueIsEmpty()) {
			// Send the next available sample to the output.
			if (SamplingCompression) {
				CompressByte(DequeueSample());
			} else
				UsartSendChar(DequeueSample());
			LedSet(LED_ORANGE, LED_MODE_OFF);
		} else {
			// If the queue is empty and sampling is not active, we're done.
			if (!SamplingActive)
				break;
			LedSet(LED_ORANGE, LED_MODE_ON);
		}

		// Turn on the RED LED if the queue is full.
		if (SampleQueueIsFull()) {
			LedSet(LED_RED, LED_MODE_ON);
		} else
			LedSet(LED_RED, LED_MODE_OFF);

		// 'startTicks' is the millisecond count of when we started sampling.
		// 'Ticks' is the millisecond count now.
		if (SamplingActive && ((Ticks - startTicks) > SamplingTime)) {
			// Turn sampling off when time expires.
			// But continue in the loop until the queue is empty.
			TimerDenit();

			// If we're in transition-only mode, we need to send a final sample
			// to expand to the full sample time.
			if (SamplingMode == SAMPLING_MODE_TRANSITIONONLY)
				EnqueueFinalSample();

			SamplingActive = 0;
		}
	}

	// If compression is active, de-intialize and send and "stop compression" marker.
	if (SamplingCompression) {
		CompressFlush();
		CompressDenit();
		UsartSendString("</cmp>");
	}

	// If we had an overflow (i.e. we are sending data to the queue faster than it can be
	// sent out,) turn on the RED LED and send an overflow error.
	if (Overflow) {
		LedSet(LED_RED, LED_MODE_ON);
		UsartSendString("<err>Overflow</err>");
	}
}
コード例 #12
0
int main(void)
{
	static char ledsta;
	/***********************************/
	SystemClock_HSI(9);           //系统时钟初始化,时钟源内部HSI
	cycleCounterInit();				    // Init cycle counter
	SysTick_Config(SystemCoreClock / 1000);	//SysTick开启系统tick定时器并初始化其中断,1ms
	UART1_init(SysClock,uart1baudSet); //串口1初始化
  NVIC_INIT();	                //中断初始化
  STMFLASH_Unlock();            //内部flash解锁
  LoadParamsFromEEPROM();				//加载系统参数配置表
  LedInit();	                  //IO初始化
  Adc_Init();										//摇杆AD初始化
	KeyInit();										//按键初始化
 	NRF24L01_INIT();              //NRF24L01初始化
  SetTX_Mode();                 //设无线模块为接收模式
  controlClibra();							//遥控摇杆校准
#ifdef UART_DEBUG  
	TIM3_Init(SysClock,2000);			//定时器初始化,1s为周期打印摇杆值
#endif
	TIM4_Init(SysClock,TIME4_Preiod);	  //定时器4初始化,定时时间单位:(TIME4_Preiod)微秒
	
	LedSet(led2,1);
	LedSet(led3,1);
	
	LoadRCdata();                //摇杆赋值
	//RockerUnlockcrazepony();	 //摆杆启动
  Lockflag = 0;								 //解锁标志,1表示产生了一次按键操作,0表示该按键操作已经发送到飞控
	
  LedSet(led2,0);
	LedSet(led3,0);
	 
  while (1)             
	{ 
		//10Hz loop
		if(flag10Hz == 1)  //10Hz 
		{		
			flag10Hz = 0;
			/*status led*/
			ledsta = !ledsta;
			LedSet(signalLED,ledsta);				        
			/*crazepony Lock*/
			KeyLockcrazepony();
			/*IMUcalibrate  */
			IMUcalibrate();
			/*remote calibrate*/
			Remotecalibrate();
		}

		//50Hz loop
		if(flag50Hz == 1)
		{
			LoadRCdata();
			flag50Hz = 0;
			
		}
		
		// 80Hz 12.5ms
		if(flag80Hz)
		{
			flag80Hz = 0;
			CommUAVUpload(MSP_SET_4CON);   
		}
	}
}
コード例 #13
0
ファイル: led.c プロジェクト: busmaster/homebus
/*-----------------------------------------------------------------------------
*  Led Initialisierung
*/
void LedInit(void) {

   LedSet(eLedRedOff);
   LedSet(eLedGreenOff);
}