milan.rajik
Banned

Please provide a sample IAR AVR C Code for LED Blinking using Timer1 interrupt. I am new to IAR AVR Compiler. I have done LED Blinking project using delays and it works fine. I need code with Timer interrupts for ATMega32.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 #include <iom32.h> #include <intrinsics.h> // structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0 PORTB.7 -> PORT_B.b7 typedef struct{ char b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } bits; // define all the ports of your microcontroller, add more ports depending on the available mcu ports #define PORT_A (* (volatile bits *) &PORTA) #define PIN_A (* (volatile bits *) &PINA) #define DDR_A (* (volatile bits *) &DDRA) #define PORT_B (* (volatile bits *) &PORTB) #define PIN_B (* (volatile bits *) &PINB) #define DDR_B (* (volatile bits *) &DDRB) #define PORT_C (* (volatile bits *) &PORTC) #define PIN_C (* (volatile bits *) &PINC) #define DDR_C (* (volatile bits *) &DDRC) #define PORT_D (* (volatile bits *) &PORTD) #define PIN_D (* (volatile bits *) &PIND) #define DDR_D (* (volatile bits *) &DDRD) void Delay_ms() { unsigned int i, j; for(i = 0; i < 127; i++) for(j = 0; j < 1275; j++); } #pragma vector = TIMER1_COMPA_vect void interrupt_ISR_TIMER1_COMPA_vect() { PORTB = ~PORTB; // Toggle pins on Port B } int main( void ) { DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; //global interrupts are enabled __enable_interrupt(); SREG_bit7 = 1; TCCR1A = 0x80; TCCR1B = 0x09; OCR1AH = 0x0F; OCR1AL = 0x9F; OCIE1A_bit = 1; while(1) { } return 0; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include <iom32.h> #include <intrinsics.h> #pragma vector = TIMER1_COMPA_vect __interrupt void irqHandler( void ) { PORTB = ~PORTB; // Toggle pins on Port B } int main( void ) { DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; SREG_Bit7 = 1; TCCR1A = 0x80; TCCR1B = 0x09; OCR1AH = 0x0F; OCR1AL = 0x9F; TIMSK_Bit4 = 1; //global interrupts are enabled __enable_interrupt(); while(1) { } //return 0; }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #include <iom32.h> #include <intrinsics.h> #define F_CPU 4000000UL #pragma vector = TIMER1_COMPA_vect __interrupt void irqHandler( void ) { PORTB = ~PORTB; // Toggle pins on Port B } int main( void ) { DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; SREG_Bit7 = 1; TCCR1A = 0x80; TCCR1B = 0x0B; OCR1AH = 0x7A; OCR1AL = 0x11; TIMSK_Bit4 = 1; //global interrupts are enabled __enable_interrupt(); while(1) { } //return 0; }