Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

A faulty pin on PIC 16F876, RA5?

Status
Not open for further replies.

Tricka90

Member level 1
Joined
Sep 2, 2013
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
385
I'm trying to light up a LED with a PIC 16F876 (datasheet: https://ww1.microchip.com/downloads/en/devicedoc/30292c.pdf) on port RA5. The LED just doesn't light up.
I've set TRISA = 0 and PORTA.RA5 = 1 of course.
In the datasheet I found that RA5 is also an analog port, so I set up all ports as digital with ADCON1 = 0b00000110 and ADCON0 = 0.
Still the LED doesn't work.
Then I found that RA5 is also a "slave select for the synchronous serial port" so I tried to disabilitate this function with PIE1.SSPIE = 0 and SSPCON.SSPEN = 0.
The LED continues not lighting up.
Do you think I'm doing something wrong? Could it be that pin RA5 is just faulty?
 

The code it's just like that for now.
Yes, MCLR is high and all other pins does work
 

Then I found that RA5 is also a "slave select for the synchronous serial port" so I tried to disabilitate this function with PIE1.SSPIE = 0 and SSPCON.SSPEN = 0.

You don't have to do this, the register should be set to zero on a reset.

CLRF PORTA ; Initialize PORTA by
; clearing output data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x06 ; Configure all pins
MOVWF ADCON1 ; as digital
CLRF TRISA
BCF STATUS, RP0 ; Select Bank 0

This code should work, you do not show your circuit diagram so I assume the LED is connected to the +5V via a 220R resistor. If the LED is connected to ground the change the first line to read

movlw 0FFH
movwf PORTA
 

What kind of language is that? I'm using MikroC and it doesn't recognize it!
The LED is connected to ground
 

Please, try this into real pic mcu!!!

Using 20MHz Crystal Osc.

************************************************************************************************

This code is:
"
Code:
CLRF PORTA ; Initialize PORTA by
; clearing output data latches
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x06 ; Configure all pins
MOVWF ADCON1 ; as digital
CLRF TRISA 
BCF STATUS, RP0 ; Select Bank 0
"
MPLAB MPASM Assembly language!!!
 

Attachments

  • Pisca.rar
    9.2 KB · Views: 56
Last edited:

Try this.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void main(){
 
      TRISA = 0x00;
      PORTA = 0x00;
      ADCON1 = 0b00000110;
      CMCON = 0x07;
 
      PORTA.F5 = 1;   //PORTA.B5 = 1;
 
      while(1){
 
 
          ;
 
 
      }
}

 

Thank you for all the help.
I must say I'm really really sorry, I made a big mistake: the "faulty" pin isn't RA5...it is RA4 !!!
This pin could also be used as T0CKI, that is Timer0 clock input.
I have disabled the bits, now I have OPTION_REG = 0b100000010, just RBPU and prescaler because I would like to use Timer0 in my program.
Why it still doesn't work? Should I set other bits?
 

Hi,

Check the datashhet, RA4 is an open collector output, so you need to add a pull up resistor when used as an output

Have a look here for an explanation **broken link removed**
 
Last edited:

Check the output voltage at the purticular pin when the program is running... If you get 5V then your mc is working fine. If you get less than 3.5V then use a pull up resister.
 
wp100 is correct. As mentioned in the datasheet page no 29, RA4 is open drain output. So, you need to pullup the RA4 pin.

HTML:
Pin RA4 is multiplexed with the Timer0 module clock
input to become the RA4/T0CKI pin. The RA4/T0CKI
pin is a Schmitt Trigger input and an open drain output.
All other PORTA pins have TTL input levels and full
CMOS output drivers.
 
Last edited:

Hi,

As you can see it reverses the logic.
 

Attachments

  • 000106.jpg
    000106.jpg
    47.7 KB · Views: 91

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top