Bình thường thì LED6 sáng, LED7 tối. Khi nhấn phím, LED6 tối, LED7 sáng
trong vòng 0,5 giây, rồi trở về trạng thái ban đầu (LED6 sáng, LED7 tối)
#include <16F877A.h>
#fuses NOWDT, XT
#use delay(clock=4000000)
void high_b6_low_b7() {
output_high(PIN_B6);
output_low(PIN_B7);
}
void low_b6_high_b7() {
output_low(PIN_B6);
output_high(PIN_B7);
}
///////////////////////////////////////////////////////////
#INT_EXT
void RB0_handler() {
low_b6_high_b7();
delay_ms(500);
high_b6_low_b7();
}
///////////////////////////////////////////////////////////
/**
* Keep B6 on and B7 off. Pressing the button causes interrupt:
* B6 off and B7 on, delay half second, then B6 on and B7 off
*
* Wiring (TM Board)
* (1) PIC's B0 to Matrix Key R0
* Matrix Key C0 to GND
* (2) PIC's B6-B7 to LED6-LED7
*
* Ref: Interrupt Mechanism
*
http://www.mikroelektronika.co.yu/en...sicbook/06.htm
*/
void main() {
enable_interrupts(GLOBAL); // enable all interrupts
enable_interrupts(INT_EXT); // enable external interrupt from pin RB0/INT
high_b6_low_b7();
while (true) {
// do nothing
}
}