View previous topic :: View next topic |
Author |
Message |
John5788 Guest
|
Cannot output low |
Posted: Thu Jul 03, 2008 3:41 pm |
|
|
hello, i am trying to learn how to develop on the pic 18f4550 and am running into, a probably trivial problem.
here is my code
Code: | #include "18F4550.h"
int main(void)
{
output_low(PIN_A1);
return 0;
} |
All i want it to do is output a low on pin A1, but when i check the voltage with a multimeter, it is 4.867 volts. what am i doing wrong? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
|
John5788 Guest
|
|
Posted: Thu Jul 03, 2008 3:59 pm |
|
|
i changed the code a bit to this:
#include "18F4550.h"
Code: | int main(void)
{
setup_adc(ADC_OFF);
setup_adc_ports( NO_ANALOGS );
while(1)
{
output_low(PIN_A1);
}
return 0;
} |
and it is still outputting 5v.
more information: i am using the picdem fsusb demo board right now. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 03, 2008 4:13 pm |
|
|
My mistake, the outputs on this chip are not affected by the analog port settings (only the inputs are affected).
Your program is so simple that it can only fail when something very basic is wrong. Did you post all program code? Now the processor include and fuses are missing. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 03, 2008 4:17 pm |
|
|
Quote: | I am using the picdem fsusb demo board right now. |
This board comes with a built-in USB bootloader that uses pin A1
to detect if a USB cable is plugged into the board. See page 11
(page 15 in the Acrobat reader) and also the schematic:
http://ww1.microchip.com/downloads/en/DeviceDoc/51526b.pdf |
|
|
John5788 Guest
|
|
Posted: Thu Jul 03, 2008 5:13 pm |
|
|
ok so i took a glance at the datasheet some more and it says RD0 is connected to the D1 LED, so i modified my code:
Code: | #include "18F4550.h"
int main(void)
{
while(1)
{
output_high(PIN_D0);
}
return 0;
} |
now the LED lights up, its working!
so as I understand, I cannot use RA0, RA1, RB0, RB1, RB2 for anything interesting, but all other lines are fair for use? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 04, 2008 2:24 am |
|
|
You can use A0, A1, B0, B1, B2 as normal, _but_ you need to turn off the devices attached to them.
Quite a few things involved:
1) Fuses - NOPBADEN - otherwise PORTB, wakes up set to use for the ADC
2) setup_adc(NO_ANALOGS) (you already have this one).
3) setup_comparator(NC_NC_NC_NC) - otherwise the comparator uses various pins.
Best Wishes |
|
|
|