⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usart.c

📁 ST最新的Cortext-M3内核的ARM触摸屏演示工程
💻 C
字号:
#include "public.h"

u16 return_a_row(u16 row, u8 input_window);
void clear_window(u8 input_window);
vu8 usart_input[20];
vu8 usart_output[40];
vu8 * usart_iup = usart_input;
vu8 * usart_ipp = usart_input;
vu8 * usart_oup = usart_output;
vu8 * usart_opp = usart_output;

	/* USART1 configuration ------------------------------------------------------*/
  	/* USART and USART2 configured as follow:
        - BaudRate = 9600 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  	*/
void USART1_Init(void)
{
	USART_InitTypeDef USART_InitStructure;
  	USART_InitStructure.USART_BaudRate = 9600;
  	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  	USART_InitStructure.USART_StopBits = USART_StopBits_1;
  	USART_InitStructure.USART_Parity = USART_Parity_No;
  	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  	/* Configure USART1 */
  	USART_Init(USART1, &USART_InitStructure);
  
  	/* Enable USART1 Receive and Transmit interrupts */
  	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  	//USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

  	/* Enable the USART1 */
  	USART_Cmd(USART1, ENABLE);
}

void analyze_usart_input(void)
{
	static u8 row = 35;
	static u8 col = 2;
	u8 chr;
	if(usart_ipp != usart_iup)
	{
		chr = *usart_ipp++;
		if(usart_ipp > ((vu8 *)usart_input) + 19)
		{
			usart_ipp = (vu8 *)usart_input;
		}
		if(13 == chr)
		{
			append_string_2_usart_output("@return command is resieved!!!");
			row = return_a_row(row, 0);
			col = 2;
		}
		else if(27 == chr)
		{
			append_string_2_usart_output("@clear command is resieved!!!");
			clear_window(0);
			row = 35;
			col = 2;
		}
		else if((0x20 <= chr) && (0x80 > chr))
		{
			set_position(col, row);
			lcm_data_write(chr);
			col++;
			if(col > 37)
			{
				row = return_a_row(row, 0);
				col = 2;
			}
		}
		else
		{
			append_string_2_usart_output("@unknown command is resieved!!!");
		}
	}
}

u16 return_a_row(u16 row, u8 input_window)
{
	u16 tmp;
	if(0x00 == input_window)
	{
		tmp = 115;
	}
	else
	{
		tmp = 221;
	}
	row += 16;
	if(row >= tmp)
	{
		row = tmp - 80;
	}
	display_ram_string(2, row, "                                    ", 0x20);
	return row;
}

void clear_window(u8 input_window)
{
	u16 sr, er;
	if(0x00 == input_window)
	{
		sr = 35;
		er = 115;
	}
	else
	{
		sr = 141;
		er = 221;
	}
	while(sr < er)
	{
		display_ram_string(2, sr, "                                    ", 0x20);
		sr += 16;
	}
}

void append_string_2_usart_output(u8 * string)
{
	u8 * tmpp;
	static u8 row = 141;
	static u8 col = 2;
	while(0x00 != (*string))
	{
		tmpp = (u8 *)usart_opp;
		tmpp++;
		if(tmpp > ((u8 *)usart_output) + 39)
		{
			tmpp = (u8 *)usart_output;
		}
		*tmpp = *(string++);

		set_position(col, row);
		lcm_data_write(*tmpp);
		col++;
		if(col > 37)
		{
			row = return_a_row(row, 1);
			col = 2;
		}
		
		usart_opp = tmpp;
		if(RESET == USART_GetITStatus(USART1, USART_IT_TXE))
		{
   			USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
		}
	}
		   
	if(col != 2)
	{
		row = return_a_row(row, 1);
		col = 2;
	}
}

void analyze_usart_output(void)
{
	u8 string[] = "@Touched at (xxx,xxx)!!!";
	u16 x, y;
	if(0x00 != get_touch() && ((vu32)0 == main_timer))
	{
		x = touch_x;
		y = touch_y;
		string[13] = (x / 100) + '0';
		x %= 100;
		string[14] = (x / 10) + '0';
		string[15] = (x % 10) + '0';

		string[17] = (y / 100) + '0';
		y %= 100;
		string[18] = (y / 10) + '0';
		string[19] = (y % 10) + '0';
		append_string_2_usart_output(string);
		main_timer = 200;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -