|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
12F629 Issue with output_toggle() |
Posted: Tue Aug 16, 2005 12:13 pm |
|
|
I have a problem with the output_toggle() function working within a IF{} statement. When i move into the while() loop it toggles the correct GPIO pin. Any suggestgion would help
Here is the copy of the code
Thanks KMAC
Code: |
*****************************************************************************
* Default_Reset.c - This code will allow the user to reset the short range *
* radio to its default settings. *
* *
* *
* Functions: void detect_ra_change() - This allows to see the pushbutton *
* interrupt *
* *
* void clear_delta() - Presets the value of Reset Interrupt *
* flag *
* *
* void Toggle_LED() - This function toggles the DONE LED *
* On and Off *
* *
* *
* *
* *
* Author: Kevin McClure copyright (c) 2005 Cooper Power Systems *
* *
*****************************************************************************/
#include <12F629.h>
#fuses NOWDT, INTRC_IO, NOCPD, NOPROTECT, MCLR, PUT, NOBROWNOUT
#use delay(clock=4000000)
///////////////////////////////////////////////////////////////////
//
// Time and Logic and Interrupt Defines
//
//////////////////////////////////////////////////////////////////
#define LOWTOHIGH TRUE
#define HIGHTOLOW FALSE
#define Debounce_Delay 100
#define delay_time_1sec 1000
#define delay_time_2sec 3000
short int dbutton0;
#int_ra
////////////////////////////////////////////////////////////////////
//
// pin definitions
//
////////////////////////////////////////////////////////////////////
#define PDAT PIN_A0 // programming pin
#define PCLK PIN_A1 // programming pin
#define UUT_PWR PIN_A2 // UUT Power Pin
#define MCLR PIN_A3 // MCLR reset input
#define DEFAULT_SET PIN_A4 // Default Set Pin
#define DONE_L PIN_A5 // Done Indication LED
/*****************************************************************
* void detect_ra_change() - This function detects the change *
* in RA0 and sets the correct value *
* Variable dbutton1 dependent of the *
* value of RA0 *
*****************************************************************/
void detect_ra_change()
{
int current;
static int last=0;
set_tris_A(0x0B); // Sets the status of the I/O pins
current=input_A(); // Sets current to the value of the GPIO register
//test the value bit 0 (GPIO 0) to see if it is TRUE
#if LOWTOHIGH
if ((!bit_test(last,0))&&(bit_test(current,0))) {dbutton0=1;}
//test the value bit 0 (GPIO 0) to see if it is FALSE
#elif HIGHTOLOW
if ((!bit_test(current,0))&&(bit_test(last,0))) {dbutton0=1;}
#endif
last=current;
}
/*****************************************************************
* void Toggle_LED() - This function toggles the DONE LED *
* On and Off *
*****************************************************************/
void Toggle_LED()
{
output_toggle(DONE_L);
}
/*****************************************************************
* void clear_delta() - This function clears and defalts set the *
* Reset interrupt flag value to 0 *
*****************************************************************/
void clear_delta()
{
dbutton0=0; //Sets the default value to 0
}
/*****************************************************************
* Start of Main Function *
*****************************************************************/
void main(void)
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
clear_delta(); // Clears the Reset Interupt Flag
output_low(DEFAULT_SET); // De-Asserts the DEF signal
output_high(UUT_PWR); // energizes the UUT
while(TRUE)
{
delay_ms(Debounce_Delay); // (Needs 1 sec Debounce)
enable_interrupts(INT_RA0); // Enable GPIO 0 Interrupt
enable_interrupts(GLOBAL); // Enable Global Interrupts
if(dbutton0==1)
{
disable_interrupts(GLOBAL); //Disables All Interrupts
Toggle_LED(); // Calls the Function to Toggle the DONE LED
output_low(UUT_PWR); // De-energizes the UUT
delay_ms(delay_time_1sec); // 2 Second Delay
output_high(DEFAULT_SET); // Asserts the DEF Signal
delay_ms(delay_time_2sec ); // 2 Second Delay
output_high(UUT_PWR); // Renergizes the UUT
delay_ms(delay_time_2sec); // 2 Second Delay
output_low(DEFAULT_SET); // De-Asserts the DEF Signal
output_low(DONE_L); // Set the DONE LED to ON
delay_ms(delay_time_2sec); // 2 Second Delay
output_high(DONE_L); // Sets the deone LED to OFF
dbutton0 =0; // Resets the push button flag
enable_interrupts(GLOBAL); // Re-enables the interupts
}// End of If Statement
}// End of While Statement
}// End Of Main
|
|
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Tue Aug 16, 2005 12:52 pm |
|
|
#byte port_a=0x{porta's address}
...
port_a ^= 0x20; // 0010 0000
....
This is an alternative way to toggle, which is merely doing an XOR on bit 5.
I did not quite read into your code to see if there is something wrong with your program's flow, but you can try the above statement in place of that toggle library function and see what happens. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|