PIC16F876 flashing problem

Discussion in 'Embedded Systems and Microcontrollers' started by lihle, Sep 21, 2010.

  1. lihle

    Thread Starter Active Member

    Apr 12, 2009
    83
    3
    guys i dont know what going on with my pic. i am using pic16f876 with 4Mhz crystal oscillator, 22pF capacitor. i have written a flash code to test the output and it seems its not working for me. here is my code below.i am trying to measure the output voltage to be +5v. i have put Mclr to +5v.

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF


    org 0x000
    goto Start
    org 0x006
    Start
    bsf STATUS,RP0
    MOVLW H'06'
    MOVWF ADCON1
    movlw 0x00
    movwf TRISB
    movwf TRISA
    movwf TRISC
    bcf STATUS,RP0
    movlw 0x0F
    movwf PORTA
    movlw b'00000000'
    movwf PORTB
    movlw b'00000111'
    movwf PORTC
    ;*********************************************************
    Main
    clrf PORTB
    movlw b'11111111'
    movwf PORTB
    ;bsf PORTB
    goto Main


    END ; directive 'end of program'
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    What is your setup. If you use say a Pickit programmer and let this unit also supply power during runtime. You must check both that power is turned on, and that the MCLR pin is not set to low level.
     
  3. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    Verify the registers in your equates section are correct. I've spent an hour or two banging my head against the keyboard before only to discover I equated things like "PORTB" to the wrong register.
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Good catch. In this case they seams to missing.
     
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    PORTB, etc are all defined in the include file:
    If you have the include line all is fine.
    PORTB is flashing far too fast for the eye to see. Any LED connected to it should just look on.

    Code ( (Unknown Language)):
    1.     list      p=16f876            ; list directive to define processor
    2.     #include <p16f876.inc>        ; processor specific variable definitions
    3.    
    4.     __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF
    5.  
    6. ; '__CONFIG' directive is used to embed configuration data within .asm file.
    7. ; The lables following the directive are located in the respective .inc file.
    8. ; See respective data sheet for additional information on configuration word.
    9.  
    10.  
    11.  
    12.  
    13.  
    14.  
    15. ;***** VARIABLE DEFINITIONS
    16. w_temp        EQU     0x7E        ; variable used for context saving
    17. status_temp   EQU     0x7F        ; variable used for context saving
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24.  
    25.  
    26. ;**********************************************************************
    27.         ORG     0x000             ; processor reset vector
    28.         clrf    PCLATH            ; ensure page bits are cleared
    29.           goto    main              ; go to beginning of program
    30.  
    31.  
    32.         ORG     0x004             ; interrupt vector location
    33.         movwf   w_temp            ; save off current W register contents
    34.         movf    STATUS,w          ; move status register into W register
    35.         movwf    status_temp       ; save off contents of STATUS register
    36.  
    37.  
    38. ; isr code can go here or be located as a call subroutine elsewhere
    39.  
    40.  
    41.         movf    status_temp,w     ; retrieve copy of STATUS register
    42.         movwf    STATUS            ; restore pre-isr STATUS register contents
    43.         swapf   w_temp,f
    44.         swapf   w_temp,w          ; restore pre-isr W register contents
    45.         retfie                    ; return from interrupt
    46.  
    47.  
    48.  
    49. main
    50.  
    51. ; remaining code goes here
    52.  
    53.  
    54.  
    55.  
    56.         END                       ; directive 'end of program'
     
  6. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Your code is switching the port pins high/low repeatedly.

    Is this what you have wanted in the first place? Or do you want to check the pin level to be steady?

    Code ( (Unknown Language)):
    1. ;*************************************************  ********
    2. Main                    
    3.        clrf            PORTB
    4.        movlw           b'11111111'
    5.        movwf           PORTB
    6.        ;bsf            PORTB
    7.        goto            Main     ; // use "goto $" if you want steady pin level
    8.  
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This code should work for chip. Unless your name is Clark Kent you will never see any blinking. Because the switch rate is way to high.
    Code ( (Unknown Language)):
    1.  
    2. list   p=16f876
    3. #include <p16F876.inc>
    4.   __CONFIG (_CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF)
    5.  
    6.     cblock 0x20
    7. Delay1                   ; Define two file registers for the
    8. Delay2                   ; delay loop
    9.      endc
    10.      
    11.      org 0
    12. Start:
    13.      bsf       STATUS,RP0          ; select Register Page 1
    14.      movlw 0
    15.      tris PORTC                ;test instr
    16. ;bcf       TRISC,0             ; make IO Pin B.0 an output
    17.      bcf       STATUS,RP0          ; back to Register Page 0
    18. MainLoop:
    19.      bsf       PORTC,0             ; turn on LED C0
    20. OndelayLoop:
    21.      decfsz    Delay1,f            ; Waste time.  
    22.      goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
    23.      decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
    24.      goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
    25.                                    ; call it a two-tenths of a second.
    26.      
    27.      bcf       PORTC,0             ; Turn off LED C0
    28. OffDelayLoop:
    29.      decfsz    Delay1,f            ; same delay as above
    30.      goto      OffDelayLoop
    31.      decfsz    Delay2,f
    32.      goto      OffDelayLoop
    33.      goto      MainLoop            ; Do it again...
    34.      end
    35.  
     
  8. lihle

    Thread Starter Active Member

    Apr 12, 2009
    83
    3
    guys i have solve the problem. the thing was the breadboard threads of which are loose and the crystal oscillator was floating. even though i have spent a lot of time trying to fix the problem. that is before you suspect your code try to use a continuity tester to track the voltage path, it will help you.

    lihle
     
Loading...