Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem with pic 16f84 code

Status
Not open for further replies.

mahesh.gsd

Newbie level 4
Joined
Apr 11, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,327
hai, i am new to pic 16f84, i program them with RC as a clock source,and i use mplab,recently i thought of using Xtal 4Mhz for flashing an led. but im not able to make it flash led, i have tried even simulating it in proteus, the problem persists, the problem that i see is either the led is turned on constanly or it doesnt glow at all. please help me.:cry:

below is the code that i tried to do it. i guess i have given enough delay, correct me if im wrong, and there are not warning errors, and im able to burn the flash with this program, but im not getting the output.
config bits clk - xt, put - on, code protect - off and wdt - off

list p=PIC16F84A
include <P16F84A.INC>

TIME1 EQU 10H
TIME2 EQU 11H

BSF STATUS,5
MOVLW 00H
MOVWF TRISA
BCF STATUS,5

RUN
MOVLW b'00001'
MOVWF PORTA
CALL DELAY
MOVLW b'00000'
MOVWF PORTA
CALL DELAY
GOTO RUN

DELAY
MOVLW 0FFH
MOVWF TIME1
LOOP1
DECFSZ TIME1,1
MOVLW 0FFH
MOVWF TIME2
LOOP2
DECFSZ TIME2,1
GOTO LOOP2
GOTO LOOP1
RETURN
END
 

Your delay code looks strange. I don't see an exit condition. Use an automatic delay code generator, like this one.
 
  • Like
Reactions: Raza

    Raza

    Points: 2
    Helpful Answer Positive Rating
Ok, thanks a lot, but what about the configuration bits, is it all right?? and about the problem with pic:|

Added after 17 minutes:

i appreciate very much for the help. but im sorry i still have the problem with that, i tried simulating it, the led is on continuously. and my code looks like this .thank you

list p=PIC16F84A
include <P16F84A.INC>

cblock
d1
d2
d3
endc

BSF STATUS,5
MOVLW 00H ; and set up
MOVWF TRISA
BCF STATUS,5
RUN
MOVLW b'00001'
MOVWF PORTA
CALL DELAY
MOVLW b'00000'
MOVWF PORTA
CALL DELAY
GOTO RUN

movlw 0x03
movwf d1
movlw 0x18
movwf d2
movlw 0x02
movwf d3
DELAY
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY

goto $+1
goto $+1
goto $+1

END
 

Your delay code is still wrong. You are setting the loop counters at outside of the DELAY block, so these 6 lines are never executed.

For 1 second delay, the calculator gives this code:
Code:
DELAY
			;999990 cycles
	movlw	0x07
	movwf	d1
	movlw	0x2F
	movwf	d2
	movlw	0x03
	movwf	d3
DELAY_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	DELAY_0

			;6 cycles
	goto	$+1
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return
Just paste it to the end of your code (replace with the old one).
 

sorry... its still doesnt work, i will post the circuit diagram... please check whether it has got any problem in it.
 

Hi,

Have not looked at your code only your circuit.

Try this design.

The diodes serve two functions - 1. it stops the battery from being connected the wrong way round and 2. it drops the 6v to 5.4v.
As this is still on the high side I would add the second diode which will reduce it to about 4.7v - the pic16f84 is designed to run at a nominal 5v.

The led must have a current limiting resistor around 330R should be ok.

Mlcr is best 'pulled up' a 10k resistor.

Not shown in your diagram are the pics supply connections which should have a 100nf cap across them as close to the pic pins as possible to reduce interference.
 

thanks a lot wp100, i will try that schematic and will get back to you shortly, and i have given the complete code in the same above discussion, if you dont mind you can have a look at it, and correct me if im wrong. thanks a lot again.

Added after 7 minutes:

i tried it with that circuit, im still stuck in the same problem, the LED is turned on continuosly. no flashing effect is seen. thanks
 

mahesh.gsd said:
thanks a lot wp100, i will try that schematic and will get back to you shortly, and i have given the complete code in the same above discussion, if you dont mind you can have a look at it, and correct me if im wrong. thanks a lot again.

Added after 7 minutes:

i tried it with that circuit, im still stuck in the same problem, the LED is turned on continuosly. no flashing effect is seen. thanks

From all the previous post I have created this listing and tested it on Proteus.
Some points:
- the cblock needs a starting address. 0x0c is the start of the General Purpose Register (GPR)
- the config switches can be set by __CONFIG
- the circuit above works fine.

list p=PIC16F84A
include <P16F84A.INC>
__CONFIG 11h


cblock 0x0c
d1
d2
d3
endc


ORG 0000h
BSF STATUS,5
MOVLW 00H ; and set up
MOVWF TRISA
BCF STATUS,5
RUN
MOVLW b'00001'
MOVWF PORTA
CALL DELAY
MOVLW b'00000'
MOVWF PORTA
CALL DELAY
GOTO RUN



DELAY
;999990 cycles
movlw 0x07
movwf d1
movlw 0x2F
movwf d2
movlw 0x03
movwf d3
DELAY_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto DELAY_0

;6 cycles
goto $+1
goto $+1
goto $+1

;4 cycles (including call)
return


END
 

    mahesh.gsd

    Points: 2
    Helpful Answer Positive Rating
thanks a lot dingo, its working fine thank you a lot, you made my day.
i still have a small doubt, please can you clarify it, could you explain how really does the delay work , i mean your understanding of the code thats there in delay, and why is it needed a starting address for it.
 

The delay is simply what is called a nested loop.
There are many ways to implement this but the code shown is very compact.

you should be able to follow the sequence if you know what the commands do
decfsz d1, f ; decrements memory postion d1 and puts the result into d1
; if the result is not zero then the next command ia initiated
; if the result is zero the the next command is jumped.
goto $+2 ;$ is the program counter so $+2 is a simple jump over the next decfsz
The start position for the cblock sets the first of the general purpose register.
Without this then d1 would point at address 0x00 which is the indirect address register.
Code start position is always 0x0000

For further info look up the datasheets at microchip.com
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top