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.
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
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
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
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
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