AVR Example2.c: Rozdiel medzi revíziami
Z SensorWiki
(3 medziľahlé úpravy od rovnakého používateľa nie sú zobrazené.) | |||
Riadok 4: | Riadok 4: | ||
/* Monoliticke mikropocitace - Priklad 1.2 */ | /* Monoliticke mikropocitace - Priklad 1.2 */ | ||
/* */ | /* */ | ||
− | /* Program zasvieti/zhasne LED na | + | /* Program zasvieti/zhasne LED na PORTB.5 podla stavu prepinaca na PORTB.4 */ |
/* Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit */ | /* Ako Priklad 1.1, len doplnene o makra ktore (mozu) program sprehladnit */ | ||
/* */ | /* */ | ||
/* Autor: Richard Balogh <balogh@elf.stuba.sk> */ | /* Autor: Richard Balogh <balogh@elf.stuba.sk> */ | ||
/* Historia: */ | /* Historia: */ | ||
− | /* 19.2.2006 prva pokusna verzia | + | /* 19. 2.2006 prva pokusna verzia */ |
− | /* | + | /* 12.10.2012 uprava pre Acrob/Arduino (PD -> PB) */ |
+ | /* Verzia: */ | ||
+ | /* studentska bez konkretnych hodnot */ | ||
/* */ | /* */ | ||
/* ************************************************************************** */ | /* ************************************************************************** */ | ||
− | #include <avr/io.h> // spolu s -mmcu= | + | |
+ | #include <avr/io.h> // spolu s -mmcu=atmega328 nahra spravny .h subor | ||
// ktory potrebujeme kvoli PORTx, PINx a DDRx | // ktory potrebujeme kvoli PORTx, PINx a DDRx | ||
− | #define SW1 ( | + | #define SW1 (PINB & 0x??) |
− | #define LEDon | + | #define LEDon PORTB &= ~(_BV(5)) // cbi(PORTB,5); ale cbi je nepodporovane |
− | #define LEDoff ( | + | #define LEDoff (PORTB |= _BV(5)) // sbi(PORTB,5); ale sbi je nepodporovane |
int main (void) | int main (void) | ||
{ | { | ||
− | + | DDRB = 0x??; // bin: 00?? 0000 1 = out, 0 = in | |
− | + | PORTB = 0x??; // bin: 00?? 1111 1 = LED zhasni, 1 = pull-up ON | |
do{ | do{ | ||
− | if ( SW1 ) // bin: | + | if ( SW1 ) // bin: PINB & 0001 0000 = sw1 OFF? |
− | LEDoff; // bin | + | LEDoff; // bin: PORTB + 0010 0000 = nastav PB5, LED OFF |
else // t.j. ak sw1 ON: | else // t.j. ak sw1 ON: | ||
− | LEDon; // bin: | + | LEDon; // bin: PORTB & 1101 1111 = vynuluj PB5, LED ON |
} while(1); // toto rob stale dokola | } while(1); // toto rob stale dokola | ||
Riadok 42: | Riadok 45: | ||
− | [[ | + | [[MMP_Cvi%C4%8Denie_2#Postup|Späť na cvičenie...]] |
+ | |||
+ | [[Category:AVR]][[Category:MMP]] |
Aktuálna revízia z 07:24, 12. október 2012
/* ************************************************************************** */
/* */
/* Monoliticke mikropocitace - Priklad 1.2 */
/* */
/* Program zasvieti/zhasne LED na PORTB.5 podla stavu prepinaca na PORTB.4 */
/* 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 */
/* 12.10.2012 uprava pre Acrob/Arduino (PD -> PB) */
/* Verzia: */
/* studentska bez konkretnych hodnot */
/* */
/* ************************************************************************** */
#include <avr/io.h> // spolu s -mmcu=atmega328 nahra spravny .h subor
// ktory potrebujeme kvoli PORTx, PINx a DDRx
#define SW1 (PINB & 0x??)
#define LEDon PORTB &= ~(_BV(5)) // cbi(PORTB,5); ale cbi je nepodporovane
#define LEDoff (PORTB |= _BV(5)) // sbi(PORTB,5); ale sbi je nepodporovane
int main (void)
{
DDRB = 0x??; // bin: 00?? 0000 1 = out, 0 = in
PORTB = 0x??; // bin: 00?? 1111 1 = LED zhasni, 1 = pull-up ON
do{
if ( SW1 ) // bin: PINB & 0001 0000 = sw1 OFF?
LEDoff; // bin: PORTB + 0010 0000 = nastav PB5, LED OFF
else // t.j. ak sw1 ON:
LEDon; // bin: PORTB & 1101 1111 = vynuluj PB5, LED ON
} while(1); // toto rob stale dokola
return (0); // formalita, nikdy sem neprideme
}