Hi
I 've build an electric circuit with 2 magnet sensors to control an engine.
When 1 sensor gets a signal de engine should start, then when the other one gets a signal the engine has to stop. I need to control al this with a microcontroller (PIC12F683). But something is wrong. Don't know if I've build the circuit wrong, or the code of my chip. I've used next code:
( GPIO.F0 = sensor 1, GPIO.F1 = sensor 2, GPIO.F4 = engine)
I hope someone can tell me this is correct or not.
Thanks
Kenny
I 've build an electric circuit with 2 magnet sensors to control an engine.
When 1 sensor gets a signal de engine should start, then when the other one gets a signal the engine has to stop. I need to control al this with a microcontroller (PIC12F683). But something is wrong. Don't know if I've build the circuit wrong, or the code of my chip. I've used next code:
( GPIO.F0 = sensor 1, GPIO.F1 = sensor 2, GPIO.F4 = engine)
Code:
void init() {
// Configure GPIO Port
ANSEL = 0b00000001; // Configure all GPIO pins as DIGITAL
TRISIO = 0b00000011; // GP0 and GP1 are input, rest is output
GPIO = 0x00; // Set all output pins to low
WPU = 0x00; // Weak-pull-up disabled
// Configure AD-onvertor
ADCON0 = 0x00; // AD disabled
ADRESH = 0x00; // Init the AD-register
// Configure Comparator
CMCON0 = 0xFF; // Comparator is turned OFF
CMCON1 = 0x00; // Comparator is turned OFF
// Interrupt Configuration
INTCON = 0x00; // Disable all interrupts
}
void main() {
init();
while(1)
{
if (GPIO.F0){
GPIO.F4 = 1 ;
}
if (GPIO.F1){
GPIO.F4 = 0;
}
}
}
I hope someone can tell me this is correct or not.
Thanks
Kenny
Last edited: