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.

16F876A Simpe Program, Yet not working !

Status
Not open for further replies.

aljamri

Member
16F876A Simple Program, Yet not working !

Hi,

Long time I've not dealt with 16F876A, know want to do some experiment, not succeeded. back to square 1, copied a ready made Template from MPLab and put a simple ON - OFF program as in the following code but failed to make it work.

Is there anything wrong with it ?



Code:
list		p=16f876a	
	#include	<p16f876a.inc>	
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & 
             _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_ON & 
             _CPD_OFF

		cblock	0x20	
			CounterA
			CounterB
			CounterC	
		endc

Loop	
	movlw	0xff
	movwf	PORTC	
	movwf	PORTB
	call	Delay			
	movlw	0xff
	movwf	PORTC
	movwf	PORTB			
	call	Delay
	goto	Loop			

Delay	
	movlw	D'6'
	movwf	CounterC
	movlw	D'24'
	movwf	CounterB
	movlw	D'168'
	movwf	CounterA
loop	
	decfsz	CounterA,1
	goto	loop
	decfsz	CounterB,1
	goto	loop
	decfsz	CounterC,1
	goto	loop
	retlw	0x00


	END

Thanks
 
Last edited:
hi,
Look at what you are loading the PORTs with.!
Code:
Loop	
	movlw	[B]0xff[/B][COLOR="Red"] [B] ON[/B][/COLOR]
	movwf	PORTC	
	movwf	PORTB
	call	Delay			
	movlw	[B]0xff[/B][COLOR="Red"] [B]ON[/B][/COLOR]
	movwf	PORTC
	movwf	PORTB			
	call	Delay
	goto	Loop
 
Thanks for your usual fast response Eric. Yes you are right, I tried to make them constantly ON to avoid Oscillation calculation, but still non of the LED's is ON in both PORTS. I even measured the pin with my DMM to isolate the LED's board doubts.
 
MCLR (pin 1) pulled high? external oscillator hooked up (correctly pins 9 and 10 with caps)? Power applied to PIC (pin 20)? Ground applied to PIC?
Sorry, just making sure the hardware is correct as well :)
 
Thanks for your usual fast response Eric. Yes you are right, I tried to make them constantly ON to avoid Oscillation calculation, but still non of the LED's is ON in both PORTS. I even measured the pin with my DMM to isolate the LED's board doubts.

hi,
Try this it runs OK in simulation.
You had not set the PORT's state, also always set an origin

Code:
	list		p=16f876a	
	#include	<p16f876a.inc>	
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

		cblock	0x20	
			CounterA
			CounterB
			CounterC	
		endc

	org 0x0000
	goto main
	org 0x0004
	retfie

main:
	bsf STATUS, RP0
	movlw 0x0
	movwf PORTB
	movwf PORTC
	bcf STATUS, RP0

Loop	
	movlw	0xff
	movwf	PORTC	
	movwf	PORTB
	call	Delay			
	movlw	0x00
	movwf	PORTC
	movwf	PORTB			
	call	Delay
	goto	Loop			

Delay	
	movlw	D'6'
	movwf	CounterC
	movlw	D'24'
	movwf	CounterB
	movlw	D'168'
	movwf	CounterA
loop	
	decfsz	CounterA,1
	goto	loop
	decfsz	CounterB,1
	goto	loop
	decfsz	CounterC,1
	goto	loop
	retlw	0x00


	END
 
Last edited:
MCLR (pin 1) pulled high? external oscillator hooked up (correctly pins 9 and 10 with caps)? Power applied to PIC (pin 20)? Ground applied to PIC?
Sorry, just making sure the hardware is correct as well :)

You have a point, This is the first time I'm using the board I soldered according to Nigle's design. I've double checked all these points and no light. Thanks :)
 
Hi Eric,

Still no progress, I'll check my circuit again and try this code.

Thanks again, I'll try it and let you know soon.
 
hah, I put this into MPLAB to test and pasted my default code at the top of setting TRIS etc, so didn't even notice this missing!
 
You need to load TRIS registers first which makes the direction of PIC pins.

hi Gayan.
I have placed the TRISx statements in the corrected listing I posted, it works just fine in Oshonsoft.

Hope you are keeping well.:)
 
It is working fine. Thanks for all and many more for Eric. :)
 
I'll forward one more step. Now I want to set Port C as input and B as output ( as it is ). I made a small modification to Eric's code as follows:

Code:
MAIN:
	bsf STATUS,RP0
		movlw 0x0
		movwf PORTB

		movlw 0xff
		movwf PORTC
	bcf STATUS,RP0

Or it has to be like this
Code:
MAIN:
	bsf STATUS, RP0
	            movlw 0x0
	            movwf PORTB
	bcf STATUS, RP0

	bsf STATUS, RP0
	          movlw 0xff
	          movwf PORTC
	bcf STATUS, RP0
 
Last edited:
hi aljamri,
The 1st piece of code will do the job.
Code:
MAIN:
	bsf STATUS,RP0
		movlw 0x0
		movwf PORTB

		movlw 0xff
		movwf PORTC
	bcf STATUS,RP0
 
Status
Not open for further replies.

Latest threads

Back
Top