CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F4431 port D input problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PIC18F4431 port D input problem
PostPosted: Fri Apr 08, 2011 11:38 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 11:55 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 12:33 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 12:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 1:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 1:43 pm     Reply with quote

What board are you using ? Post a link to the website for it.
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 1:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 2:05 pm     Reply with quote

Yes, it's hardware. One side of the chip isn't soldered!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 2:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 2:12 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 08, 2011 3:20 pm     Reply with quote

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....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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