Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Port RA5 on PIC16F876A

Status
Not open for further replies.

ccola

New Member
OK first of I'm still getting my feet wet with pic programming so this is probably a simple answer is just has me stuck.

Is there something special about PortA.5 that I'm missing?

I'm using PBP, on a PIC16F876A, below is a small part (abbreviated) of the code, I am pulling portA pins low with a switch, and they should then light up the LEDs on portB in theory :) PortA.2 is measuring the value of a pot to adjust the amount of time the LED is on. Everything works except for PortA.5 it is just dead :( no matter what state PortA.5 is in it has no effect on the PortB.5 LED...

Code:
Y var Word

Define ADC_BITS 8
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50

ADCON1 = 7

PortA = %11111111
TrisA = %11111111
PortB = %00000000
TrisB = %00000000

main:

adcin 2, Y
Y = Y * 10

If PortA.0 = 0 Then
PortB.0 = 1
Pause Y
PortB.0 =0    
Endif

'This part of the code below doesn't work?

If PortA.5 = 0 Then
PortB.5 = 1
Pause Y
PortB.5 = 0    
Endif

Goto main
 
By default RA5 is an analogue input (along with ALL other analogue inputs), you don't show any code configuring the analogue pins - so I can only assume it's still set as an analogue input?.
 
Like I said I'm just getting my feet wet so yes, nothing is configured I guess and that is probably my problem?

It just puzzles me that portA 0, 1, 2, 3, 4 all work as is in the program but 5 just won't function....
 
ccola said:
Like I said I'm just getting my feet wet so yes, nothing is configured I guess and that is probably my problem?

It just puzzles me that portA 0, 1, 2, 3, 4 all work as is in the program but 5 just won't function....

Check the datasheet for the 16F876, or try my analogue tutorial at the URL listed below (which is probably simpler?), there are restrictions as to which pins can be analogue, you can't simply have individual ones at random as analogue - they have to be in a set pattern.

You need to check with your compiler about how to configure the analogue inputs, my assembler tutorial probably won't help you with that!.

BTW, there are only 5 analogue pins on PortA, and RA4 isn't one of them!, that's an open collector output pin (or a digital input pin), that often gives problems!.
 
ccola said:
OK first of I'm still getting my feet wet with pic programming so this is probably a simple answer is just has me stuck.

Is there something special about PortA.5 that I'm missing?

I'm using PBP, on a PIC16F876A, below is a small part (abbreviated) of the code, I am pulling portA pins low with a switch, and they should then light up the LEDs on portB in theory :) PortA.2 is measuring the value of a pot to adjust the amount of time the LED is on. Everything works except for PortA.5 it is just dead :( no matter what state PortA.5 is in it has no effect on the PortB.5 LED...

Code:
Y var Word

Define ADC_BITS 8
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50

ADCON1 = 7        

PortA = %11111111
TrisA = %11111111
PortB = %00000000
TrisB = %00000000

main:

adcin 2, Y
Y = Y * 10

If PortA.0 = 0 Then
PortB.0 = 1
Pause Y
PortB.0 =0    
Endif

'This part of the code below doesn't work?

If PortA.5 = 0 Then
PortB.5 = 1
Pause Y
PortB.5 = 0    
Endif

Goto main


Adcon1=7 sets all porta pins to digital mode
I suggest you move your pot to AN0 and use adcon1=14 or adcon1=%1110
this sets AN0 to analog and AN1-7 as digital



Mart
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top