Minor Microcontroller Problem

Discussion in 'Embedded Systems and Microcontrollers' started by Skyferia, Jun 26, 2010.

  1. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    Hi,

    Alright here's the deal. I have a PIC16F877A microcontroller which somewhat refuses to work. Here's the details:

    • Programmed PIC16F877A using MPLAB and PICKIT2 to open ports A, B and D
    • Tested with an LED (with a 100Ω resistor in series), does not light up
    • Measured from a(ny) pin of Ports A, B and D to ground but has practically no reading
    • Measured from VDD to VSS, obtained 5V reading
    • Components untouched, reprogrammed PIC - noticed a short flicker on the LED when in process of programming
    I've tried the PIC on both my development kit and breadboard but with same results. From your experiences, is my PIC busted or is there something I overlooked?

    I do not have (access to) another PIC for the moment unfortunately.


    = EDIT =
    Forgot the code. Here:
    Code ( (Unknown Language)):
    1.  
    2. #include <pic.h>
    3.  
    4. __CONFIG(0x3f3A);                // 20Mhz HS XTAL-OSC
    5.  
    6. void main(void)
    7. {
    8.         TRISA = 0x00;
    9.         TRISB = 0x00;
    10.         TRISD = 0x00;
    11.         ADCON = 0x06;
    12.         CMCON = 0x07;
    13.         PORTA = 0xFF;
    14.         PORTB = 0xFF;
    15.         PORTD = 0xFF;
    16.  
    17.         while(1)
    18.         {
    19.         for(int i=0;i<20000;i++)
    20.         {
    21.             PORTA = 0xFF;
    22.             PORTB = 0xFF;
    23.             PORTD = 0xFF;
    24.          }
    25.     }
    26. }    
     
    Last edited: Jun 26, 2010
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    If you can program your device and verify the programmed data. I think it is good change for that your PIC is working.
    It is often wise to start very simple. Start with port A only. Then add some LEDS to PORTA. Also remember to set the ADCON1 register. It should have value 0x06h to set AN7 to AN0 as digital pins. If you have not done it, download the data sheet, and crosscheck what you have done for every register used
     
  3. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    Yes I can program and verify the data.

    I'm sorry, I don't quite get what you mean.

    Well.. Port B does not have any "restrictions" and can be readily programmed by only setting the tri-states as output. Will try the method you mentioned and update once done.

    Thank you kindly.

    = EDIT =
    Updated the code with
    Code ( (Unknown Language)):
    1. ADCON1 = 0x06;
    and... no, still not working... sigh, this'll teach me to always have a spare around.
     
    Last edited: Jun 26, 2010
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You could try to implement with RC oscillator. It could be that your oscillator is not working. Place the R and C component close the IC
     
  5. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    I did, and they are close to the IC. I even replaced the crystal with a 4MHz oscillator and two 15pF capacitors (and changing the config to __CONFIG(0x3f39)), still same results.

    The strange thing is the LED flicker during the time of programming. When I place the LED at, say, Port D, there was no flicker whatsoever.
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Probably a stupid question but do you have the MCLR pin pulled up to Vdd?
     
    Skyferia likes this.
  7. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    You mean if the MCLR is powered by 5V as well as the Vdd?
    Yes, except that a 10kΩ resistor resides between the 5V and the MCLR pin.
     
  8. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    ADCON1 = 0x06 for all digital outputs.
     
  9. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    Yup, tried that. Also if, in that context, Port A fails, Port B should be working perfectly. It's not. :(
     
  10. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    Forgot to say that for someone checking the code, that a config word hex value is worthless, spell it out. The LVP and WDT should be off.
     
  11. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    OSC is set to HS (XT when changing to 4MHz).
    WDT, PUT, BODEN, LVP, CP, CPD and WRT_ENABLE are all disabled.
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Are you sure the programmer is not pulling the MCLR low. I think it is low by default then using PICKIT 2. You have to pull it high in MPLAB.
     
    Skyferia likes this.
  13. Skyferia

    Thread Starter New Member

    May 5, 2010
    20
    0
    Really? Hmm.. could you guide me on how I can pull it high in MPLAB?

    = EDIT =
    It's alright I got it! Thanks guys, truly appreciate the help.
     
    Last edited: Jun 26, 2010
  14. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    That's weird and kinda odd. Don't use MPLAB, but use PICkit 2 in stand alone mode, so never had a problem with MCLR before.
     
  15. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You can use the PICKIT 2 application to control the MCLR pin also. But then this option is not selected. The MCLR pin is released to be controlled by the Hardware not the PICKIT. This is not the case in MPLAB. I think in the PICKIT application they turn the line controlling the MLCR into an input then not used to pull the line low
     
  16. reema paul

    New Member

    Jun 28, 2010
    12
    2
    start with board checking move on to open single port and then all.thou dint get y u use adcon1 where u just hv to switch on ports.
    use
    *********SOP********
    include<htc.h>
    void main()
    {
    unsigned int i;
    TRISB=0X00;
    TRISC=0X00;
    TRISD=0X00;
    PORTB=0XFF;
    for(i=0;i<=0x0f;i++);
    PORTC=0XFF;
    for(i=0;i<=0x0f;i++);
    PORTD=0XFF;
    for(i=0;i<=0x0f;i++);
    }
    *****************EOP***********
    try using this...still if there is no output.then ur controller is busted!
    all d best
     
Loading...