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.

Problem in LED Flasher in pic 16F877A

Status
Not open for further replies.

rakan

New Member
Hello Guyz,

I am a newcomer to this forum and i have been looking for such a great forum for a while.

I am also a newcomer to the Microcontroller programming stuff and robotics.

Been trying to make a LED flasher in PIC16F877A but unfortunatly things not working have made me hate the electronics stuff.

Here is the schematics:
**broken link removed**

Code:
Code:
;header for 16F877

;Equates section
	TMR0		EQU	1
	OPTION_R	EQU	1
	PORTA		EQU	5
	PORTB		EQU	6
	PORTC		EQU	7
	TRISA		EQU 5
	TRISB		EQU	6
	TRISC		EQU	7
	STATUS		EQU	3
	ZEROBIT		EQU	2
	CARRY		EQU	0
	EEADR		EQU	0DH
	EEDATA		EQU	0CH
	EECON1		EQU	0CH
	EECON2		EQU	0DH
	RD			EQU	0
	WR			EQU	1
	WREN		EQU	2
	ADCON0		EQU	1FH
	ADCON1		EQU 1FH
	ADRES		EQU	1EH
	GHS0		EQU	3
	GODONE		EQU	2
	COUNT		EQU	20H
;*******************************************
	LIST 	P=16F877
	ORG		0
	GOTO	START
;********************************************

;CONFIGURATION BITS
;	_CONFIG	H'3FF0'
;********************************************
;1 SECOND DELAY
DELAY1	CLRF	TMR0
LOOPA	MOVF	TMR0,W
		SUBLW	.32
		BTFSS	STATUS,ZEROBIT
		GOTO	LOOPA
		RETLW	0

;0.5 DELAY
DELAYP5	CLRF	TMR0
LOOPB	MOVF	TMR0,W
		SUBLW	.16
		BTFSS	STATUS,ZEROBIT
		GOTO	LOOPB
		RETLW	0
;********************************************

START	BSF		STATUS,5
		MOVLW	B'11111111'
		MOVWF	TRISA
		
		MOVLW	B'00000000'
		MOVWF	TRISB
		
		MOVLW	B'11111111'
		MOVWF	TRISC
		
		MOVLW	B'00000111'
		MOVWF	OPTION_R
	
		MOVLW	B'00000000'
		MOVWF	ADCON1
		BSF		STATUS,6
		BCF		EECON1,7	
		BCF		STATUS,5
		BCF		STATUS,6
		BSF		ADCON0,0
		CLRF	PORTA
		CLRF 	PORTB
		CLRF	PORTC
;***************************************************

; program starts here

BEGIN	BSF		PORTB,1
		CALL	DELAYP5
		BCF		PORTB,1
		CALL 	DELAYP5
		GOTO	BEGIN
END
;************************************************

I dont really know but when i supply 12V to the power regulator it outputs more or less 5V and these are supplied to both VDD pis and MCLR. I am using port RB1 to get output to led but it's not doing anything.

Can you help me get over this problem?

regards,
Rakan
 
Assuming you're showing all the components?, your regulator isn't likely to work correctly as you've left off the capacitors essential for it's operation.

I suggest you try looking at my tutorials, which give the correct circuits, and example software. You should also use the supplied MicroChip equates file, rather than defining your own.
 
CONFIG word

I think there shall be double underbar (two underbars) and no semicolon before __CONFIG
 
A few things you need to check are:

The config command is commented-out so you either need to set the config in your programmer to enable the XT crystal resonator or use the __CONFIG command (two underscores as mentioned by OY2L)

Your diagram shows the led connected to portB,0 but your program is using portB,1.

You are making the program far to complicated at this stage by trying to make a delay with TMR0 - you have not initialized it either.
I suggest you just get it working with a simple delay loop to begin with then try using timers later. You can automatically generate the delay loop code using an excellent utility at:

Also, I suggest you have a look at using an include file for all of the main equates as it saves you having to have them all in your actual program.
eg. #include <p16f877A.inc>
(the include files for each microcontroller can usually be found in
"C:\Program Files\Microchip\MPASM Suite" )
 
Thanks alot guys, I got it fixed. I think the problem was in the equates code which i copied from the book i am reading. But it looks like i should have used the ready code from microchip for that specific PIC.


I tried it on a pic16F84A and it worked fine but when i connected a push button and pushed the button a couple of times the PIC stopped working and i think it wont work any more because it doesnt give a successfull verify in the programming phase. What could be wrong? is it because there are no capacitors in that circuit?
 
rakan said:
but when i connected a push button and pushed the button a couple of times the PIC stopped working and i think it wont work any more because it doesnt give a successfull verify in the programming phase. What could be wrong? is it because there are no capacitors in that circuit?

I had a problem like this lastnight. Are you trying to program it with the switch hooked up?

read the last few posts in my topic here-
https://www.electro-tech-online.com/threads/question-about-mplab-and-pics.28685/
 
rakan said:
I tried it on a pic16F84A and it worked fine but when i connected a push button and pushed the button a couple of times the PIC stopped working and i think it wont work any more because it doesnt give a successfull verify in the programming phase. What could be wrong? is it because there are no capacitors in that circuit?
You must Debounce the Button.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top