R&DElec
Newbie level 5
Hello, I'm trying to program PIC10F206 to :
when IN is High :1) the out is high 2) 30 sec delay or timer starts
while in the time (or delay) : when IN goes high again I want it to reset the time
when IN low: Out low
my problem is when in is high and timer starts no matter how many times In goes high again it still waits for 30 Second to be over instead of restarting my timer.
I am using MPLab v6.05 and C8 compile and Pickit3
I'm not sure why it doesn't like the way that I'm asking it to reset the timer
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config CP = OFF // Code Protect (Code protection off)
#pragma config MCLRE = OFF // Master Clear Enable (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN GP0
#define OUT GP1
void main(void) {
// Set IN as input and OUT as output
TRISGPIO = 0b01;
CMCON0 = 0b1000001;
while(1) {
// Check if IN is high
if(IN) {
// Set OUT high
OUT = 1;
// Start 30-second timer
int i = 0;
while(i < 30) { // 30 * 1 second = 30 seconds
__delay_ms(1000); // 1 second delay
if(IN) {
// If IN goes high again, restart the timer
i = 0;
} else {
i++;
}
}
} else {
// Set OUT low
OUT = 0;
}
}
}
when IN is High :1) the out is high 2) 30 sec delay or timer starts
while in the time (or delay) : when IN goes high again I want it to reset the time
when IN low: Out low
my problem is when in is high and timer starts no matter how many times In goes high again it still waits for 30 Second to be over instead of restarting my timer.
I am using MPLab v6.05 and C8 compile and Pickit3
I'm not sure why it doesn't like the way that I'm asking it to reset the timer
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config CP = OFF // Code Protect (Code protection off)
#pragma config MCLRE = OFF // Master Clear Enable (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#include <xc.h>
#define _XTAL_FREQ 4000000
#define IN GP0
#define OUT GP1
void main(void) {
// Set IN as input and OUT as output
TRISGPIO = 0b01;
CMCON0 = 0b1000001;
while(1) {
// Check if IN is high
if(IN) {
// Set OUT high
OUT = 1;
// Start 30-second timer
int i = 0;
while(i < 30) { // 30 * 1 second = 30 seconds
__delay_ms(1000); // 1 second delay
if(IN) {
// If IN goes high again, restart the timer
i = 0;
} else {
i++;
}
}
} else {
// Set OUT low
OUT = 0;
}
}
}