View previous topic :: View next topic |
Author |
Message |
johnl
Joined: 30 Sep 2003 Posts: 120
|
PIC18F4431 port D input problem |
Posted: Fri Apr 08, 2011 11:38 am |
|
|
Port D is connected to a dip switch, but bits 0-2 always return 0. Compiler is V 3.218
Also the NOMCLR actually enables master clear in MPLAB v7.6
Code: |
#include <18F4431.h>
#include <string.h>
#include <stdlib.h>
#FUSES NOBROWNOUT, NOIESO, NOMCLR, NOPWMPIN, NOFCMEN
#FUSES NOWDT,NODEBUG,NOLVP,NOPROTECT,INTRC_IO
#FUSES NOEBTRB, NOPUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use standard_io(d)
#byte PORTD=0xF83
char sw;
main()
{
set_tris_a(0xFF);
set_tris_b(0xC0);
set_tris_c(0x70);
set_tris_d(0x1F);
set_tris_e(0x07);
delay_ms(20);
sw = PORTD & 0b11111;
printf("\n %X", sw); // Upon reset, this only displays bits 3 and 4.
// Bits 0,1 and 2 always display as 0
while(1) ;
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 08, 2011 11:55 am |
|
|
What internal peripherals does the PIC have that you haven't disabled ??
Also you'll need correct pullup / pulldown resistors depending on whether active high/active low required. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Fri Apr 08, 2011 12:33 pm |
|
|
I added code to disable timers 0 and 5 from using the D0 pin as a clock input. Pins have PU resistors. Voltage at pins changes from 0 to 5v corresponding to the switch position (as seen with a scope.)
Bit D0 still reads as 0 regardless of voltage on pin.
Code: |
#include <18F4431.h>
#include <string.h>
#include <stdlib.h>
#FUSES NOBROWNOUT, NOIESO, NOMCLR, NOPWMPIN, NOFCMEN
#FUSES NOWDT,NODEBUG,NOLVP,NOPROTECT,INTRC_IO
#FUSES NOEBTRB, NOPUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use standard_io(d)
#byte PORTD=0xF83
#byte T5CON=0xFB7
#byte T0CON=0xFB5
char sw;
main()
{
set_tris_a(0xFF);
set_tris_b(0xC0);
set_tris_c(0x70);
set_tris_d(0x1F);
set_tris_e(0x07);
T0CON = 0; // source for Timer 0 is internal; not pin D0.
T5CON = 0; // source for Timer 5 is internal; not pin D0.
delay_ms(20);
sw = PORTD & 0b11111;
printf("\n %X", sw); // Upon reset, this only displays bits 3 and 4.
// Bits 0,1 and 2 always display as 0
while(1) ;
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 08, 2011 12:54 pm |
|
|
Are you sure there aren't ANY peripherals on PORT D ?
I don't have spec sheet for that PIC but seems odd uC wouldn't have SPI,ADC, etc. available on those pins something other than just DIO ! |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Fri Apr 08, 2011 1:27 pm |
|
|
From the data sheet, pin D0 is only shared with the timer 0 and timer 5 inputs:
RD0/T0CKI/T5CKI |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 08, 2011 1:43 pm |
|
|
What board are you using ? Post a link to the website for it. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Fri Apr 08, 2011 1:58 pm |
|
|
It's a custom board so there's no link. Sounds like you are suspecting a hardware problem. I just buzzed out pin D0 and it is correctly connected to the switch and is not shorted to any other pins.
The chip is the 44TQFP package. I do have a protoboard I could wire up the 40 DIP on.
Or I have another compiler (SourceBoost) I can try on the present board. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Fri Apr 08, 2011 2:05 pm |
|
|
Yes, it's hardware. One side of the chip isn't soldered!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 08, 2011 2:06 pm |
|
|
Try the 40-pin DIP with CCS, because that's how I will test it, if I do.
I don't have your version of PCH. I have v3.191, and then I have a gap,
starting again at v3.230. So I can't exactly test your problem, otherwise
I would have done it already. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Fri Apr 08, 2011 2:12 pm |
|
|
Thanks much. Sorry I wasted everyone's time. You were correct in suspecting hardware.
It works now.
Solder is a wonderful thing! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Fri Apr 08, 2011 3:20 pm |
|
|
heck, I'm happy you found the problem and could fix it...
unlike the chevy van sitting here with rusted, busted WELDED hinges on it ! idiots.... |
|
|
|