[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] volatile with winavr2010
From: |
Leiu |
Subject: |
[avr-gcc-list] volatile with winavr2010 |
Date: |
Tue, 01 Jun 2010 08:14:07 +0700 |
Thanks all, But i can't find bug, Here is my full code
#include <avr/io.h>
#include <avr/interrupt.h>
#ifndef F_CPU
#define F_CPU 8000000
#endif
#include <util/delay.h>
volatile uint8_t first_edge = 'A';
void usart_initiation() {
UCSRA = 0; //Control register initiation, double transfer rate
UCSRB = (1<<TXEN)|(1<<RXEN); // enable transmitter and receiver
UBRRH = 0;
UBRRL = 51; // set baud rate = 9600
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // 8 bit data, 1 stop
bit
}
void avr2pc(uint8_t data)
{
loop_until_bit_is_set(UCSRA,UDRE);
UDR = data;
}
void timer1_init()
{
TCCR1A = 0x83; //Fast PWM 10 bit
TCCR1B = 0x45; //set prescale = 1024
TIMSK = 0x24; //enable timer1 overflow interrupt
TCNT1H = 0x00; //clear counter
TCNT1L = 0x00;
ICR1H = 0x00; //clear input capture
ICR1L = 0x00;
OCR1AH = 0xff; //set max pwm
OCR1AL = 0xff;
}
ISR(TIMER1_OVF_vect)
{
if(first_edge <= 'Z')
{
avr2pc(first_edge);
++first_edge;
}else
{
first_edge = 'A';
}
}
int main()
{
//char data;
PORTD = 0x00;
DDRD = (1<<PD1);
PORTA = 0xff;
DDRA = 0xff;
timer1_init();
usart_initiation();
sei();
while(1)
{
;
}
return 0;
}
Result : i can show 'A'! why?
Please help me!
- [avr-gcc-list] volatile with winavr2010,
Leiu <=