PIC16F876 flashing problem

Thread Starter

lihle

Joined Apr 12, 2009
83
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'
 

t06afre

Joined May 11, 2009
5,934
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.
 
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.
 

Markd77

Joined Sep 7, 2009
2,806
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.

Rich (BB code):
    list      p=16f876            ; list directive to define processor
    #include <p16f876.inc>        ; processor specific variable definitions
    
    __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & _RC_OSC & _WRT_ENABLE_ON & _LVP_ON & _DEBUG_OFF & _CPD_OFF

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.






;***** VARIABLE DEFINITIONS
w_temp        EQU     0x7E        ; variable used for context saving 
status_temp   EQU     0x7F        ; variable used for context saving








;**********************************************************************
        ORG     0x000             ; processor reset vector
        clrf    PCLATH            ; ensure page bits are cleared
          goto    main              ; go to beginning of program


        ORG     0x004             ; interrupt vector location
        movwf   w_temp            ; save off current W register contents
        movf    STATUS,w          ; move status register into W register
        movwf    status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


        movf    status_temp,w     ; retrieve copy of STATUS register
        movwf    STATUS            ; restore pre-isr STATUS register contents
        swapf   w_temp,f
        swapf   w_temp,w          ; restore pre-isr W register contents
        retfie                    ; return from interrupt



main

; remaining code goes here




        END                       ; directive 'end of program'
 

eblc1388

Joined Nov 28, 2008
1,542
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?

Rich (BB code):
;*************************************************  ********
Main                    
       clrf            PORTB
       movlw           b'11111111'
       movwf           PORTB
       ;bsf            PORTB
       goto            Main     ; // use "goto $" if you want steady pin level
 

t06afre

Joined May 11, 2009
5,934
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.
Rich (BB code):
list   p=16f876 
#include <p16F876.inc>
  __CONFIG (_CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF & _DEBUG_OFF & _CPD_OFF)
  
    cblock 0x20
Delay1                   ; Define two file registers for the
Delay2                   ; delay loop
     endc
      
     org 0
Start:
     bsf       STATUS,RP0          ; select Register Page 1
     movlw 0
     tris PORTC                ;test instr
;bcf       TRISC,0             ; make IO Pin B.0 an output
     bcf       STATUS,RP0          ; back to Register Page 0
MainLoop:
     bsf       PORTC,0             ; turn on LED C0
OndelayLoop:
     decfsz    Delay1,f            ; Waste time.  
     goto      OndelayLoop         ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
     decfsz    Delay2,f            ; The outer loop takes and additional 3 instructions per lap * 256 loops
     goto      OndelayLoop         ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
                                   ; call it a two-tenths of a second.
      
     bcf       PORTC,0             ; Turn off LED C0
OffDelayLoop:
     decfsz    Delay1,f            ; same delay as above
     goto      OffDelayLoop
     decfsz    Delay2,f
     goto      OffDelayLoop
     goto      MainLoop            ; Do it again...
     end
 

Thread Starter

lihle

Joined Apr 12, 2009
83
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
 
Top