Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 4th April 2007, 10:49 AM   (permalink)
Default Problem in LED Flasher in pic 16F877A

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:


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
rakan is offline  
Old 4th April 2007, 11:40 AM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 4th April 2007, 10:18 PM   (permalink)
Default CONFIG word

I think there shall be double underbar (two underbars) and no semicolon before __CONFIG
OY2L is offline  
Old 4th April 2007, 11:31 PM   (permalink)
Default

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: http://www.piclist.com/techref/picli...egen/delay.htm

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" )
picasm is offline  
Old 5th April 2007, 08:41 PM   (permalink)
Default

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 is offline  
Old 5th April 2007, 09:02 PM   (permalink)
Default

Quote:
Originally Posted by rakan
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-
http://www.electro-tech-online.com/m...plab-pics.html
Andy1845c is online now  
Old 7th April 2007, 11:45 AM   (permalink)
Default

Quote:
Originally Posted by rakan
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.
__________________
Gayan

My Website
http://gsmicro.blogspot.com/
Gayan Soyza is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
LED Pilot Light Problem Jim Niemeyer Electronic Projects Design/Ideas/Reviews 7 18th February 2007 12:44 AM
PIC Transistor LED PeterDove Micro Controllers 30 9th February 2007 09:48 PM
PIC 16F628A UART Coding Problem Gayan Soyza Micro Controllers 11 1st February 2007 12:59 PM
PIC 16F877A - Problem with A/D conversion disco_dave Micro Controllers 11 17th February 2006 03:54 AM
Newcomers, please read! (PIC regarded) Upd. 0xD Jay.slovak Micro Controllers 0 17th April 2005 02:05 PM



All times are GMT. The time now is 09:42 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker