void UartPrg(void)
{
uint8_t i,j;
/*Receive Checksum check*/
if(rx_end == 1)
{
rx_end = 0;
g_uart1_rx_length = uart_rx_buf[3]+4;
rx_checksum = 0;
i=0;
while(i < g_uart1_rx_length)
{
rx_checksum += uart_rx_buf[i];
i++;
}
if(rx_checksum == uart_rx_buf[g_uart1_rx_length])
{
work_begin = 1; //Command response flag
}
}
/*Send*/
if(send_begin == 0)
return;
send_begin = 0;
g_uart1_tx_count = 0;
uart_tx_buf[0] = 0xAA;
uart_tx_buf[1] = 0x55;
g_uart1_tx_length = uart_tx_buf[3]+4;
j = 0;
tx_checksum = 0;
while(j<g_uart1_tx_length)
{
tx_checksum += uart_tx_buf[j];
j++;
}
uart_tx_buf[g_uart1_tx_length] = tx_checksum;
STMK1 = 1;
TXD1 = uart_tx_buf[0];
STMK1 = 0;
}
/* End user code. Do not edit comment generated here */
/***********************************************************************************************************************
* Function Name: r_uart1_interrupt_receive
* Description : This function is INTSR1 interrupt service routine.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void __near r_uart1_interrupt_receive(void)
{
volatile uint8_t rx_data;
rx_data = RXD1;
if(work_begin == 0)
{
if(g_uart1_rx_count == 0)
{
if(rx_data == 0x55)
{
uart_rx_buf[0] = rx_data;
g_uart1_rx_count++;
}
}
else if(g_uart1_rx_count == 1)
{
if(rx_data == 0xAA)
{
uart_rx_buf[1] = rx_data;
g_uart1_rx_count++;
}
}
else if(g_uart1_rx_count <= 3)
{
uart_rx_buf[g_uart1_rx_count] = rx_data;
g_uart1_rx_count++;
}
else
{
if(g_uart1_rx_count <= 255)
{
uart_rx_buf[g_uart1_rx_count] = rx_data;
g_uart1_rx_count++;
if(g_uart1_rx_count >=(uart_rx_buf[3]+5))
{
g_uart1_rx_count = 0;
rx_end = 1; //receive end flag
}
}
else
{
g_uart1_rx_count = 0;
}
}
}
}
/***********************************************************************************************************************
* Function Name: r_uart1_interrupt_send
* Description : This function is INTST1 interrupt service routine.
* Arguments : None
* Return Value : None
***********************************************************************************************************************/
static void __near r_uart1_interrupt_send(void)
{
g_uart1_tx_count++;
if(g_uart1_tx_count<(uart_tx_buf[3]+5))
{
TXD1 = uart_tx_buf[g_uart1_tx_count];
}
else
{
g_uart1_tx_count = 0;
}
}
|