#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_uart_regs.h"
#include "sys/alt_irq.h"
#include "stdlib.h" //NULL需要定义
unsigned char rxdata;
void Set_baund(unsigned int buadrate)
{
unsigned int division;
division=(unsigned int)(ALT_CPU_FREQ/buadrate+0.5);
}
void UART_ISR(void)
{
//IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE,0x0);
if((IORD_ALTERA_AVALON_UART_STATUS(RS232_BASE)&0x80)==0x80)
{
rxdata=IORD_ALTERA_AVALON_UART_RXDATA(RS232_BASE);
while(IORD_ALTERA_AVALON_UART_STATUS(RS232_BASE)&0x80);
}
IOWR_ALTERA_AVALON_UART_TXDATA(RS232_BASE,rxdata);
while(!(IORD_ALTERA_AVALON_UART_STATUS(RS232_BASE)&0x40));//trdy=1,保持寄存器数据移到移位寄存器,传送准备好
//IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE,0x8);
}
void delay(unsigned long int time)
{
unsigned long int i;
for(i=0;i<time;i++);
}
void UART_Init(void)
{
Set_baund(115200);
IOWR_ALTERA_AVALON_UART_STATUS(RS232_BASE,0x0);
IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE,0x80);
alt_irq_register(RS232_IRQ,NULL,UART_ISR);
}
int main(void)
{
UART_Init();
// Set_baund();
while(1)
{
IOWR_ALTERA_AVALON_UART_TXDATA(RS232_BASE,1); IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE,0x8);
delay(1000000);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE,0xf);
delay(1000000);
}
}
串口调试工具波特率也是115200,但发送1时,调试显示收到的十六进制数据不是1,是39,十六进制发送也不对,哪个地方有问题?
IOWR_ALTERA_AVALON_UART_TXDATA(RS232_BASE,1)
此帖出自
小平头技术问答
一周热门 更多>