|
|
View previous topic :: View next topic |
Author |
Message |
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
Output_float, input statements help... |
Posted: Wed Oct 18, 2006 10:25 pm |
|
|
Guys or gals,
I need help with this little project.
I have the PIC16F877A chip and Im trying to read the values from some pins and low or high some other pins based from the input values.
I already checked that the values in the inputs were high (4.5 - 5V) at first (first if condition) and tried low (0V) (second if condition), and the outputs from the chip never change (always stay at 2.1 - 2.2V), in both situations.
What Am I doing wrong? Im a newbie in PIC C and I would like to get some guidance. Below is the code Im using...
#include "C:XXXX\AC.h"
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while (TRUE)
{
//output_float (PIN_D3);
//output_float (PIN_D7);
//output_float (PIN_D6);
if (input (PIN_D3) == 1 && input (PIN_D7) == 1 && input (PIN_D6) ==1)
{
output_high (PIN_D1);
output_high (PIN_D0);
output_high (PIN_A1);
}// end if statement
else if (input(PIN_D3) == 0 && input (PIN_D7) == 0 && input (PIN_D6) == 0)
{
output_low (PIN_D1);
output_low (PIN_D0);
output_low (PIN_A1);
}//end else
else
{
output_low (PIN_D1);
output_low (PIN_D0);
output_high (PIN_A1);
} //end second else
}// end while loop
}// end program |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Wed Oct 18, 2006 10:28 pm |
|
|
The .h file is as follows:
#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,RC, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, LVP, NOCPD, NOWRT
Is there anything wrong with this code? Obviously there is, because it does not work. Do I have to use the timer? CCCP? Anything?
Im really hoping for an answer.
Please reply at your earliest convinience.
TIA! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 18, 2006 11:09 pm |
|
|
Quote: |
#include <16F877A.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,RC, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, LVP, NOCPD, NOWRT |
1. Are you really using an external RC oscillator circuit ?
The highest allowable frequency is 4.0 MHz. It won't run at 20 MHz.
To get a 4 MHz frequency, you have to use R-C values of about
3K for the resistor and 20 pF for the capacitor.
If you don't know what you really have (R-C circuit, crystal, or
external oscillator) see this thread. It has links to photos.
http://www.ccsinfo.com/forum/viewtopic.php?t=28558
2. Are you really using Low Voltage Programming mode ? To use
that mode, you need to have a home-made programmer such as
the "TLVP" programmer, that supports LVP mode.
If you're using a normal programmer, such as a Microchip ICD2,
CCS-ICD, CCS MachX, Warp-13a, PicStart-Plus, etc., then change
the fuse to NOLVP. |
|
|
xcamarox
Joined: 18 Oct 2006 Posts: 9
|
|
Posted: Wed Oct 18, 2006 11:26 pm |
|
|
PCM Programmer, I could kiss you right now, but I guess I would hate it later so,
THANK YOU VERY MUCH!!!
That did it. No wonder I used to have mixed results when I used this chip back 2 motnhs ago. Some stupid settings made a huge difference. I guess next time I'll do some more research. I would not think that for such a small program this made a difference, but now I guess I'll be more careful next time.
THANK YOU. GRACIAS. DANKA. MERCI!!!
I really can not thank you enough. |
|
|
|
|
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
|