Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16F877A not functioning

Status
Not open for further replies.

daredavel

New Member
the code is clean and running in proteus, but when i program it in my pic16f877a its not functioning..doesn't even output logic 1.. vdd/vss are connected correctly..but no reading from the output ports.. I can read/write in my pic..i think its not broken.. :confused: I even tested it to output 2 ports.. still no output..can't even lit an LED.. what could be possible wrong?

here's my program for outputting the 2 ports:

Code:
		LIST	P=16F877A
		#include <p16f8477.inc>
		
		__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
		
org	0x0000

		bsf	STATUS, RP0
		movlw	0x00
		movwf	TRISC
		movwf	TRISD
	

		bcf	STATUS, RP0
		movlw 	0xff
		movwf 	PORTC
		movwf	PORTD

		end
 
the code is clean and running in proteus, but when i program it in my pic16f877a its not functioning..doesn't even output logic 1.. vdd/vss are connected correctly..but no reading from the output ports.. I can read/write in my pic..i think its not broken.. :confused: I even tested it to output 2 ports.. still no output..can't even lit an LED.. what could be possible wrong?

here's my program for outputting the 2 ports:

Code:
        LIST   [COLOR=Blue] P=16F877A[/COLOR]
      [COLOR=Red]  #include <p16f8477.inc>[/COLOR]
        
        __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
        
org    0x0000

        bsf    STATUS, RP0
        movlw    0x00
        movwf    TRISC
        movwf    TRISD
    

        bcf    STATUS, RP0
        movlw     0xff
        movwf     PORTC
        movwf    PORTD

        end

hi,
The PIC is set to a different type.???
 
One thing wrong is it's not a valid program, it will repeatedly loop round and keep running from the start - you need to add an endless loop at the end. Secondly, you have the wrong include file referenced.

You could also be using non-functioning hardware, assembled wrongly.
 
Look at this edited version.

Code:
        LIST    P=16F877A
        #include <p16f877A.inc>
        errorlevel  -302 , -207             ; suppress message 302 from list file

        __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _[COLOR="Red"]RC[/COLOR]_OSC
CounterA equ 0x20
CounterB equ 0x21
CounterC equ 0x22

        
    org    0x0000

        bsf    STATUS, RP0
        movlw    0x00
        movwf    TRISC
        movwf    TRISD
    
loop1:
        bcf    STATUS, RP0
        movlw     0xff
        movwf     PORTC
        movwf    PORTD
        call    delay1        
        movlw     0x00
        movwf     PORTC
        movwf    PORTD
       [COLOR="Red"] call    delay1[/COLOR]  
        goto loop1

;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
delay1:
        movlw    D'3'
        movwf    CounterC
        movlw    D'138'
        movwf    CounterB
        movlw    D'85'
        movwf    CounterA
loop        decfsz    CounterA,1
        goto    loop
        decfsz    CounterB,1
        goto    loop
        decfsz    CounterC,1
        goto    loop
        retlw    0
        end

EDITED: the Delay1
 
Last edited:
That's so similar to my tutorial 1.2 Eric :D

Same problem, same solution.

Code:
;Tutorial 1.2 - Nigel Goodwin 2002
	LIST	p=16F628		;tell assembler what chip we are using
	include "P16F628.inc"		;include the defaults for the chip
	__config 0x3D18			;sets the configuration settings (oscillator type etc.)

	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb 			;used in delay routine
	endc
	
	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
					;this is where the program starts running	
	movlw	0x07
	movwf	CMCON			;turn comparators off (make it like a 16F84)

   	bsf 	STATUS,		RP0	;select bank 1
   	movlw 	b'00000000'		;set PortB all outputs
   	movwf 	TRISB
	movwf	TRISA			;set PortA all outputs
	bcf	STATUS,		RP0	;select bank 0

Loop	
	movlw	0xff
	movwf	PORTA			;set all bits on
	movwf	PORTB
	nop				;the nop's make up the time taken by the goto
	nop				;giving a square wave output
	call	Delay			;this waits for a while!
	movlw	0x00
	movwf	PORTA
	movwf	PORTB			;set all bits off
	call	Delay
	goto	Loop			;go back and do it again

Delay	movlw	d'250'			;delay 250 ms (4 MHz clock)
	movwf	count1
d1	movlw	0xC7
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

	end

You missed the second delay call Eric, so it won't flash, but will appear to be permanently ON
 
Last edited:
Woops!, too quick on the keyboard today, missed that 2nd delay!!...:eek:
 
sorry sir! i posted the wrong code..didn't notice it right away..anyway, you corrected it..:D thats pretty helpful sir nigel! but i don't have an xtal osc right now..i only have a couple of led..resistors..and the pic to test the ports..a simple output 1 will to lit the leds will do..:)
 
sorry sir! i posted the wrong code..didn't notice it right away..anyway, you corrected it..:D thats pretty helpful sir nigel! but i don't have an xtal osc right now..i only have a couple of led..resistors..and the pic to test the ports..a simple output 1 will to lit the leds will do..:)

Your program is set to use a 20MHz external crystal, so it's not surprising it doesn't work if you don't have one. You could set it to use a simple RC oscillator instead, and add those components. One of the reasons my tutorials are based mainly on the 16F628 is that the 16F628 has an internal oscillator, no need for any external one.
 
how did you know that my program is set to use a 20MHz oscillator sir? how i could set it to 4MHz? actually, i just took the worksheet from unknown program and edit the contents.. thank you!
 
how did you know that my program is set to use a 20MHz oscillator sir? how i could set it to 4MHz? actually, i just took the worksheet from unknown program and edit the contents.. thank you!

Because you have it set to _HS_OSC in the config fuses (which is 'mostly' used for 20MHz).

Setting it to a lower frequency crystal won't help you unless you have the lower frequency crystal and capacitors fitted.
 
sorry sir! i posted the wrong code..didn't notice it right away..anyway, you corrected it..:D thats pretty helpful sir nigel! but i don't have an xtal osc right now..i only have a couple of led..resistors..and the pic to test the ports..a simple output 1 will to lit the leds will do..:)

hi,
Set the CONFIG to 0x3F33 for Res/Cap osc mode.
Look at this image file.

Or:
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    33.1 KB · Views: 211
Last edited:
thank you sir!! in that way sir, i dont have to add the 4MHz xtal and cap? or i still should? will it be ok now without the xtal sir?
 
thank you sir!! in that way sir, i dont have to add the 4MHz xtal and cap? or i still should? will it be ok now without the xtal sir?

hi,
With two Sirs its a little confusing.:D

If you mean my post, no 4mHz crystal, just a 20pF cap and say a 82K resistor will get you going.

CONFIG at _RC_OSC
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top