为什么我写的这个程序接受不到串口的数据,谁能帮我修改一下?
功能:使用串口UART0接收上位机发送的数据,当接收到8个连续数据后,将接收计数值加一后输
* 出数码管D1显示,并将数据原封不动地发送回上位机。
* 说明:将跳线器JP5、JP3短接。
* 通讯波特率115200,8位数据位,1位停止位,无奇偶校验。
#include "config.h"
#define HC595_CS (1<<29)
#define UART_BPS 115200
uint8 rcv_buf[8];
uint8 rcv_new;
uint8 const DISP_TAB[16] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xC6,0xA1,0x86,0x8E
};
void SPI_Init(void)
{
S0PCCR = 0x52;
S0PCR = 0x30;
}
void UART0_Init(void)
{
U0LCR = 0x83;
U0DLM = ((Fpclk / 16) / UART_BPS) / 256;
U0DLL = ((Fpclk /16) / UART_BPS) % 256;
U0LCR = 0x03;
}
void SendByte(uint8 data)
{
U0THR = data;
}
void SendBuf(void)
{
uint8 i;
for(i=0;i<8;i++)SendByte(rcv_buf[i]);
while ((U0LSR&0x20)==0);
}
void __irq IRQ_UART0(void)
{
uint8 i;
if((U0IIR & 0x0F) == 0x40) rcv_new = 1;
for(i=0;i<8;i++)
{
rcv_buf[i] = U0RBR;
}
VICVectAddr = 0x00;
}
uint8 HC595_SendDate(uint8 date)
{
IO0CLR = HC595_CS;
S0PDR = date;
while ( (S0PSR&0x80) == 0);
IO0SET = HC595_CS;
return(S0PDR);
}
int main(void)
{
uint8 rcv_counter;
rcv_counter = 0;
rcv_new = 0;
PINSEL0 = 0x00005505;
PINSEL1 = 0x00000000;
IO0DIR = HC595_CS;
UART0_Init();
SPI_Init();
U0IER = 0x01;
U0FCR = 0x81;
VICIntSelect = 0x00;
VICVectAddr0 =(int )IRQ_UART0;
VICVectCntl0 = 0x20 | 6;
VICIntEnable = 1<<6;
HC595_SendDate(DISP_TAB[2]);
while(1)
{
if(rcv_new==1)
{
SendBuf();
rcv_counter++;
HC595_SendDate(DISP_TAB[rcv_counter]);
rcv_new = 0;
}
}
return(0);
} |