/* ************************************************************************** */
/* */
/* Monoliticke mikropocitace - Priklad 1.3 */
/* */
/* Program zasvieti/zhasne LED na PD5 s periodou ??? */
/* */
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */
/* Historia: */
/* 3. 3. 2006 prva pokusna verzia */
/* Verzia: */
/* Pre studentov, chybajuce hodnoty */
/* Prenositelnost: */
/* */
/* ************************************************************************** */
#include <avr/io.h>
#define LEDon PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane
#define LEDoff (PORTD |= _BV(PD5)) // sbi(PORTD,PD5); ale sbi je nepodporovane
#define F_CPU 8000000
void delay_ms(unsigned int ms);
int main (void)
{
DDRD = 0x??; // bin: ???? ???? 1 = out, 0 = in
PORTD = 0x??; // bin: ???? ???? 1 = LED zhasni, 1 = pull-up ON
do{
LEDoff; // bin PORTD + 0010 0000 = nastav PD5, LED OFF
delay_ms(500); // cakaj 500 ms (0,5 s)
LEDon; // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON
delay_ms(500); // cakaj 500 ms (0,5 s)
} while(1); // toto rob stale dokola
return (0); // formalita, nikdy sem neprideme
}
void delay_ms(unsigned int ms)
{
unsigned int index;
while (ms)
{
index = F_CPU / ????; // vypocitajte, kolko treba, aby sme dostali 1ms!!
while (index)
{
asm volatile ("nop");
index--;
}
ms--;
}
}