Hi Guys,
I am finally entering the microcontroller world and will be working on my first project. One of the designs for the projects includes an event X happening when a button is held LOW for 3 seconds. I am not the best programmer but wanted to brainstorm with you guys on how I am going to approach this, and if someone can give me tips, that would be great!.
The microcontroller I will be using is a PIC18F13K50
My basic design is this:
Oscillator will be in circuit and set to 1 MHz with a prescaler of 256:1
The contact switch which will be held for 3 seconds will be connected to Pin 14(RC2) which has an INT2. When the switch is pressed, I will set INT2 to set high when it sees an active low. In turn, INT2 will be an high priority interrupt. From there, the code will go to a Push Button function I will make that will see how long the button is pressed for. In order to achieve this, I will start a timer (Timer0 - 16 bit). The Timer0 will also have an interrupt where it will over flow if button is held for 3 seconds or longer. Now to monitor how long the button is pressed for, I will put in a while loop to monitor the status of RC7 (should be active low) and within the loop, the timer will increment. If it takes the timer0 interrupt to overflow for 3 seconds or longer, than I will do event X. If the timer0 interrupt bit doesn't get set within 3 seconds, than I know the button was pressed for less than 3 seconds, thus the PIC will do nothing.
If you guys can give me tips on the logic of my program, I would greatly appreciate it. In addition, I want to conserve as much power as possible so right when the microprocessor starts, the PIC will be sleeping until INT2 (button press) wakes it up.
Thanks in advance!
I am finally entering the microcontroller world and will be working on my first project. One of the designs for the projects includes an event X happening when a button is held LOW for 3 seconds. I am not the best programmer but wanted to brainstorm with you guys on how I am going to approach this, and if someone can give me tips, that would be great!.
The microcontroller I will be using is a PIC18F13K50
My basic design is this:
Oscillator will be in circuit and set to 1 MHz with a prescaler of 256:1
The contact switch which will be held for 3 seconds will be connected to Pin 14(RC2) which has an INT2. When the switch is pressed, I will set INT2 to set high when it sees an active low. In turn, INT2 will be an high priority interrupt. From there, the code will go to a Push Button function I will make that will see how long the button is pressed for. In order to achieve this, I will start a timer (Timer0 - 16 bit). The Timer0 will also have an interrupt where it will over flow if button is held for 3 seconds or longer. Now to monitor how long the button is pressed for, I will put in a while loop to monitor the status of RC7 (should be active low) and within the loop, the timer will increment. If it takes the timer0 interrupt to overflow for 3 seconds or longer, than I will do event X. If the timer0 interrupt bit doesn't get set within 3 seconds, than I know the button was pressed for less than 3 seconds, thus the PIC will do nothing.
If you guys can give me tips on the logic of my program, I would greatly appreciate it. In addition, I want to conserve as much power as possible so right when the microprocessor starts, the PIC will be sleeping until INT2 (button press) wakes it up.
Thanks in advance!