串口进不了中断,请教马老师,谢谢!
使用icc编译串口调试助手发送1,但是助手收不到数据啊
查看eeprom里已经写入值了
请老师指点
#include <iom16v.h>
#include "macros.h" // 常用的宏定义
#include "eeprom.h"
#include "stdio.h"
#define uchar unsigned char
#define uint unsigned int
//eeprom区定义
#pragma data:eeprom
char table[]={0x01,0x02,0x03,0x04,0x05};
#pragma data: data
uchar *q=table;
int flag=UDR;
int i;
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}
/***************************************
串口输出函数
****************************************/
void putc(unsigned char c)
{
while (!(UCSRA&(1<<UDRE)));
UDR=c;
}
#pragma interrupt_handler uart0_rx_isr:12
void uart0_rx_isr(void)
{
//uart has received a character in UDR
if(flag==1)
{
for(i=0;i<=4;i++)
{
putchar(EEPROMread((unsigned int)(q++)));
}
}
}
void main()
{
CLI();
uart0_init();
SEI();
while(1)
{
;
}
} 最好的方法是用Studio软仿真一下,看什么地方没有设置。 建议LZ买本我的<M16>书参考学习吧.里面关于USART和RS232有2章内容.
页:
[1]