The following is a program written in assembly language that flashes LEDs at one-second intervals, assuming an ATmega328P microcontroller.
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
DDRB |= (1 << PB5); Set PB5 to the output mode
TCCR0A |= (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); Set timer 0 to fast PWM mode and use non-inverted mode output
TCCR0B |= (1 << CS01); Set the prescaled to 8
while (1) {
PORTB ^= (1 << PB5); Flip the state of PB5
_delay_ms(1000 / 4); Wait 1/4 second
}
}
In this program, we used the PORTB.5 pin of the ATmega328P microcontroller to control the blinking of an LED.
Use timer 0 to generate a PWM signal to flip the state of the LED at 4-second intervals.
The _delay_ms() function is used to pause program execution to wait for a certain amount of time.
In this example, we set it to 1000 / 4 milliseconds, which is the state of flipping the LED in 1/4 of a second.