AVR Example2.c: Rozdiel medzi revíziami
Zo stránky SensorWiki
Nová stránka: <source lang="c"> </source> |
Bez shrnutí editace |
||
Riadok 1: | Riadok 1: | ||
<source lang="c"> | <source lang="c"> | ||
/* ************************************************************************** */ | |||
/* */ | |||
/* Monoliticke mikropocitace - Priklad 1.2 */ | |||
/* */ | |||
/* Program zasvieti/zhasne LED na PD5 podla stavu prepinaca na PD2 */ | |||
/* Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit */ | |||
/* */ | |||
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */ | |||
/* Historia: */ | |||
/* 19.2.2006 prva pokusna verzia */ | |||
/* Prenositelnost: */ | |||
/* */ | |||
/* ************************************************************************** */ | |||
#include <avr/io.h> // spolu s -mmcu=atmega16 nahra spravny .h subor | |||
// ktory potrebujeme kvoli PORTx, PINx a DDRx | |||
#define SW1 (PIND & 0x??) | |||
#define LEDon PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane | |||
#define LEDoff (PORTD |= _BV(PD5)) // sbi(PORTD,PD5); ale sbi je nepodporovane | |||
int main (void) | |||
{ | |||
DDRD = 0x??; // bin: 1010 0010 1 = out, 0 = in | |||
PORTD = 0x??; // bin: 1x11 110x 1 = LED zhasni, 1 = pull-up ON | |||
do{ | |||
if ( SW1 ) // bin: PIND & 0000 0100 = sw1 OFF? | |||
LEDoff; // bin PORTD + 0010 0000 = nastav PD5, LED OFF | |||
else // t.j. ak sw1 ON: | |||
LEDon; // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON | |||
} while(1); // toto rob stale dokola | |||
return (0); // formalita, nikdy sem neprideme | |||
} | |||
</source> | </source> | ||
[[CADRS_Cvi%C4%8Denie_8#Postup|Späť na cvičenie...]] |
Verzia z 11:23, 5. november 2008
/* ************************************************************************** */
/* */
/* Monoliticke mikropocitace - Priklad 1.2 */
/* */
/* Program zasvieti/zhasne LED na PD5 podla stavu prepinaca na PD2 */
/* Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit */
/* */
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */
/* Historia: */
/* 19.2.2006 prva pokusna verzia */
/* Prenositelnost: */
/* */
/* ************************************************************************** */
#include <avr/io.h> // spolu s -mmcu=atmega16 nahra spravny .h subor
// ktory potrebujeme kvoli PORTx, PINx a DDRx
#define SW1 (PIND & 0x??)
#define LEDon PORTD &= ~(_BV(PD5)) // cbi(PORTD,PD5); ale cbi je nepodporovane
#define LEDoff (PORTD |= _BV(PD5)) // sbi(PORTD,PD5); ale sbi je nepodporovane
int main (void)
{
DDRD = 0x??; // bin: 1010 0010 1 = out, 0 = in
PORTD = 0x??; // bin: 1x11 110x 1 = LED zhasni, 1 = pull-up ON
do{
if ( SW1 ) // bin: PIND & 0000 0100 = sw1 OFF?
LEDoff; // bin PORTD + 0010 0000 = nastav PD5, LED OFF
else // t.j. ak sw1 ON:
LEDon; // bin: PORTD & 1101 1111 = vynuluj PD5, LED ON
} while(1); // toto rob stale dokola
return (0); // formalita, nikdy sem neprideme
}