Vstupy a výstupy AVR: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 3: | Riadok 3: | ||
Tu si trocha zablikáme LEDkou aby sme sa naučili používať _delay_ms() | Tu si trocha zablikáme LEDkou aby sme sa naučili používať _delay_ms() | ||
<tabs> | |||
<tab name="AVR C"><source lang="cpp"> | |||
#define F_CPU 16000000UL // toto je lepsie vlozit do parametrov pre kompilator | |||
#include <avr/io.h> | |||
#include <util/delay.h> | |||
#define set_bit(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) | |||
#define clear_bit(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) | |||
#define LED1 PB5 // zabudovana dioda | |||
void delay(int delay) // vlastna funkcia pre dlhsie casy | |||
{ | |||
for (int i=1; i<=delay; i++) | |||
_delay_ms(1); | |||
} | |||
int main(void) | |||
{ | |||
set_bit(DDRB,LED1); // set pin LED1 as output | |||
while(1) | |||
{ | |||
delay(250); // 250 ms delay | |||
set_bit(PORTB,LED1); // LED1 = log.1 | |||
delay(250); // 250 ms delay | |||
clear_bit(PORTB,LED1); // LED1 = log.0 | |||
} | |||
return(0); // sem nikdy neprideme | |||
} | |||
</source></tab> | |||
<tab name="Arduino"> | |||
<source lang="arduino"> | |||
void setup() | |||
{ | |||
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output. | |||
} | |||
void loop() | |||
{ | |||
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) | |||
delay(1000); // wait for a second | |||
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW | |||
delay(1000); // wait for a second | |||
} | |||
</source></tab> | |||
</tabs> | |||
== Digitálne vstupy (Tlačidlá) == | == Digitálne vstupy (Tlačidlá) == |
Verzia z 22:49, 7. február 2021
Digitálne výstupy (LED)
Tu si trocha zablikáme LEDkou aby sme sa naučili používať _delay_ms()
#define F_CPU 16000000UL // toto je lepsie vlozit do parametrov pre kompilator
#include <avr/io.h>
#include <util/delay.h>
#define set_bit(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define clear_bit(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define LED1 PB5 // zabudovana dioda
void delay(int delay) // vlastna funkcia pre dlhsie casy
{
for (int i=1; i<=delay; i++)
_delay_ms(1);
}
int main(void)
{
set_bit(DDRB,LED1); // set pin LED1 as output
while(1)
{
delay(250); // 250 ms delay
set_bit(PORTB,LED1); // LED1 = log.1
delay(250); // 250 ms delay
clear_bit(PORTB,LED1); // LED1 = log.0
}
return(0); // sem nikdy neprideme
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.
}
void loop()
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Digitálne vstupy (Tlačidlá)
A potom to využijeme tu
Ošetrenie zákmitov (debouncing)
a) Hardvérové
b) Softvérové
Literatúra:
- Jack G. Ganssle: A Guide to Debouncing. The Ganssle Group, Rev 2: April, 2007.
- Elliot Williams: Embed With Elliot:Debounce Your Noisy Buttons, Part I. Hackaday, 2015.
- Elliot Williams: Embed With Elliot:Debounce Your Noisy Buttons, Part II. Hackaday, 2015.