AVR Example3.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 4: | Riadok 4: | ||
/* Monoliticke mikropocitace - Priklad 1.3 */ | /* Monoliticke mikropocitace - Priklad 1.3 */ | ||
/* */ | /* */ | ||
/* Program zasvieti/zhasne LED na | /* Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s] */ | ||
/* */ | /* */ | ||
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */ | /* Autor: Richard Balogh <balogh@elf.stuba.sk> */ | ||
/* Historia: */ | /* Historia: */ | ||
/* 3. 3. 2006 prva pokusna verzia */ | /* 3. 3. 2006 prva pokusna verzia */ | ||
/* 12.10. 2012 upravene pre Acrob / Arduino (portD / portB) */ | |||
/* Verzia: */ | /* Verzia: */ | ||
/* Pre studentov, chybajuce hodnoty */ | /* Pre studentov, chybajuce hodnoty */ | ||
Riadok 17: | Riadok 18: | ||
#include <avr/io.h> | #include <avr/io.h> | ||
#define LEDon | #define LEDon PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane | ||
#define LEDoff ( | #define LEDoff (PORTB |= _BV(5)) // sbi(PORTB,PB5); ale sbi je nepodporovane | ||
#define F_CPU | #define F_CPU 16000000 | ||
void delay_ms(unsigned int ms); | void delay_ms(unsigned int ms); | ||
Riadok 27: | Riadok 28: | ||
{ | { | ||
DDRB = 0x??; // bin: ???? ???? 1 = out, 0 = in | |||
PORTB = 0x??; // bin: ???? ???? 1 = LED zhasni, 1 = pull-up ON | |||
do{ | do{ | ||
LEDoff; // bin | LEDoff; // bin PORTB + 0010 0000 = nastav PB5, LED OFF | ||
delay_ms(500); // cakaj 500 ms (0,5 s) | delay_ms(500); // cakaj 500 ms (0,5 s) | ||
LEDon; // bin: PORTD & 1101 1111 = vynuluj | LEDon; // bin: PORTD & 1101 1111 = vynuluj PB5, LED ON | ||
delay_ms(500); // cakaj 500 ms (0,5 s) | delay_ms(500); // cakaj 500 ms (0,5 s) | ||
Verzia z 07:11, 12. október 2012
/* ************************************************************************** */
/* */
/* Monoliticke mikropocitace - Priklad 1.3 */
/* */
/* Program zasvieti/zhasne zltu LED na PORTB.5 s periodou ?? [s] */
/* */
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */
/* Historia: */
/* 3. 3. 2006 prva pokusna verzia */
/* 12.10. 2012 upravene pre Acrob / Arduino (portD / portB) */
/* Verzia: */
/* Pre studentov, chybajuce hodnoty */
/* Prenositelnost: */
/* */
/* ************************************************************************** */
#include <avr/io.h>
#define LEDon PORTB &= ~(_BV(5)) // cbi(PORTB,PB5); ale cbi je nepodporovane
#define LEDoff (PORTB |= _BV(5)) // sbi(PORTB,PB5); ale sbi je nepodporovane
#define F_CPU 16000000
void delay_ms(unsigned int ms);
int main (void)
{
DDRB = 0x??; // bin: ???? ???? 1 = out, 0 = in
PORTB = 0x??; // bin: ???? ???? 1 = LED zhasni, 1 = pull-up ON
do{
LEDoff; // bin PORTB + 0010 0000 = nastav PB5, LED OFF
delay_ms(500); // cakaj 500 ms (0,5 s)
LEDon; // bin: PORTD & 1101 1111 = vynuluj PB5, 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--;
}
}