gutisie
Junior Member level 1
Hi there!!, i have a problem with my code.
I am using pic 12f629, and mplab universal suite compiler.
I would kindly request that someone check why my code is not counting the switch pulses.
The code is design for starting with the led on, and if the buton is pressed 3 times, then switch off the led for say 1 s, and start again.
Hence, please find below what i think it should be. But no luck so far...
here the changes would be sensor=switch, and motor=led
thanks.
I am using pic 12f629, and mplab universal suite compiler.
I would kindly request that someone check why my code is not counting the switch pulses.
The code is design for starting with the led on, and if the buton is pressed 3 times, then switch off the led for say 1 s, and start again.
Hence, please find below what i think it should be. But no luck so far...
Code:
#include <htc.h>
#define _XTAL_FREQ 4000000
#define MAXBBS
#define IRLED GPIO2
#define MOTOR GPIO1
#define SENSOR GPIO3
#define DelayS(T) {unsigned char i; for(i=0; i<T*10; i++) __delay_ms(100);}
__CONFIG(MCLRDIS & UNPROTECT & BORDIS & WDTDIS & PWRTEN & INTIO);
void main()
{
unsigned char cnt1ms;
TRISIO = 0b111001;
OPTION = 0b11010100;
for (;;){
IRLED = 1;
MOTOR = 1;
cnt1ms = 0;
while (SENSOR==1 && cnt1ms<1000/1){
TMR0 = 0;
while(TMR0<1000/32)
;
++cnt1ms;
}
if(cnt1ms=MAXBBS/1)
MOTOR = 0;
DelayS(1);
}
}
here the changes would be sensor=switch, and motor=led
thanks.