• AVR Freaks

AnsweredSetting pins RA6/RA7 to I/O mode on PIC16F18875

Author
FileDotZip
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/11/30 18:58:55
  • Location: 0
  • Status: offline
2019/06/13 17:39:36 (permalink)
0

Setting pins RA6/RA7 to I/O mode on PIC16F18875

Hi, I can not seem to find any quick start guide to getting my microcontroller ports RA6/7 to I/O instead of OSC output. At first, they were oscillator outputs, then I changed the configuration bit from EXT1X to HFINT32 (and went full throttle to 32Mhz). This disabled RA6's (what I now know was an OSC output) digital output to 0. RA7 and RA6 now do not respond to being set high in the code, and neither are outputting clock signals. They are seemingly dead. I would like to revive them as IO pins.

My configuration bits are attached to this post.
 
Here is the datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/400001802D.pdf

and here is my code
https://pastebin.com/wA56ktNb

Attached Image(s)

#1
mbrowning
Just a Member
  • Total Posts : 1365
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: online
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 09:52:21 (permalink)
0
#pragma config FEXTOSC = HS     // External Oscillator mode selection bits (EC above 8MHz; PFM set to high power)

 
Maybe if you didn't force the oscillator on?

Oh well - there's always next year
#2
FileDotZip
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/11/30 18:58:55
  • Location: 0
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 09:54:59 (permalink)
0
Sorry, I dont understand what you mean. The Oscillator is running, as my code is executing and LED's are blinking.
#3
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11188
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 10:07:14 (permalink) ☄ Helpfulby FileDotZip 2019/06/14 10:15:50
+2 (2)
config FEXTOSC = HS

 
You're still enabling an external oscillator.  You need OFF, not FEXTOSC.
#4
FileDotZip
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/11/30 18:58:55
  • Location: 0
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 11:00:06 (permalink)
0
I have a followup question. RA0-7 now go high with 5V. With other pins such as PortC and PortD, I am not getting such luck. Sometimes they have 5V if I turn only one pin high, but if i turn two high (on portD) then one goes to 1.4V and one goes to 3.8V. I think its because the pins are analog capable, and are giving an analog signal out. How can I make them give a digital signal out? (i.e 5V on high)
#5
mbrowning
Just a Member
  • Total Posts : 1365
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: online
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 11:31:20 (permalink)
+1 (1)
The datasheet holds all the answers. "Analog capable" means analog inputs. Analog input buffers are always on, and ANSEL registers allow you to turn on the digital buffers for digital input use. Digital outputs are unaffected by any of that. There are a couple of fixed location DAC outputs which can be configured to be analog outputs through the DAC control registers, but never default to that.
 
You are either overloading the outputs, or measuring them wrong (e.g. measuring a toggling output with a multimeter).
 
edit - or not properly making them outputs
post edited by mbrowning - 2019/06/14 11:32:22

Oh well - there's always next year
#6
FileDotZip
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2016/11/30 18:58:55
  • Location: 0
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 11:40:06 (permalink)
0
I am making RC0/7 and RD0/7 outputs and enabling them just like I enabled RA0/7 and set them as high. Each RA pin goes to 5V. Exactly what I need. Pardon me, but i am still learning to read datasheets, what feature should i look for in other ports/pins(such as RC and RD) to match the (described above) functionality of RA0/7?
#7
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11188
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 11:49:12 (permalink)
+1 (1)
Write to LAT registers, not PORT registers.
#8
cvm
Super Member
  • Total Posts : 268
  • Reward points : 0
  • Joined: 2011/09/16 05:16:15
  • Location: 0
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 12:13:16 (permalink)
+1 (1)
#pragma config WDTE = ON
 
You may want to disable the watchdog, as you will be getting a watchdog reset every 2 seconds, I think. Not real easy to figure out what pins are doing when the mcu is resetting all the time.
#9
ahuramazda
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2016/09/03 08:11:17
  • Location: 0
  • Status: online
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 12:41:50 (permalink)
0
Why dont you use mcc?
#10
ric
Super Member
  • Total Posts : 22361
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Setting pins RA6/RA7 to I/O mode on PIC16F18875 2019/06/14 15:18:10 (permalink) ☼ Best Answerby FileDotZip 2019/06/14 15:34:43
+2 (2)
FileDotZip
Sorry, I dont understand what you mean. The Oscillator is running, as my code is executing and LED's are blinking.

I see you've already fixed this, but just to be clear what the problem was, this line
#pragma config FEXTOSC = HS     // External Oscillator mode selection bits (EC above 8MHz; PFM set to high power)

turns on the external oscillator, so RA6 and RA7 are dedicated to external oscillator use..
This line
#pragma config RSTOSC = HFINT32   // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits)

tells your PIC to use the internal oscillator, but plainly the code has been changed without changing the comment, which still says the external oscillator is being used.
 

I think its because the pins are analog capable, and are giving an analog signal out. How can I make them give a digital signal out? (i.e 5V on high)

"analog capable" refers to the input capability, not output.
All "analog capable" pins power up in analog mode, and will read as zero if you try to do a digital read of them before switching them to digital mode (via the matching ANSELx register).
 
As jtemples pointed out, do writes to LAT registers, not PORT registers. It doesn't matter so much when you write an entire port (e.g. PORTC = 0), but it is critical when you write an individual bit.
So, instead of
RD0 = 1;

use
LATD0 = 1;

Get into the right habit now. If you do it the wrong way, it will sometimes work, and sometimes fail, and cause you hours of fruitless debugging!
 
And finally, as CVM mentioned, turn off the WDT.
Do NOT enable it until you understand how it works, and what it is for. Otherwise as mentioned it will keep resetting your PIC every two seconds.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#11
Jump to:
© 2019 APG vNext Commercial Version 4.5