PDA

View Full Version : 16F887 PORTC.7 high



Neosec
- 31st March 2013, 04:07
I'm pretty sure this is due to the serial feature on C.7.

I have LEDs on all port C pins and pin 7 lights the LED with TRISC = %11111111

Is C.7 pulled high waiting for an external serial data stream to pull it low?

RCSTA? TXSTA?

Neo

Demon
- 31st March 2013, 12:50
For starters; 1 means input, 0 is output.

Posting all your code wouldn't hurt either.

Robert

Example:
http://www.picbasic.co.uk/forum/showthread.php?t=14205&highlight=tris+output

Neosec
- 31st March 2013, 13:41
Sorry, I guess I wasn't very clear. I'm just playing around with ADCs on PortA, not doing anything with PortC. I'm using a EasyPIC3 development board so LEDs are available on all pins. I'm aware the 1 means input and that as an input the pin may float above 0V but I was under the impression that it should not have enough power to drive an LED when set as an input. None of the other pins on PortC drive the LEDs but C.7 is bright. Using melabs U2 Programmer to program the MCU; set MCU to 16F887, Oscillator to XT, all other fuses to default. LCD, ADCs work as expected, just this C.7 thing is odd and just do to my ignorance.


' Define LCD pins
DEFINE LCD_DREG PORTB ' Sets LCD Data Port to Port-B instead of default Port A
DEFINE LCD_DBIT 4 ' Sets for use of PortB bits 4 thru 7 for the data
DEFINE LCD_RSREG PORTB ' Sets RS (Register Select) to Port B instead of default PortA.4
DEFINE LCD_RSBIT 2 ' Sets RS (Register Select) to bit 2 of port B (PORTB.2)
' ' Enable stays at the default PORTB.3

ANSELH = 0
ANSEL = 0 ' This sets the ADCs to Digital
Low PORTB.2 ' LCD R/W line low (W)
Pause 2000 ' Wait 2 seconds (2000 mS)for LCD to start

Lcdout $fe, 1, "16F887 ADC Test" ' Display sign-on message


TRISC = %1111111

DEFINE ADC_BITS 10 ' 10 bit A/D Conversion

ANSELH = 0
ANSEL = %00001100 ' Set pin (AN2, AN3) to analog input, the rest to digital
ADCON1 = %10000000 ' Set up A/D converter - Right Just., VDD REF.

adc_val var word
adc_val_2 var word

pause 2000 'settle



mainloop:

ADCIN 2, adc_val ' Get ADC value from ADC channel 2

ADCIN 3, adc_val_2 ' Get ADC value from ADC channel 3

Lcdout $fe, 1, DEC (adc_val)," ADC 1 Value"

Lcdout $fe, $C0, DEC (adc_val_2)," ADC 2 Value"

Pause 200

goto mainloop

End

Neosec
- 31st March 2013, 14:17
Just some more input...
On the 16F887 PORTC.6 and PORTC.7 have a ENHANCED UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (EUSART) feature. C.6 is labeled RC6/TX/CK and C.7 is RC7/RX/DT. I have to assume that, since I've set C.7 as in input and there's no data going out the DT line, that the RX (receiver) is holding the pin high. So, I guess my question is about the basics of the serial data feature on the MCU and why it affects this pin the way it does?

TIA

Neosec
- 31st March 2013, 15:07
Tried setting RCSTA: RECEIVE STATUS AND CONTROL REGISTER to RCSTA = %00000000

From Data Sheet -
bit 7 SPEN: Serial Port Enable bit
1= Serial port enabled (configures RX/DT and TX/CK pins as serial port pins)
0= Serial port disabled (held in Reset)
In an attempt to disable the serial port but it had no effect. C7 still high. BTW there is a 10k pull down resistor enabled on the dev. board (all of port C) and the output of C.7 is over-driving it.
Edit: And just FYI, If I set C.7 as an output and PORTC.7 = 0 the LED goes out (off) as it should.

Darrel Taylor
- 31st March 2013, 15:37
Try adding another 1 to your TRIS statement. It only has 7.

TRISC = %1111111

is the same as ...

TRISC = %01111111

Which puts PORTC.7 in output mode.

Or just leave the TRIS statement out. PIC's default to all 1's for all TRIS registers.

Neosec
- 31st March 2013, 16:17
Good catch DT, unfortunately that didn't help.

Edit!

Found the Problem!!! It's the EasyPIC3 Board! I removed the PIC 16F887 and C7 Stayed on!!!

What really helped was that the experienced people here didn't have a simple - Look dummy - answer. Not having a quick answer quickly helped solve the problem!

Thank you all!!

Neo

Neosec
- 31st March 2013, 16:47
Ok, here's a full rundown of what happened... All my fault of course, but perhaps some day someone else may have this issue or a similar one an be able to learn from my mistakes.
The EasyPIC3 development board has jumper settings for an RS-232 interface. The pertinent one here is the RX choices of RB1, RB2, RC7. RC7 was jumpered of course. This was the first project I've worked on on this board over 18 pins on a PIC so it was never an issue before. When I first noticed the LED on I set PORTC.7 as an output and to low... LED off. All good. Then I set TRISC = %1111111 which had no effect. Right then I noticed the jumper on the RS232 port, removed it, still the LED stayed on so I discounted the jumper as a factor since it made no difference, assuming it was un-powered or floating. As Darrel pointed out I only had 7 ones for the TRISC register which caused the removal of the RS-232 jumper to have no effect! Since TRISC was set to %01111111.
Removal of the RS-232 jumper and TRISC = %1111111 and RCSTA = %00000000 (neither of which were needed) and all's well.

A typo and a missed jumper combined it just the right order to really complicate things.

Thanks again

Neo

Demon
- 31st March 2013, 22:39
Thank you for taking the time to document your solution. :)

Robert