• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC12F683 button

Status
Not open for further replies.

PR3CiSiON

New Member
Here is my whole program.



#if defined(__PCB__)
#include <12F683.h>
#fuses INTRC,NOWDT,NOPROTECT, NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_B0
#define GP1 PIN_B1
#define GP2 PIN_B2
#define GP3 PIN_B3
#define GP4 PIN_B4
#define GP5 PIN_B5

#elif defined(__PCM__)
#include <12F683.h>
#use delay(clock=4000000)
#define GP0 PIN_A0
#define GP1 PIN_A1
#define GP2 PIN_A2
#define GP3 PIN_A3
#define GP4 PIN_A4
#define GP5 PIN_A5

#endif

void cycle_forward (void)
{

}

void cycle_backward (void)
{

}


void main() {
#if defined(__PCB__)
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
// See .h file for other special
// options for setup_counters
#else
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
#endif

while (TRUE){
if(!input (GP4)){

}
else{
output_high (GP0);
delay_ms (150);
output_low (GP0);
delay_ms (150);
output_high (GP0);
delay_ms (150);
output_low (GP0);
delay_ms (70);
output_high (GP1);
delay_ms (150);
output_low (GP1);
delay_ms (70);
output_high (GP2);
delay_ms (150);
output_low (GP2);
delay_ms (150);
output_high (GP2);
delay_ms (150);
output_low (GP2);
delay_ms (70);
}
}
}





it is in C language, and "works". what does not work is that it does not do the code when i hit a button on a breadboard. I programed this, and set it up all good. but it keeps doing that code unser the 'else' thing. when I have GP4 with negative, it keeps going. same when i have it high voltage. why does it not just do it once whenever i hit the button to make GP4 positive? I made the code into a seperate method and said if GP4=false, initiate the method, else do nothing, but it keeps looping and does not wait for me to hit the button or anything.
 

PR3CiSiON

New Member
Also, does anybody know any good pic simulators that I can upload the hex file to it (in the simulator) and run wires and led's to test it on my comp? free or not, it dont matter.
 

eng1

New Member
it is in C language, and "works". what does not work is that it does not do the code when i hit a button on a breadboard. I programed this, and set it up all good. but it keeps doing that code unser the 'else' thing. when I have GP4 with negative, it keeps going. same when i have it high voltage. why does it not just do it once whenever i hit the button to make GP4 positive? I made the code into a seperate method and said if GP4=false, initiate the method, else do nothing, but it keeps looping and does not wait for me to hit the button or anything.
I would expect your program to execute the instruction if(!input (GP4)){} regerdless of the state of the button. You haven't set the CMCON0 and ANSEL registers for digital I/O. Pins configured as analog inputs read as '0'.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top