View previous topic :: View next topic |
Author |
Message |
mnewbill
Joined: 10 Apr 2010 Posts: 5
|
Problem with port D not leaving pins high upon output_high |
Posted: Sat Apr 10, 2010 10:36 pm |
|
|
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
|
|
|
mnewbill
Joined: 10 Apr 2010 Posts: 5
|
|
Posted: Sat Apr 10, 2010 11:13 pm |
|
|
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
|
|
Posted: Sat Apr 10, 2010 11:35 pm |
|
|
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
|
|
Posted: Sat Apr 10, 2010 11:57 pm |
|
|
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
|
|
Posted: Sun Apr 11, 2010 12:55 am |
|
|
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
|
|
|
mnewbill
Joined: 10 Apr 2010 Posts: 5
|
|
Posted: Sun Apr 11, 2010 1:29 am |
|
|
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
|
|
|
|
|