我第一次使用ATMEGA128芯片,我用ICCAVR对一个简单的程序进行编译,然后用AVR STUDIO4.13下载到芯片然后运行,但是我发现程序在运行后跑飞了,我设置断点都不能停住,给我感觉就是程序进入子程序后竟然不能回到主程序了?请各位帮我看看是怎么回事,谢谢了,另程序附上
#include "Hardware.h" #include <macros.h>
void WDT_off(void){ WDTCR = (1<<WDCE) | (1<<WDE);//置位WDCE 和 WDE WDTCR = 0x00;//关闭WDT } void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x00; PORTD = 0x00; DDRD = 0x00; PORTE = 0x00; DDRE = 0x00; PORTF = 0x00; DDRF = 0x00; PORTG = 0x00; DDRG = 0x00; }
//TIMER0 initialize - prescale:Stop // WGM: Normal // desired value: 1Hz // actual value: Out of range void timer0_init(void) { TCCR0 = 0x00; //stop ASSR = 0x00; //set async mode TCNT0 = 0x00 /*INVALID SETTING*/; //set count OCR0 = 0x00 /*INVALID SETTING*/; TCCR0 = 0x00; //start timer }
//TIMER1 initialize - prescale:Stop // WGM: 0) Normal, TOP=0xFFFF // desired value: 1Hz // actual value: Out of range void timer1_init(void) { TCCR1B = 0x00; //stop TCNT1H = 0x00 /*INVALID SETTING*/; //setup TCNT1L = 0x00 /*INVALID SETTING*/; OCR1AH = 0x00 /*INVALID SETTING*/; OCR1AL = 0x00 /*INVALID SETTING*/; OCR1BH = 0x00 /*INVALID SETTING*/; OCR1BL = 0x00 /*INVALID SETTING*/; OCR1CH = 0x00 /*INVALID SETTING*/; OCR1CL = 0x00 /*INVALID SETTING*/; ICR1H = 0x00 /*INVALID SETTING*/; ICR1L = 0x00 /*INVALID SETTING*/; TCCR1A = 0x00; TCCR1B = 0x00; //start Timer }
//TIMER2 initialize - prescale:Stop // WGM: Normal // desired value: 1Hz // actual value: Out of range void timer2_init(void) { TCCR2 = 0x00; //stop TCNT2 = 0x00 /*INVALID SETTING*/; //setup OCR2 = 0x00 /*INVALID SETTING*/; TCCR2 = 0x00; //start }
//TIMER3 initialize - prescale:Stop // WGM: 0) Normal, TOP=0xFFFF // desired value: 1Hz // actual value: Out of range void timer3_init(void) { TCCR3B = 0x00; //stop TCNT3H = 0x00 /*INVALID SETTING*/; //setup TCNT3L = 0x00 /*INVALID SETTING*/; OCR3AH = 0x00 /*INVALID SETTING*/; OCR3AL = 0x00 /*INVALID SETTING*/; OCR3BH = 0x00 /*INVALID SETTING*/; OCR3BL = 0x00 /*INVALID SETTING*/; OCR3CH = 0x00 /*INVALID SETTING*/; OCR3CL = 0x00 /*INVALID SETTING*/; ICR3H = 0x00 /*INVALID SETTING*/; ICR3L = 0x00 /*INVALID SETTING*/; TCCR3A = 0x00; TCCR3B = 0x00; //start Timer }
//UART0 initialize // desired baud rate: 115200 // actual: baud rate:115200 (0.0%) // char size: 8 bit // parity: Disabled void uart0_init(void) { UCSR0B = 0x00; //disable while setting baud rate UCSR0A = 0x00; UCSR0C = 0x06; UBRR0L = 0x01; //set baud rate lo UBRR0H = 0x00; //set baud rate hi UCSR0B = 0xD8; }
#pragma interrupt_handler uart0_rx_isr:19 void uart0_rx_isr(void) { //uart has received a character in UDR }
#pragma interrupt_handler uart0_tx_isr:21 void uart0_tx_isr(void) { //character has been transmitted }
//UART1 initialize // desired baud rate:9600 // actual baud rate:9600 (0.0%) // char size: 8 bit // parity: Disabled void uart1_init(void) { UCSR1B = 0x00; //disable while setting baud rate UCSR1A = 0x00; UCSR1C = 0x06; UBRR1L = 0x17; //set baud rate lo UBRR1H = 0x00; //set baud rate hi UCSR1B = 0xD8; }
#pragma interrupt_handler uart1_rx_isr:31 void uart1_rx_isr(void) { //uart has received a character in UDR }
#pragma interrupt_handler uart1_tx_isr:33 void uart1_tx_isr(void) { //character has been transmitted }
//call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts // XDIV = 0x00; //xtal divider // XMCRA = 0x00; //external memory WDT_off(); port_init(); // timer0_init(); // timer1_init(); // timer2_init(); // timer3_init(); uart0_init(); uart1_init();
MCUCR = 0x80; EICRA = 0x00; //extended ext ints EICRB = 0x00; //extended ext ints EIMSK = 0x00; TIMSK = 0x00; //timer interrupt sources ETIMSK = 0x00; //extended timer interrupt sources // SEI(); //re-enable interrupts //all peripherals are now initialized }
void main(void){ init_devices(); PORTE=0xff; while(1); } |