PIC casovac - sekundy (přesunuto)
Moderátor: Moderátoři
-
victus14
PIC casovac - sekundy (přesunuto)
jsem v programovani pro MCU pomerne novy. Zatim to zkousim tak nejak v Ccku, ale narazil jsem na problem. Mam PIC12F675 a chtel bych mu dat na vstup, ze po trech logickych vstupech, ktere musi prijit behem 15 sekund, bude mit vystup. Kdyz treba prijdou behem 15 sekund jen 2, tak se ten vstup vyresetuje.
Nema to nejakou alternativu treba <time.h>, co by se dalo pouzit?
-
Návštěvník
Kód: Vybrat vše
#define RUN (1)
#define CPL (2)
uint8_t tick_1s;
uint8_t timer_status;
uint8_t timer_value;
// sw timer enable
if ((bit_is_set(PINB,0) ||
bit_is_set(PINB,1) ||
bit_is_set(PINB,2)) &&
timer_status!=RUN )
{
timer_status = RUN;
timer_value = 15;
}
// write output
if (timer_status==CPL)
{
if (bit_is_set(PINB,0) &&
bit_is_set(PINB,1) &&
bit_is_set(PINB,2))
{
bit_set(PORTB,3);
}
else
{
bit_clear(PORTB,3);
}
}
// sw timer logic
if (tick_1s)
{
if (timer_status==RUN)
{
if (timer_value!=0)
{
timer_value--;
}
else
{
timer_status=CPL;
}
}
}