今天下午做了串口实验,不过是用的查询方式做的。明天继续吧,用中断方式实现串口通信!哈哈,有点小的成就感!把代码贴出来吧,我用的是周立功的模板。
//串口查询通讯
#include "config.h"
#define UART_BPS 9600
//从上位机接受字符串并保存
void GetStrFromPC(uint8 *s,uint32 n)
{
uint8 str;
for(;n>0;n--)
{
while((U0LSR&0x01)==0);
str=U0RBR;
*s++=str;
}
//return
}
//想串口0发送数据
void PushDataToUART(uint8 *PushData)
{
while(1)
{
if(*PushData=='/0')
break;
U0THR=*PushData++;
while((U0LSR&0x40)==0);
}
}
void delay(uint32 n)
{
uint32 i;
for(;n>0;n--)
for(i=0;i<5000;i++)
;
}
int main (void)
{// add user source code
uint8 snd[32];
uint16 f;
&n