PIC16F877A based project

Discussion in 'Embedded Systems and Microcontrollers' started by harami, Jun 20, 2011.

  1. harami

    Thread Starter Member

    Jun 20, 2011
    66
    0
    Im new to the PIC world and am having difficulties using it in my project. My project is a simple lighting control system. I already written the program (code). I programmed the PIC and build it on a breadboard. I also build a external RC ocillator. But I still get zero output.

    PIN 19,20,21 - output from the pic to the keypad
    PIN 27,28,29,30 - input to the pic from the keypad
    PIN 23,24,25,26 - output from the pic, connected to the leds

    PIN 1 - 5V pow
    er supply
    PIN 40 - GND

    PIN 13, 14 - RC ocillator

    Also, on pic16f877a, PIN 11,12 and 31,32 they both are VSS and VDD. So can we use only one of them or do we have to use both of them.

    Can you guys help me PLEASE!!!
     
    Last edited: Jun 20, 2011
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Not before you post code and schematic
     
  3. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    And also post your configuration settings, if you are configuring them from your programmer application.
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Possible problems (with no diagram, can't say for sure):

    Oscillator isn't right/doesn't match config word

    You've used low-voltage programming and haven't grounded Portb.3

    Reset pin not correctly wired

    You didn't use Port B for the inputs from the keypad, and didn't install pullup resistors
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    QFT.

    Also, check the pins used as digital are not being default configured to analog functions. Especially check pins with an "AN#" option.
     
  6. harami

    Thread Starter Member

    Jun 20, 2011
    66
    0
    thank you everyone for your replies... i have attached my circuit design and the code.
    Thank you for your help..
     
  7. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I didn’t gone through your code, but then also as per your schematic their are a lots of problem,
    1) First the current limiting resistor for the LEDs are 1K which will limit the current too much you should use 330 ohms instead.
    2) Your configuration setting for oscillator is RC but you wired a crystal for that your setting should be HS(High Speed Crystal/Resonator).And that 10K resistor to pin 14 is not needed unless it’s a AT strip cut crystals or if it's the case of overdriving.
    3)And pin no 12 and 31 should be connected to Vss i.e.. GND
    4)Normally we use 0.1uF rather 1nF.

    Good luck
     
    Last edited: Jun 20, 2011
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    To expand on debjit's... that's 1nf to 0.1 as a bypass cap. For the crystal I've normally seen values such as 22pF there but that depends on the exact crystal you used (meaning it's probably on the data sheet for the crystal). 1K on the LEDs may be OK, they ain't gonna be bright but I've done that before.

    How are you programming this? Pins 39 & 40 are used for programming but you have 40 grounded. MCLR on pin 1 is good, without that resistor these things tend to only work when the programmer is connected. 1K may be low, 10K is typical.

    Additionally, when posting a micro's schematic it is best to indicate what function you are using on the pins, otherwise we'd have to look up the part and write that in to see all of what you're doing. (And guess what? I ain't a gonna do that! ;) )
     
  9. stahta01

    Member

    Jun 9, 2011
    133
    21
    This is stupid, I am not going to waste my time looking up what "5" means.

    Code ( (Unknown Language)):
    1.  
    2. BSF STATUS,5        ;BANK 1
    3.  
    Learn to use the inc file; do not define the things all over again.

    Code ( (Unknown Language)):
    1.  
    2. PLC    EQU 02h    
    3. PORTC    EQU 07h
    4. PORTD    EQU 08h
    5. TRISC     EQU 87h
    6. TRISD     EQU 88h
    7. KEY     EQU 20h
    8. STATUS     EQU 03h
    9.  
    Learn to use the proper columns in assemble.
    Your code had over a dozen column warnings.
    instruction can not be in first columns.
    labels must be in first columns.

    Tim S.
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Tim?

    Is there perhaps a gentler way to convey this information to harami? After all, he is new here and it does take some guts to present your work to strangers for review.

    I know you have 3 whole posts more then harami and you do have several legitimate points here, just please try to be encouraging towards someone who is doing honest work while struggling with both hardware and software issues on his first project.
     
  11. stahta01

    Member

    Jun 9, 2011
    133
    21
    I suggest measuring one or more of the outputs and verify it is changing from high to low.

    If not, the first thing to check is Power and Ground hooked up right.
    Second, is external crystal circuit correct.
    debjit625 says there might be an issue there.

    Note: I suggest using a know good simple program to confirm the hardware setup above is correct.

    I suggest one that is only changing a single output pin to confirm the software and hardware works together.

    Tim S.
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    A programmer is not a prgrammer, unless he/she is able to utelize the power of the availible tools. And herby be able to debug and simulate code. The hobbyist may not have accsess to fancy (and expensive) hardware debugging tools. But the fact is that many errors can be tracked down with the software simulator tool named MPLAB SIM.
    http://forum.allaboutcircuits.com/showthread.php?t=44852
     
  13. stahta01

    Member

    Jun 9, 2011
    133
    21
    Third thing to check is the right voltage the reset/ master clear pin.
    It looks like you already have this on pin 1.

    Tim S.
     
  14. harami

    Thread Starter Member

    Jun 20, 2011
    66
    0
    as far as the code is concern, i do get lots of warnings however i managed to minimise all the errors. i compiled it using MPLAP IDE and it worked perfectly. but when i put it on a breadboard i get nothing which proves that there is something wrong with the circuit.

    as the PIC16F877A haven't got internal oscillator, i have config RC_OSC on the code and build a RC oscillator circut. i connected pin1 to 5 V power supply. i searched for pic16f877a based projects to understand how the circuit are built and what needs to be connected to the pic in order to make it work. but i cant find any relevant information. can anyone tell me if i need to add anything else to my circuit. and if possible can anyone give me a rough circuit diagram for this project. with this project im going nowhere and i really need help from you guys... PLEASE!!
     
  15. stahta01

    Member

    Jun 9, 2011
    133
    21
    http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

    Per Table 14-2 You need to use HS for a normal 6MHz Crystal and the Caps should be 15pF; and remove the 10K resistor unless you have a valid reason to have it. If you do, state that reason.

    You need to use _HS_OSC instead of _RC_OSC.

    Tim S.
     
  16. harami

    Thread Starter Member

    Jun 20, 2011
    66
    0
    as i have already used _RC_OSC, i will connect a RC oscillator circuit to the pic. it does not make any difference which ever OSC i config or dose it? im using 10k resistor and 1nf caps for RC oscillator circuit. do u think this will be appropriate?

    Also i need a power supply for 3 different pins. do i need to supply 5V individually or shall i connect it all to a 5v power rail?
     
  17. stahta01

    Member

    Jun 9, 2011
    133
    21

    You need to use _HS_OSC !!! Edit: This assumes you are still using the 6MHz Crystal.

    No, I do NOT think it is correct; please read the datasheet.
    Or, have you decided not to use a Crystal?

    What type of Crystal are YOU using?


    Tim S.
     
    Last edited: Jun 25, 2011
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Per the fine manual Fig 14.3 use an R between 3K and 100K (so 10K is good) and a C of greater then 20 pF, so again 1 nF is also good.

    Connect all the 5V stuff to the 5V rail. What else could you do, use multiple 5V supplies?
     
  19. harami

    Thread Starter Member

    Jun 20, 2011
    66
    0
    i have attached my circuit design. i build my circuit as shown in this design but it still not working. can anyone please help me. deadline for this project is in 2 weeks time and i still cant figure out the problem. can anyone please have a look at my circuit diagram...
    circuit diagram.png
     
  20. kavli

    New Member

    Aug 1, 2011
    23
    2
    Before we can get any further, you need to tell if you're using an RC oscillator or an X-tal, as your diagram suggests.

    An X-tal (Crystal) is not the same thing as an RC oscillator. An RC-oscillator is made from a resistor and a capacitor, hence the name. And because those two oscillator circuits are fundamentally different seen from the controller point of view, you need to specify the correct config word when programming the device, as several has suggested in this thread. Please review those comments.

    -- K
     
Loading...