Ejemplo n.º 1
0
//主函数
int main(void)
{
	OS_ERR err;
	CPU_SR_ALLOC();
	
	delay_init(168);  //时钟初始化
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组配置
	uart_init(115200);   //串口初始化
	LED_Init();         //LED初始化	
	LCD_Init();			//LCD初始化	
	KEY_Init();			//按键初始化
	BEEP_Init();		//初始化蜂鸣器
	FSMC_SRAM_Init();	//初始化SRAM
	my_mem_init(SRAMIN);//初始化内部RAM
	ucos_load_main_ui();//加载主UI
	
	OSInit(&err);		    //初始化UCOSIII
	OS_CRITICAL_ENTER();	//进入临界区			 
	//创建开始任务
	OSTaskCreate((OS_TCB 	* )&StartTaskTCB,		//任务控制块
				 (CPU_CHAR	* )"start task", 		//任务名字
                 (OS_TASK_PTR )start_task, 			//任务函数
                 (void		* )0,					//传递给任务函数的参数
                 (OS_PRIO	  )START_TASK_PRIO,     //任务优先级
                 (CPU_STK   * )&START_TASK_STK[0],	//任务堆栈基地址
                 (CPU_STK_SIZE)START_STK_SIZE/10,	//任务堆栈深度限位
                 (CPU_STK_SIZE)START_STK_SIZE,		//任务堆栈大小
                 (OS_MSG_QTY  )0,					//任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息
                 (OS_TICK	  )0,					//当使能时间片轮转时的时间片长度,为0时为默认长度,
                 (void   	* )0,					//用户补充的存储区
                 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项
                 (OS_ERR 	* )&err);				//存放该函数错误时的返回值
	OS_CRITICAL_EXIT();	//退出临界区	 
	OSStart(&err);      //开启UCOSIII
}
Ejemplo n.º 2
0
//ALIENTEK战舰STM32开发板实验3
//按键输入实验  
//技术支持:www.openedv.com
//广州市星翼电子科技有限公司 	 
 int main(void)
 {
 	u8 t;
	delay_init();	    	 //延时函数初始化	  
 	LED_Init();			     //LED端口初始化
	KEY_Init();              //初始化与按键连接的硬件接口
	BEEP_Init();         	 //初始化蜂鸣器端口
	LED0=0;					 //先点亮红灯
	while(1)
	{
 		t=KEY_Scan(0);		//得到键值
	   	if(t)
		{						   
			switch(t)
			{				 
				case KEY_UP:	//控制蜂鸣器
					LED4=!LED4;
					LED1=!LED1;
					LED2=!LED2;
					LED3=!LED3;
					break;
				case KEY_LEFT:	//控制LED0翻转
					LED1=!LED1;
					break;
				case KEY_DOWN:	//控制LED1翻转	 
					LED2=!LED2;
					break;
				case KEY_RIGHT:	//同时控制LED0,LED1翻转 
					LED3=!LED3;
					break;
			}
		}else delay_ms(10); 
	}	 
 }
Ejemplo n.º 3
0
int main(void)
{
	u8 key;
	Stm32_Clock_Init(336,8,2,7);
	delay_init(168);
	LED_Init();
	BEEP_Init();
	KEY_Init();
	LED0 = 0;	//点亮红灯
	
	while(1)
	{
		key = KEY_Scan(0);
//		key = KEY_Scan_Custom(0);
		if(key)//有按键按下
		{
			switch(key)
			{
				case WKUP_PRES: BEEP = !BEEP;break;
				case KEY2_PRES: LED0 = !LED0;break;
				case KEY1_PRES: LED1 = ~LED1;break;
				case KEY0_PRES: LED1 = !LED1; LED0 = !LED0;break;
			}
		}
		else
			delay_ms(10);
	}
	
}
Ejemplo n.º 4
0
void start_task(void *pdata)
{	
	
	OS_CPU_SR cpu_sr = 0;
	pdata = pdata;
	u8 err;
	delay_init(168);

	USART1_Init();//初始化
	LED_Init();
	BEEP_Init();

	pringf("Hello world\n");

	OS_ENTER_CRITICLE();	//进入临界区 无法被中断打断

	//创建系统定时器
	pTmrLed = OSTmrCreate(	0,//dly 计时前的延迟
				OS_TMR_CFG_TICKS_PER_SEC/2,//周期 宏本身表示1s
				OS_TMR_OPT_PERIODIC,//周期模式
				(OS_TMR_CALLBACK)LedTmrCallback,
				NULL,
				NULL,
				&err
				);//定时器时间到了 自动调用回调函数
	pTmrBeep = OSTmrCreate(	0,
				OS_TMR_CFG_TICKS_PER_SEC/2,
				OS_TMR_OPT_PERIODIC,
				(OS_TMR_CALLBACK)BeepTmrCallback,
				NULL,
				NULL,
				&err
				);

	//启动定时器
	if( OSTmrStart(pTmrLED,&err) == OS_TRUE )
	{
		printf("LED TMR Start.\n");
	}
	else
		printf("LED TMR Fail.\n");

	if( OSTmrStart(pTmrBeep,&err) == OS_TRUE )
	{
		printf("BEEP TMR Start.\n");
	}
	else
		printf("BEEP TMR Fail.\n");
	

	OS_EXIT_CRITICLE();		//退出临界区 可以被中断打断

	while(1)//一直延时 等待程序运行
		OSTimeDlyHMSM(0,0,0,500);
	

}
Ejemplo n.º 5
0
void beepTask(void *pdata)
{
	BEEP_Init();
	while(1)
	{
		OPEN_BEEP();
		Delay(100000);
		CLOSE_BEEP();
		Delay(100000);
	}	
}
Ejemplo n.º 6
0
//各个外设的初始化
void Peripheral_Init(void)
{
	// 中断向量表配置
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	
	PS_Init();	
    KEY_Init();	
	STATU_Init();
	LED_Init();
	BEEP_Init();
    CAN1_Init();
	CAN2_Init();
    OLED_Init();
    ADC_Configuration();
}
Ejemplo n.º 7
0
void beepTask(void *pdata)
{
    //int i = 0;
    INT8U err;
    BEEP_Init();
    while(1)
    {
        //等待信号量
        OSSemPend(pkey,0,&err);// 等待时间设置为0 表示死等待
        //蜂鸣器动作
        OPEN_BEEP();
        OSTimeDlyHMSM(0,0,0,50);
        CLOSE_BEEP();

    }
}
Ejemplo n.º 8
0
void beepTask(void *pdata)
{
	int i = 0;
	BEEP_Init();
	while(1)
	{
		OPEN_BEEP();
		//Delay(100000);//实际上是空语句 可以把这个时间让给优先级低的执行
		OSTimeDly(500);
		CLOSE_BEEP();
		//Delay(100000);
		OSTimeDly(500);//这个时候CPU可以去执行别的事情 可以执行多任务
		i++;
		if(i>=3)
		{
			OSTaskChangePrio(BEEP_TASK_PRIO,12);
			OSTaskDel(12);
			//先把蜂鸣器任务优先级改为12 然后删除第12优先级的任务 	
		}
	}	
}
Ejemplo n.º 9
0
/**
  * @brief  Main function.
  *
  * @param  None.
  * @retval int
  */
int main( void )
{
    GPIO_Init(GPIOD, GPIO_PIN_7, GPIO_MODE_OUT_PP_LOW_FAST);
    //GPIOD->DDR |= GPIO_PIN_7;
    //GPIOD->CR1 |= GPIO_PIN_7;
    GPIOD->ODR |= GPIO_PIN_7;

    BEEP_Init(BEEP_FREQUENCY_1KHZ);
    
    while(1)
    {
        //float _sqrt;
        //_sqrt = sqrtf(4.0);
        delay(30000);
        GPIOD->ODR ^= GPIO_PIN_7;
        BEEP_Cmd(ENABLE);
        delay(3000);
        BEEP_Cmd(DISABLE);
        delay(3000);
        BEEP_Cmd(ENABLE);
        delay(3000);
        BEEP_Cmd(DISABLE);
    }
}
Ejemplo n.º 10
0
static w_err_t   beep_init(w_chdev_s *dev)
{
    BEEP_Init();
    beepst[0] = 0;
    return W_ERR_OK;
}
Ejemplo n.º 11
0
void Beep_Init(BEEP_Frequency_TypeDef BEEP_Frequency)
{
    BEEP_Init(BEEP_Frequency);
    CLK_LSICmd(ENABLE);
    BEEP_Cmd(ENABLE);
}
Ejemplo n.º 12
0
/**
  * @brief Example main entry point.
  * @par Parameters:
  * None
  * @retval
  * None
  */
void main(void)
{

    u8 i = 0;

    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Initialization of I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);

    /* Initialization of I/O in Input Mode with Interrupt */
    GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_FL_IT);

    /* Initialization of the Interrupt sensitivity */
    EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);

    /* BEEP calibration */

    BEEP_LSICalibrationConfig(LSIMeasurment());

    GPIO_Write(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN)); /* All LEDs ON */

    /* Initialize SPI for LCD */
    SPI_DeInit();
    SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_128, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE, SPI_DATADIRECTION_1LINE_TX, SPI_NSS_SOFT, 0x07);
    SPI_Cmd(ENABLE);

    /* Initialize LCD */
    LCD_Init();

    /* Clear LCD lines */
    LCD_Clear();

    /* Enable general interrupts for Key button reading */
    enableInterrupts();

    LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER OFF");
    LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "   Press Key");

    while (1)
    {
        /* Check button status */
        if (ButtonPressed == TRUE) /* Button is pressed */
        {
            ButtonPressed = FALSE;
            /* Change BEEP frequency */
            switch (i)
            {
            case 0:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_1KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED1_PIN); /* LED1 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 1kHz");
                i = 1;
                break;
            case 1:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_2KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED2_PIN); /* LED2 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 2kHz");
                i = 2;
                break;
            case 2:
                BEEP_Cmd(DISABLE);
                Delay(100);
                BEEP_Init(BEEP_FREQUENCY_4KHZ);
                BEEP_Cmd(ENABLE);
                GPIO_Write(LEDS_PORT, LED3_PIN); /* LED3 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER 4kHz");
                i = 3;
                break;
            case 3:
                BEEP_Cmd(DISABLE);
                GPIO_Write(LEDS_PORT, LED4_PIN); /* LED4 ON */
                LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  BEEPER OFF");
                i = 0;
                break;
            default:
                break;
            }
        }

    }

}
Ejemplo n.º 13
0
__interrupt void SPI_IRQHandler(void)
{
    static u8 cnt = 0;
    u8 * data = getDataBuf();
    
    if(SPI_GetITStatus(SPI_IT_RXNE) != RESET){
        spi_cmd = SPI_ReceiveData();
        SPI_ClearITPendingBit(SPI_IT_RXNE); 
    }    
    if(SPI_GetITStatus(SPI_IT_TXE) != RESET){
        if(spi_cmd == 0xff)
            SPI_SendData(cnt);
        else if((spi_cmd & 0xc0) == 0x40)
            SPI_SendData(data[spi_cmd&0x3f]);
        else if((spi_cmd & 0xc0) == 0x80)
        {
            switch(buffer_s)
            {
            case 0:
              SPI_SendData(Rx_Buffer[spi_cmd&0x3f]);
              break;
#if defined(NEED_RESOLVE_INFO)             
            case 1:
              SPI_SendData(RxGGA[spi_cmd&0x3f]);
              break;
#endif // defined(NEED_RESOLVE_INFO)              
            case 2:
              SPI_SendData(DataP[spi_cmd&0x3f]);
              break;
            case 3:
              SPI_SendData(DataQ[spi_cmd&0x3f]);
              break;            
            default:
              SPI_SendData(data[spi_cmd&0x3f]);
              break;
            }
        }
        else if((spi_cmd & 0xf0) == 0x30)
            buffer_s = spi_cmd & 0xf;
        else if((spi_cmd & 0xfc) == 0x14)
        {
            switch(spi_cmd & 0x03)
            {
            case 0:
              BEEP_Cmd(DISABLE);
              SPI_SendData(spi_cmd);
              break;           
            case 1:
              BEEP_DeInit();
              BEEP_Init(BEEP_FREQUENCY_1KHZ);
              BEEP_Cmd(ENABLE);              
              SPI_SendData(spi_cmd);
              break;             
            case 2:
              BEEP_DeInit();
              BEEP_Init(BEEP_FREQUENCY_2KHZ);
              BEEP_Cmd(ENABLE);                  
              SPI_SendData(spi_cmd);
              break;
            case 3:
              BEEP_DeInit();
              BEEP_Init(BEEP_FREQUENCY_4KHZ);
              BEEP_Cmd(ENABLE);                  
              SPI_SendData(spi_cmd);
              break;            
            default:
              BEEP_Cmd(DISABLE);
              SPI_SendData(data[spi_cmd]);
              break;
            }            
        }
        else
            SPI_SendData(0x66);
        cnt ++;
        SPI_ClearITPendingBit(SPI_IT_TXE); 
    }
}
Ejemplo n.º 14
0
int main(void)
{		
//	u8 x=0;
	unsigned char status;
	u8 Data[16];
	u8 i;
	u8 k=0;//读写错误重试次数
	u8 j;
	
  
	USART1_Config();
	//printf("USART1_Config success\n");
	SysTick_Init();
	
	//printf("SysTick_Init success\n");
	SPI_FLASH_Init();
	//printf("SPI_FLASH_Init success\n");
	InitRc522();				
	//printf("InitRc522 success\n");
	TIM3_PWM_Init();
	//printf("TIM3_PWM_Init success\n");
	GPIO_OUT_Init();
	//NVIC_Configuration();
	EXTI_PB1_Config();
	EXTI_PB2_Config();
	BEEP_Init();
	beep_ok();
	
  	while(1) 
{	
		
			status = PcdRequest(PICC_REQIDL,CT);/*扫描卡*/
			status = PcdAnticoll(SN);/*防冲撞*/
			//printf("%d",status);
			if (status==MI_OK)
			{
				k=0;
				sn=((SN[0]<<24)|(SN[1]<<16)|(SN[2]<<8)|(SN[3]));
				//printf("MI_OK\n");
				//printf("%x\n",sn);
				
				if((sn==YANGCHENGUANG)||(sn==LIUZHIYU)||(sn==CHENDUYU)||(sn==WUPENG)||(sn==BLUECARD))
				{
					//printf("OPEN DOOR\n");
					beep_ok();
					opendoor();
				}
				
			}
			else
			{
				k++;
				if((k++)>20)
				{
					SPI_FLASH_Init();
					//printf("SPI_FLASH_Init success\n");
					Reset_RC522();
					//printf("InitRc522 success\n");
					k=0;
				}
			}
			delay_ms(100);
	}
}