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 support@ccsinfo.com

Problem with port D not leaving pins high upon output_high

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



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

Problem with port D not leaving pins high upon output_high
PostPosted: Sat Apr 10, 2010 10:36 pm     Reply with quote

Here is my code:
Code:

#include <16F724.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=8000000)

//====================================
void main()
{
output_high(PIN_D7);
output_high(PIN_D6);
output_high(PIN_C5);

//or using these, result is the same, the last instruction wins, only pin 5 is high.
output_bit(PIN_D7, 1);
output_bit(PIN_D5,1);
}

I tried all these instructions and only end up with 1 pin high at a time.
but using output_d(0b10111100);
I can make multiple pins high.
What is wrong ? This above code works perfect for port c....just not on D?
Nothing is on this port except some led and resistors to a low.

Any ideas? Am I not configuring the port properly?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 10:51 pm     Reply with quote

Quote:

Nothing is on this port except some led and resistors to a low.

See these threads on the RMW (Read-Modify-Write) problem with the 16F PIC's i/o pins:
http://www.ccsinfo.com/forum/viewtopic.php?t=33425
http://www.ccsinfo.com/forum/viewtopic.php?t=41315
http://www.ccsinfo.com/forum/viewtopic.php?t=23756

If you still have problems, then give a detailed description of the
external circuits on your i/o pins (including component values).
Post the schematic in ASCII art, as shown in the 2nd link above.
mnewbill



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 11:13 pm     Reply with quote

Thanks for the tip. I don't know if that is my problem,
It is similar, I have a led in series with a 150 ohm resistor on the port pins, one for each pin. I have the same thing on port A and B. They both are working perfectly. Only on port D am I having this issue. It is funny. It would be ok on the other ports and not on this one. I measure 3.8 volts on the pin(s) when the light is on, being driven high by the pin. Is this a low level for a high? It is consistent on all my ports having this level. My input VDD is 5 volts.
The current draw on the pin is about 13ma. Too much???
mnewbill



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 11:35 pm     Reply with quote

i think this is the issue, but i think it shouldnt do this. i hear about this shaddow register, but how is it implimented?
thanks
mark
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 10, 2010 11:57 pm     Reply with quote

I downloaded the data sheet and looked at this PIC. This is not a
general purpose PIC. It's a specialized PIC, used for capacitive
touch applications. It has these Analog Select registers:
Quote:

ANSELA
ANSELB
ANSELD
ANSELE

If you look at the PIC data sheet, all these registers default to "Analog"
mode for the pins on these ports. CCS has an company standard of
setting pins on port A (and sometimes port B) to be digital i/o pins.
But they don't do anything about higher ports. That means that Ports
D and E are left in Analog mode. That's your problem.

They warn you about this in the data sheet:
Quote:

The state of the ANSELD bits has no affect on digital
output functions. A pin with TRIS clear and ANSEL set
will still operate as a digital output, but the Input mode
will be analog. This can cause unexpected behavior
when executing read-modify-write instructions on the
affected port.

Note: The ANSELD register must be initialized
to configure an analog channel as a digital
input. Pins configured as analog inputs will
read ‘ 0 ’.


16F724 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41341E.pdf

To configure Port D for all digital i/o, you need to use a #byte statement
to set the address of ANSELD. Do this above main(). Then near the
start of main(), set ANSELD = 0 with a line of code.

The basic issue is, if you're going to use a specialized PIC for general
purpose programs, then you need to read the data sheet and learn how
to disable all the special features on the various ports.
mnewbill



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 12:55 am     Reply with quote

I think you are correct. Would somebody be so kind as to show me what the statement would look like in its proper syntax to edit the register in question?

Or some code that disables the analogue and enables the standard IO for port D?

This is my first program for a PIC, and I didn't know they were specialized, but I don't have time to order some more, and would just like to use these if possible.
Thanks
mark
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 1:02 am     Reply with quote

This post shows how to use the #byte statement to define the address
of a register, and also how to write to that register with a line of code.
http://www.ccsinfo.com/forum/viewtopic.php?t=37960&start=1

To find the address of ANSELD, look at the table on page 26 of the
16F724 data sheet. It shows the addresses of the registers in a
column on the left side of the page.

16F724 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/41341E.pdf
mnewbill



Joined: 10 Apr 2010
Posts: 5

View user's profile Send private message

PostPosted: Sun Apr 11, 2010 1:29 am     Reply with quote

Thanks, that fixed it!
If anybody wants to know the address it was:
Code:

#byte ANSEL = 0x188  // address of port D ANSEL IO control

void main()
{
ANSEL = 0x00; // Set A/D pins to all digital
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