#include <16F877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(crystal=20000000)
int increment_scr = 0;
#int_EXT // Zero Crossing Interrupt
void EXT_isr(void)
{
output_low(PIN_B2);
delay_ms(increment_scr);
output_high(PIN_B2);
delay_ms(1);
output_low(PIN_B2);
//delay_ms(increment_scr);
}
void main()
{
set_tris_b(0b0000001); // setting the I/O pins of port B --> 1 pin will be set as input --- 0 as digital output
enable_interrupts(INT_EXT); // enabling external interrupt
ext_int_edge(H_TO_L); // external interrupt raise when signal goes from high to low
enable_interrupts(GLOBAL); // all interrupt are enabled
while(1)
{
if(input(PIN_D0) != 1) // If push Button pressed then increment the value.
{
while(input(PIN_D0) != 1){}
if (increment_scr >=9) increment_scr = 9;
else increment_scr++;
}
if(input(PIN_D1) != 1) // If push Button pressed then decrement the value.
{
while(input(PIN_D1) != 1){}
if (increment_scr <=0) increment_scr = 0;
else increment_scr--;
}
}
}