我用atmega128软仿真时,程序发送完数据后,跳不出中断,大侠帮忙看看,我是从51转过来的菜鸟。源程序在winavr下做的,在avr studio 4 下调用elf文件软仿真。 #include <stdio.h> #include <stdlib.h> #include <avr/io.h> #include <avr/interrupt.h> #include <util/twi.h> /* Note [1] */ #include <util/delay.h> #include <math.h> // unsigned char tro_buf[10]; // unsigned char tran_len; unsigned char out_index; unsigned char zzz; // void uart_init(void) { UCSR0A = 0x00; UCSR0C=(1<<UCSZ01)|(1<<UCSZ00);// 8位数据,1位停止位,无校验 UCSR0B=(1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0)|(1<<TXCIE0); //允许发送,接受,发送完中断,接受完中断 UBRR0L=103; //baud=9600 UBRR0H=0; } //中断发送子程序 SIGNAL (SIG_USART0_TRANS) { if(--tran_len > 0) { UDR0 = tro_buf[++out_index]; } else { zzz=0; //发送结束. 程序停留到这里,跳不出去了。不知为什么。奇怪!!!!! } } /************************************************/ int main(void) { uint16_t a; uart_init(); tro_buf[0] = 0x06; tro_buf[1] = 0x07; tro_buf[2] = 0x08; tro_buf[3] = 0x09; tro_buf[4] = 0x0a; tro_buf[5] = 0x0b;// tran_len = 5; SREG = 0X80; while(1) { out_index = 1; UDR0 = tro_buf[0]; //发送第一个数,启动发送中断 while(tran_len>0); a = 8; } }
|