uC: PIC16F628a
Compiler: Hi-TECH PICC
Goal: To connect button and learn how to enable IO
One from simplest things you can try with microcontroller – to connect button and make uC to do what you want.
Just a simple code there:
#include <htc.h>
#define _XTAL_FREQ 4000000 //Clock 4MHz
__CONFIG(MCLREN & WDTDIS & UNPROTECT);
unsigned char sRB1=0; //led is off initially
void main() {
TRISB = 0b11111101; // B2 output
RB1 = 0; // make В1 0
for (;;) {
if (RB0 == 0) {
__delay_ms(30); //debounce
if (RB0 == 0) { sRB1 = !sRB1;}
}
RB1 = sRB1;
}
}
Debounce is realized with delay macro, easy not optimal, but easy…
Pingback: PIC мк. Эксперимент №2. Подключение кнопки. | PIC микроконтроллеры