zjybest 发表于 2007-6-4 15:21:31

实践中发现的问题

昨天焊了一个板子,写了一个非常简单的程序,通过ISP写入,运行正常,但是我又把程序放在AVR STDIO4里面纯软件仿真,在TIMER中断的入口加个断电,发现不能进入TIMER中断,奇怪.同时 PORTA口也没有变化.请马老师谈谈在AVRSTDIO纯软件仿真时遇到类似问题的解决方法.



#include <iom16v.h>

#include <macros.h>



void init_devices(void);



const unsigned char digital={0xFC,0x18,0xF2,0xBA,0x1E,0xAE,0xEE,0x38,0xFE,0xBE}; //数码管显示数字的预定义

unsigned char index=0;                   //显示数字的索引



void main(void)

{

init_devices();



while(1)//主循环

{

WDR();   //清看门狗

}

}



void port_init(void)

{

PORTA = 0xFF; //高电平数码管灭,低电平亮

DDRA= 0xFF; //PA口输出状态,连接数码管

PORTB = 0x00;

DDRB= 0x00;

PORTC = 0x00; //m103 output only

DDRC= 0x00;

PORTD = 0x00;

DDRD= 0x00;

}



//TIMER1 initialize - prescale:256

// WGM: 0) Normal, TOP=0xFFFF

// desired value: 1Hz

// actual value:1.000Hz (0.0%)

void timer1_init(void)

{

TCCR1B = 0x00; //stop

TCNT1H = 0x57; //setup

TCNT1L = 0x41;

OCR1AH = 0xA8;

OCR1AL = 0xBF;

OCR1BH = 0xA8;

OCR1BL = 0xBF;

//OCR1CH = $OCR1CH$;

//OCR1CL = $OCR1CL$;

ICR1H= 0xA8;

ICR1L= 0xBF;

TCCR1A = 0x00;

TCCR1B = 0x04; //start Timer

}



//时钟中断服务函数,1秒钟执行一次

#pragma interrupt_handler timer1_ovf_isr:9

void timer1_ovf_isr(void)

{

//TIMER1 has overflowed   //这里加断电不能断掉.

TCNT1H = 0x57; //reload counter high value

TCNT1L = 0x41; //reload counter low value



PORTA=~digital;

UDR=index;

index++;

if(index>=10)index=0;

}



//UART0 initialize

// desired baud rate: 9600

// actual: baud rate:9600 (0.0%)

// char size: 8 bit

// parity: Disabled

void uart0_init(void)

{

UCSRB = 0x00; //disable while setting baud rate

UCSRA = 0x00;

UCSRC = BIT(URSEL) | 0x06;

UBRRL = 0x47; //set baud rate lo

UBRRH = 0x00; //set baud rate hi

UCSRB = 0x18;

}



//call this routine to initialize all peripherals

void init_devices(void)

{

//stop errant interrupts until set up

CLI(); //disable all interrupts

port_init();

timer1_init();

uart0_init();



MCUCR = 0x00;

GICR= 0x00;

TIMSK = 0x04; //timer interrupt sources

SEI(); //re-enable interrupts

//all peripherals are now initialized

}

zjybest 发表于 2007-6-4 15:22:35

断电加在:

   void timer1_ovf_isr(void)

{

//TIMER1 has overflowed

TCNT1H = 0x57; //reload counter high value   //这里加断电不能断掉.

TCNT1L = 0x41; //reload counter low value



PORTA=~digital;

UDR=index;

index++;

if(index>=10)index=0;

}





TCNT1H = 0x57;   //这里加断电不能断掉.
页: [1]
查看完整版本: 实践中发现的问题