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

18LF4620 port D woes!

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



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

18LF4620 port D woes!
PostPosted: Fri Jul 15, 2016 12:24 pm     Reply with quote

Hi,
I am using a 18LF4620 with 10MHz crystal, and H4.
I am trying to use port D2 and D3 as digital inputs.
I have setup_PSP(PSP_DISABLED); at the start of main, as these pins are shown as RD2/PSP2 and RD3/PSP3.

D2 works fine but D3 reads as zero, regardless of the input state.

Can someone explain what I am doing wrong, as the data sheet says that all port D pins can be configured as digital inputs?

Thanks

Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2016 1:44 pm     Reply with quote

Those are completely ordinary i/o pins. If pin D3 reads at a logic high
level with a scope and the PIC sees it as low, you probably have a
defective PIC.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jul 15, 2016 2:08 pm     Reply with quote

if a new PIC does not cure it - you need to show the relevant code you created.

how the pins were inited - and where- how you read them
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 15, 2016 2:18 pm     Reply with quote

might also be a short on your PCB, grounding the pin ?
check with power off, no PIC and ring it out

Jay
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Fri Jul 15, 2016 2:58 pm     Reply with quote

Hi all, Thanks for the replies. The PIC is on a prototype board and there is no short. 2 other, brand new PICs behave the same. Each pin has a 10K resistor to +5V and a connector which allows either pin to be grounded by a sensor switch.
All the code does is to check the logic state of each pin:
Code:
sprintf(LCDLine4, "LH Cyl=%u, RH Cyl=%u", input(PIN_D2), input(PIN_D3));
strsetsz(LCDLine4, 20); //pads string to 20 chars with spaces
lcd_gotoxy(1,4);
printf(lcd_putc, LCDLine4);


Currently, I am using wires for the sensors. A meter proves the pins can be made high (no link) or low (pin grounded)

If I use B7 and B8 instead, all is fine, so a solution is not vital but I am intrigued as to what the problem is.

Brian
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 15, 2016 4:11 pm     Reply with quote

Your code is overly complex for the problem, and your hardware sounds
overly complex as well.

Switch circuit
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___ Push button switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
D3                            --- GND
                               -   


LED on PIC pin B0
Code:
pin      470 ohms      LED       
B0  -----/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            - 

Test program:
Code:
#include <18LF4620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)

//=========================================   
void main(void)
{
int8 pin;

while(TRUE)
  {
   pin = input(PIN_D3); // Read the pin

   if(pin)
     {
      output_high(PIN_B0); // If pin D3 is high, turn on LED
     }
   else
     {
      output_low(PIN_B0); // else turn off the LED
     }

   delay_ms(100);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sat Jul 16, 2016 2:39 am     Reply with quote

Take a deep breath, and start again...

First thing is a simple statement of fact. There is nothing special about these pins, except the PSP.

So first thing to do, is to genuinely 'prove' you do not have a short (it's amazingly easy to have whiskers or tiny solder blobs). Assuming the PIC is socketed, unplug it, and test if the pins now go up/down.

Then assuming they do, you come to the problem being in your code. Look for:
1) Any TRIS statements.
2) Any fast_io/fixed_io statements.
3) Any peripheral setup referring to the pins (could be something silly like a missed line in your LCD code). #USE lines etc..

Always the thing to do, is simplify. As with the test for the lines actually going up/down, reduce code till the problem can be isolated. PCM_Programmer gives a good example of a basic 'test' routine to start from
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Sat Jul 16, 2016 8:59 am     Reply with quote

Hi both, thanks for the input.

I eventually traced it to where, just before reading the pins, I had a strcat statement instead of a strcpy to put the first item in a string!!
Putting that right made everything OK.

Thanks for the help.

Brian
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