Demo entry 6762031

C

   

Submitted by anonymous on Oct 09, 2018 at 15:34
Language: C. Code size: 1.9 kB.

#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "key.h"

 

 int main(void)
 {	
	u8 t;
	u8 len;	
	u16 times=0; 
 
	delay_init();	    	 
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	uart_init(9600);	
	LED_Init();
	KEY_Init(); 	
 
	while(1)
	{
		if(USART_RX_STA&0x8000)
		{				   
			len=USART_RX_STA&0x3fff;
			printf("\r\n你好, \r\n");
			
			for(t=0;t<len;t++)
			{
				USART1->DR=USART_RX_BUF[t];
				while((USART1->SR&0X40)==0);
			}
			
			if (USART_RX_BUF[0]=='l'&&USART_RX_BUF[1]=='e'&&USART_RX_BUF[2]=='d'&&USART_RX_BUF[3]=='0'&&USART_RX_BUF[4]==' '&&USART_RX_BUF[5]=='o' && USART_RX_BUF[6]=='n'){
				LED0=0;
			}
			if(USART_RX_BUF[0]=='l'&&USART_RX_BUF[1]=='e'&&USART_RX_BUF[2]=='d'&&USART_RX_BUF[3]=='0'&&USART_RX_BUF[4]==' '&&USART_RX_BUF[5]=='o'&&USART_RX_BUF[6]=='f'&&USART_RX_BUF[7]=='f'){
				LED0=1;
			}
			if(USART_RX_BUF[0]=='l'&&USART_RX_BUF[1]=='e'&&USART_RX_BUF[2]=='d'&&USART_RX_BUF[3]=='1'&&USART_RX_BUF[4]==' '&&USART_RX_BUF[5]=='o'&&USART_RX_BUF[6]=='n'){
				LED1=0;
			}
			if(USART_RX_BUF[0]=='l'&&USART_RX_BUF[1]=='e'&&USART_RX_BUF[2]=='d'&&USART_RX_BUF[3]=='1'&&USART_RX_BUF[4]==' '&&USART_RX_BUF[5]=='o'&&USART_RX_BUF[6]=='f'&&USART_RX_BUF[7]=='f'){
			  LED1=1;
			}
			printf("\r\n\r\n");
			USART_RX_STA=0;
		}else
		{	
			t=KEY_Scan(0);
		  switch(t)
		  {				 
			  case KEY0_PRES:
				  printf("KEY0 pressed\r\n");
				  break;
			  case KEY1_PRES:
				  printf("KEY1 pressed\r\n");
				  break;
			  case WKUP_PRES:				
				  printf("WK_UP pressed\r\n");
				  break;
			  default:
					delay_ms(10);
		  }
			times++;
			if(times%5000==0)
			{
				printf("\r\n lab4串口实验\r\n");
				printf("CSE@SUSTech\r\n\r\n\r\n");
			}
			if(times%1000==0)printf("请输入数据,以回车结束\r\n");  
			if(times%30==0)LED0=!LED0;
			delay_ms(10);   
		}
	}	 
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).