|
串口通讯 我用中断方式接受 怎么老式不行啊 请大虾们帮我看看啊 不胜感激!!!>>>>>>
[复制链接]
#include "config.h"
uint16 Fdiv;
uint8 p;
uint8 flag_ri;
void __irq IRQ_UART0(void)
{
if(0x04==(U0IIR&0x0f))
{
p=U0RBR;
flag_ri=1;
}
VICVectAddr=0x00;
}
void DelayNS(uint32 dly)
{
uint32 i;
for (;dly>0;dly--)
for (i=0;i<50000;i++);
}
int main()
{
VICIntSelect=0x00000000;
VICVectCntl0=0x26;
VICVectAddr0=(uint32)IRQ_UART0;
VICIntEnable=0x00000040;
PCONP |= 0x08;
PINSEL0=0x00000005;
PINSEL1=0x00000000;
U0LCR=0X83;
Fdiv = (Fpclk / 16) / 38400; // 设置波特率
U0DLM = Fdiv>>8;
U0DLL = Fdiv&0xff;
U0LCR=0X03;
U0FCR=0X07;
U0IER=0x01;
while(1)
{
if(flag_ri==1)
{
U0THR=p;
while( (U0LSR&0x20)==0 );
DelayNS(10);
flag_ri=0;
}
}
return 0;
}
|
|