View previous topic :: View next topic |
Author |
Message |
rina_1220
Joined: 02 Oct 2007 Posts: 20
|
PIC18F1320 and digital I/O pin config |
Posted: Mon Nov 19, 2007 8:08 am |
|
|
Hey all. I need some help with port_b configuration for pic18f1320.
I have set a small routine to test if my program is working fine and I have a problem with pins B0, B1 and B4.
My routine would light on and off a led on pin_B0 and pin_B3.
I've noticed pin_B3 works fine, but not pin_B0.
I have already set LATB=0 and ADCON1=0x70, as its told in the datasheet, because of the digital/analog i/o configuration of these pins, but it still ain't working.
Is there anything I'm missing?
here my code
Code: | #include <18f1320.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP
#FUSES NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, bits=8, parity=N, xmit=PIN_B1, rcv=PIN_B4)
#byte port_b=6
#byte OSCCON=0xFD3
#byte LATB=0xF8A
#byte ADCON1=0xFC1
void main()
{
OSCCON=0b01100010; //4MHz
port_b = 0;
set_tris_b(0); //Initialize data direction. (Set = input; reset = output)
LATB = 0; //Alternate method to clear output data latches
ADCON1 = 112;//0x70; //Set RB0 (AN4), RB1 (AN5), RB4 (AN6) as digital I/O pins
port_b = 0;
while(1)
{
output_high(PIN_B0);
output_low(PIN_B3);
delay_ms(1000);
output_low(PIN_B0);
output_high(PIN_B3);
delay_ms(1000);
}
return;
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 19, 2007 11:13 am |
|
|
Quote: | #include <18f1320.h>
#byte port_b=6
#byte OSCCON=0xFD3
#byte LATB=0xF8A
#byte ADCON1=0xFC1 |
Download the 18F1320 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39605F.pdf
Look in this section:
Quote: | 5.9.2 SPECIAL FUNCTION REGISTERS |
What should be fixed with the line shown in bold above ? |
|
|
rina_1220
Joined: 02 Oct 2007 Posts: 20
|
|
Posted: Mon Nov 19, 2007 3:50 pm |
|
|
Quote: | #include <18f1320.h>
#byte port_b=0xF81
#byte OSCCON=0xFD3
#byte LATB=0xF8A
#byte ADCON1=0xFC1 |
right?
But tell me. Do you know why the other LED on pin_B3 worked fine and just B0 didn't?
thanks a lot |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 19, 2007 4:28 pm |
|
|
Do you know for certain if the LED on Pin B0 is a good LED ?
Describe the circuit on Pin B0. Do you have a series resistor between
pin B0 and the LED ? What is the value of the resistor ? |
|
|
rina_1220
Joined: 02 Oct 2007 Posts: 20
|
|
Posted: Mon Nov 19, 2007 6:59 pm |
|
|
yeah. I have one 330ohm resistor between the led and the port. And I had 2 different leds tested on both ports. they only work on pin b3.
another thing is that if I connect pin b0 to an osciloscope it'll show its working fine (output goes from 0 to 5). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 19, 2007 7:04 pm |
|
|
The LED has probably been installed backwards.
LEDs are polarized. One pin is the cathode and the other pin is the
anode. They must be installed correctly. |
|
|
rina_1220
Joined: 02 Oct 2007 Posts: 20
|
|
Posted: Mon Nov 19, 2007 7:42 pm |
|
|
I am going to check that again when I get the chance.
Thank you again
The led on pin b0 was not grounded. that was the problem. |
|
|
|