PIC16F877A not working


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default PIC16F877A not working

    Hi. ive just connected a PIC16F877A up and programmed it with some test code but its not working properly. I have set picbasic and my programmer to the correct chip this time :P

    Heres the test code

    Code:
    trisa=%00000000
    trisb=%00000000
    trisc=%00000000
    trisd=%00000000
    
    high portb.0
    loop:
    high porta.0
    pause 500
    low porta.0
    pause 500
    goto loop
    This should see 1 LED on constantly and one flashing. Both LEDs come on but thats it. They just stay on. What could cause this to happen? Im doing everything in the same way i would with any other chip

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > "That which seems simple is often overlooked" (Usually by me)

    You've overlooked the DATASHEET...

    Change PortA to one of the other pins on PortB and you're in business...

    Then... when you're ready to play with BIG features instead of just the noddy ones...

    1. Grab a Beer (Gingerbeer/Rootbeer if you're a weenie)...
    2. Look in the Datasheet and discover how to DISABLE the Comparators on PortA
    3. Look in the Datasheet and discover how to DISABLE the A/D Convertors on PortA
    4. Look in the Datasheet and discover how to set PortA in DIGITAL mode
    5. Reporgram back to PortA and watch LED's blink
    6. Sit back and feel good at how useful the Adobe pdf reader is...

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    Oh, I did look at the datasheet so i knew which pins were on which port but ive used these chips before and only ever had a problem with 1 pin. I only need 1 pin eventually for a serial connection but this is the biggest chip i have laying around and i need a lot of space on the chip.

    I changed porta.0 to portb.1 but its still doing the same thing. I have a feeling its still something simple but i dont know what. Im gonna go get that beer

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Lucky guy, i feel generous today
    Code:
            asm        
            ifdef PM_USED
                device  pic16F877A, xt_osc, wdt_on, lvp_off, protect_off
            else
                __config _XT_OSC & _WDT_ON & _LVP_OFF & _CP_OFF
            endif
            endasm
            
            PORTA = 0
            PORTB = 0
            TRISA = 0
            TRISB = 0
            ADCON1 = 7
            CMCON = 7 
            
            CounterA VAR BYTE
            
    Start:
            for CounterA = 0 to 5
                PORTA = DCD CounterA
                PAUSE 250
                NEXT
            PORTA = 0
            
            FOR CounterA = 0 TO 7
                PORTB = DCD CounterA
                PAUSE 250
                NEXT
            PORTB = 0
                    
            GOTO Start
    make sure you properly filter the PSU line and the PIC is powered , make sure MCLR line is tied to Vdd, make sure PGM pin is loaded to GND while programming, and also make sure you have a crystal + caps attached to the PIC. The above assume a 4MHz crystal/resonator.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I have the circuit setup in the normal way. 10K resistor between VDD and MCLR. 4MHz resonator. 100uf capacitor plus 3 smaller ones. I dont know what PGM is. My programmer supports this type of chip so i would assume it sets that for me. I have never had trouble with these kind of chips before. I have tested 2 chips to be sure.

    I dont quite understand all of your code but i will try it anyway. How come you only set ports A and B? If im not using the others then dont i need to put anything in about them? Not even trisc/trisd?

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Well yes and no. Here it's an example, and i don't use the other PORTs, they're just tied to GND with some pull-down resistors... if not defined, TRISC, TRISD should have their own POR value. Usually set to $FF, have a look at the datasheet, you should find a section about the Power-On Reset values (POR)

    don't worry, it works.

    Make sure you have connected ALL Vss and ALL Vdd, unless it may not work as expected.

    If it's still don't work, program your PIC with the code above, then read it back, save the .HEX file to another FileName and post it here.. maybe there's a strange issue somewhere. Who knows.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    I have connected all 4 power pins but ive not grounded the outputs. I know your supposed to but ive never had a problem with it before. Ill give it a test maby tomoz, got a bit of a party goin off today

Similar Threads

  1. PIC16F877A PORTA.2 not working
    By The Master in forum Off Topic
    Replies: 2
    Last Post: - 10th October 2009, 18:16
  2. PIC16F877A analog problem
    By DeViLa_Q8 in forum mel PIC BASIC
    Replies: 0
    Last Post: - 30th July 2009, 20:19
  3. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  4. PIC16F877A not working again :(
    By The Master in forum Off Topic
    Replies: 24
    Last Post: - 30th October 2008, 00:04
  5. communicating pic18f452 with pic16f877a
    By tamersoss in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th July 2007, 19:54

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts