I am learning to use avr-gcc, but I have no idea, how to solve the following task:
The 8 bits from Port B should alternately set from 0 to 1 with an interval of 500 mili seconds.
I appreciate your help.
I am learning to use avr-gcc, but I have no idea, how to solve the following task:
The 8 bits from Port B should alternately set from 0 to 1 with an interval of 500 mili seconds.
I appreciate your help.
Have a look at this example. This a very basic code for timer0
:
#include<avr/io.h>
#include<avr/interrupt.h>
#define F_CPU 1000000UL
unsigned int t=0;
main()
{
DDRD=0xFF;
TCCR0=(1<<CS00);
TCNT0=0;
TIMSK=(1<<TOIE0);
sei();
while(1);
}
ISR(TIMER0_OVF_vect)
{
t++;
if(t==40000)
{
PORTD=~PORTD;
t=0;
}
}
As @Alex said you can #include <util/delay.h>
, but instant of using the provided code (by @Alex) you can simple use _delay_ms(500);
This will provide you a delay of 500ms.
The choice is yours, just keep in mind that in both cases the frequency of your clock must be defined properly to your compiler:
Example for 16MHz:#define F_CPU 16000000UL