AVR单片机:8515的UART串口接收中断问题
使用AT90S8515单片机进行UART串口通信,即:将单片机A与单片机B的TXD和RXD交叉连
接。然后把编译好的程序下载到A,而B用仿真器代替,我期望在AVR Studio中进行断点监视
串口的接收。 可是,当A向B发出数据的时候,仿真软件并不能进入中断!已经测量过了A的
TXD口(也就是B的RXD管脚),从示波器中看到所有的数据都是合法的,即:1位起始位,8
位数据位,1位停止位(无校验位)。当我在接收中断例程中设置断点,发现无论怎样,程
序都不会在断点处中断!!:-(
我的设备是这样的配置:
AT90S8515-8PC,8M晶振,AVRICE仿真器(红外壳)使用内部8M晶振,仿真软件:AVR
Studio3.53。
程序是简单的C语言测试程序,用ICCAVR6.22B编译器编译,程序如下:
/***************************************
Chip type : AT90S8515
Clock frequency : 8.000000 MHz
Memory model : Small
Internal RAM size: 512
External RAM size: 0
Data Stack size : 128
***************************************/
#include <io8515.h>
#include <stdio.h>
#include <ina90.h>
#define RXCIE 7
#define TXCIE 6
#define UDRIE 5
#define RXEN 4
#define TXEN 3
#define CHR9 2
#define RXB8 1
#define TXB8 0
#pragma interrupt_handler ext_int0:2
#pragma interrupt_handler uarti_rxd:10
#pragma interrupt_handler uart_empty:11
// 串口输入的字节数组
unsigned char SIn_Data[10];
// 串口输出的字节数组
unsigned char SOut_Data[10];
// nSInBytes: 串行收到的字节数
// nSOutBytes: 串行发送的字节数
unsigned char nSInBytes,nSOutBytes;
// RDYtoOUT_FLAG: 接收结束标志,下一步通过串口发
unsigned char RDYtoOUT_FLAG;
void init_system(void)
{
CLI();
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: off
GIMSK=0x00; // Clear general int flag
MCUCR=0x03; // Int0:rising edge
GIMSK=0x40; // Enabled int0
// UART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// UART Receiver: On
// UART Transmitter: On
UBRR=51; //对应8M,9600波特率
UCR=0xB8; //允许接收中断,发送寄存器空中断使能
// 允许接收和发送
SREG|=0x80; // 开中断
}
void ext_int0(void) // 采用外部中断0来使能串口发送
{
SIn_Data[0]=0;
RDYtoOUT_FLAG=0xFF;
GIMSK=0x00;
}
void uarti_rxd(void)
{
SIn_Data[nSInBytes]=UDR;
nSInBytes++;
if(nSInBytes>SIn_Data[0])
{
nSInBytes=0;
}
}
void uart_empty(void)
{
if(nSOutBytes>SOut_Data[0]) // 如果要发送的数据数组已完毕,则结束发送。
{
GIMSK=0x40;
UCR&=~(1<<UDRIE); // UART数据存储器空中断禁用
nSOutBytes=0;
UCR&=~(1<<TXEN); // 关闭发送器
UCR|=(1<<RXEN); // 接收使能
}
else
{
UDR=SOut_Data[nSOutBytes];
nSOutBytes++;
}
}
void transmit_uart(void)
{
RDYtoOUT_FLAG=0x00;
UCR&=~(1<<RXEN);
UCR|=1<<TXEN;
UCR|=(1<<UDRIE);
UDR=SOut_Data[0];
}
void main(void)
{
unsigned char i;
init_system();
SOut_Data[0]=9;
for(i=1;i<=9;i++)SOut_Data[i]=i;
while (1)
{
if(RDYtoOUT_FLAG==0xFF)transmit_uart();
}
}
发表时间:2002年1月16日12:51:00