经过修改,该程序可以通过发送带ON字符的字符串打开LED,或者通过发送带OFF的字符串关闭LED,并通过串口获取当前LED状态
#include "ML51.h"
void main (void)
{
unsigned char my[10];
unsigned char i=0;
MFP_P03_GPIO;
P03_PUSHPULL_MODE;
/**
For UART0 P0.5 asTXD output setting
* include uart.c in Common Setting for UART0
*/
MFP_P31_UART0_TXD; /* set P3.1 and P3.0 as Quasi mode for UART0 trasnfer */
MFP_P30_UART0_RXD;
P31_QUASI_MODE;
P30_QUASI_MODE;
UART_Open(24000000,UART0_Timer1,115200); // Open UART0 use timer1 as baudrate generate and baud rate = 115200
/**
UART0 loop test
UART0 TXD send data received by RXD pin. Connect TXD pin and RXD pin check result.
*/
while(1)
{
unsigned char temp;
temp = UART_Receive_Data(UART0);
UART_Send_Data(UART0,temp);
my[i++]=temp;
if(i>=10)
{
ENABLE_UART0_PRINTF;
printf ("\nHello\n");
DISABLE_UART0_PRINTF;
for(i=0;i<10;i++)
{
if(my[i]=='O')
{
if(my[i+1]=='N')
{
P03=0;
ENABLE_UART0_PRINTF;
printf ("\nLED is ON \n");
DISABLE_UART0_PRINTF;
}
else if(my[i+1]=='F')
{
if(my[i+2]=='F')
{
P03=1;
ENABLE_UART0_PRINTF;
printf ("\nLED is OFF \n");
DISABLE_UART0_PRINTF;
}
}
}
}
i=0;
}
}
}
|