# Problem with PIC16f84 as it always outputs from ports logic1

Status
Not open for further replies.

#### asic1984

##### Full Member level 5
pic16f84 problem?

hi

i have a problem with pic16f84 ...whatever program i write on it ...it always output from the ports logic 1

example: i tried this example
https://www.geocities.com/tjacodesign/picprogmanual/picprogmanual.html

with the code :
Code:
;ledsrun.asm
;example program with PIC16F84 µcontroller
;connect four leds with a 470 ohm series resistor to RB0 TO 3
;and a 10k / 27pF RC-oscillator
;the LEDS will light up as a running light
;written in MPASM MICROCHIP assembler
;****set up constans and variables****
INCLUDE "P16F84.INC" 			;look up file for MPASM
LIST	P=16F84
ERRORLEVEL      -302    		;SUPPRESS BANK SELECTION MESSAGES
__config  _RC_OSC&_PWRTE_ON & _WDT_OFF	;RC oscillator, power on timer
;and watchdog timer off

status	equ	h'03'		;status register
trisb	equ	h'86'		;set up register for port B
trisa	equ	h'85'		;set up register for port B
count1	equ	h'0e'		;general purpose register
count2	equ	h'0f'		;general purpose register
leds	equ	h'06'		;portB is 7seg display content
porta	equ	h'05'		;portA is not used

;****set up portA and portB****
bsf	status,5	;switch to bank1 to set up ports
movlw	h'00'
movwf	trisb		;portB is all output
movlw	h'00'
movwf	trisa		;portA is all output
bcf	status,5	;switch back to bank0 to use ports

;****main program****
start	movlw	b'00000001'	;load pattern into W
movwf	leds		;load W into portB (switch on rightmost LED)
call	delay		;wait for some time
movlw	b'00000010'	;new pattern
movwf	leds
call	delay		;wait
movlw	b'00000100'	;new pattern
movwf	leds		;
call	delay		;wait
movlw	b'00001000'	;new pattern
movwf	leds		;
call	delay		;wait
goto	start		;do it all over again
;****delay subroutine****
;****delay = wait (delay count value 1) x (delay count value 2) cycles****
delay	movlw	h'EE'		;setup delay count value 1
movwf	count1		;count1 is slow counter
loop1	decfsz	count1,1	;
goto	label		;still > 0
return			;count1 < 0 so get out of the delay loop
label	movlw	h'EE'		;setup delay count value 2
movwf	count2		;count2 is fast counter inside count1 loop
loop2	decfsz	count2,1	;
goto	loop2		;still > 0 so stay in loop2
goto	loop1		;count1 < 0 go to loop1
end;

pins 0,1,2,3 should light on and off.............but it always on

i tried many examples but same problem.........even i change the pic........knowing that ic-prog is writting and verifying that code is ok

thanks for help

#### sanjay

##### Full Member level 1
pic16f84 problem?

I think, the code looks okay, so does the register initialisation, Are you sure your delay is long enough, what I mean is that if your delay is small, then you won't notice the switching off of LEDS, as it would go very fast, maybe you can try expanding the time duration of your delay and then try out.

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

i tried before to make the delay for 4 seconds and same problem

thanks for help

#### C-Man

Re: pic16f84 problem?

Hi asic1984

I also can not see any problem with your code.

If you own an oscilloscope you could take a look at pin 15 (osc2) you should see a rectangle with about 1MHz.

Where do the 5V you are using come from?

If your 5V is rising slowly it could be possible that the 16F84 does not get a proper reset signal. You could try to connect the /MCLR (pin4) with a 10 K pullup to +5V and use a pushbutton connected to /MCRL and GND to genarate a reset signal.

hope this helps and best regards

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

thanks too much C-man for your help.....but i already do that ........and i have same strange problem

i wanna ask is that possible that pic be burned by some how and the ic-prog verifying the memory only!!!!

thanks too much

#### C-Man

Re: pic16f84 problem?

asic1984 said:
hi

thanks too much C-man for your help.....but i already do that ........and i have same strange problem

i wanna ask is that possible that pic be burned by some how and the ic-prog verifying the memory only!!!!

thanks too much

Yes could also be a problem with your programmer.

I am using a commercial one but there have been many posts here about working self built programmers just do a search. I think Fragrance has posted everything you need to program different PIC models.

Also check the PIC's fuse settings in your programmer maybe the fuses are not set correctly when you load and program your hexfile?

best regards

#### enigma460

##### Member level 4
Re: pic16f84 problem?

Ran the Program on a simulator and it works fine.

You may want to load the program from disk into IC-Prog Buffer 1, then

read the 16F84 into Buffer 2. Then compare the results. This will tell you if the PIC

programmed correctly.

The only other thing might be a bad Chip?

Good Luck

Enigma460

#### VVV

Re: pic16f84 problem?

If your circuit is built correctly it should work, I do not see any problem.
The port pins might be damaged, though.

To test that, disconnect the /MCLR pin from +5V and connect it to GND, to force the part into reset. Now all the I/O pins should be inputs and the LED's should be off. If they do not go off, then the PIC is damaged (assuming, of course that all the wiring is correct).

Since the part programs and verifies correctly, at least pins RB6, RB7 are OK as inputs. You can try moving the LED's to pins RB4:RB7 and change the pattern you write to the port, to walk the 1 in positions 4:7.

Or, connect the LED's to port A, without changing the pattern, but writing it to PORTA (this is easier, you only need to change one equate: leds equ h'06').

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

thanks all for your help.....but i think that the pic16f84 is burned as it is now output nothing on porta and output very small voltage on portb

i tried to use pic16f877 by this simple code
Code:
          processor 16f877
#include <p16f877.inc>

org 0x00
goto start

org 0x06
start    bsf 03h,5         ;bank 1

movlw 0x00
movwf 86h         ;portb output
bcf 83h,5         ;bank 0
movlw 0xff
movwf PORTB

end

but nothing is working even that i check the connection many times and it is ok

so does this pic needs any other configurations or what ?

thanks for help

#### C-Man

Re: pic16f84 problem?

asic1984 said:
so does this pic needs any other configurations or what ?

Yes as I wrote above it is absolutely necessary that the fuse bits are set correct. Some programmers do not import the fuse bits and you will have to set them manually before burning your pic.

best regards

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

thansk too much C-man but can u give an example

if u mean by the fuse bits the seeting of watch dog timer and other options so i set them in the mplab and ic-prog

thanks for help

#### C-Man

Re: pic16f84 problem?

Yes that is exacly what I mean especially important is the clock, watchdog and power up timer setting.

If you do set these bits correctly and your project still does not work after burning the pic I have no more ideas what could be wrong sorry.

best wishes

#### VVV

Re: pic16f84 problem?

I am probably going to repeat myself, but did you try using other pins of ort B, or even port A? As I mentioned, RB6, RB7 are likely OK, since you can program the PIC.

If you remove the PIC and power the circuit, are the LED's off? If not, check wiring. If yes, see next.

If you force the PIC into reset are the LED's off? If not, PIC is bad. If they do go off, the PIC is not programmed correctly.

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

thanks all for help

i returned back to pic 16f84........it works again but in same problem all ports logic 1

for vvv: thanks for help first
i tried all the ports what is strange that all ports are giving logic 1
although i only use one port in my program

noting that when i make reset all ports are off ..........and that it is ok

and when i remove the pic and still powering the circuit the leds are off so no wrong connections

i will be crazy soon

:sm29:

thanks

#### enigma460

##### Member level 4
Re: pic16f84 problem?

Do you have another 16F84 to try?

See if you get the same results.

You might also want to put an amp meter in the supply circuit to see if you are pulling an abnormal current.

Did you verify that the device is actually getting programed?

Enigma460

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

will i have another pic16f84 and it is the same problem
and i verify that the pic is programmed by reading it is contents

#### VVV

Re: pic16f84 problem?

OK, so the PIC does not seem to be damaged. That is good news.

What I suspect now is that it does not get programmed with the correct data. I know verification says it's OK, but you know, garbage in, garbage out, yet it's the same garbage and checks OK.

So, here a few more questions:
1. Did you use this programmer before? Do you know for sure it works properly?
2. Are you selecting the correct device when you program it?
3. Are you sure you assembled the program and got no errors or warnings? Sometimes we ignore warnings, but that can be a big mistake. (I speak from experience).
4. Is there any way you keep loading the wrong .hex file? (Again, happened to me...)
5. Can you attach a copy of the .hex file?

That's it for now.

#### enigma460

##### Member level 4
Re: pic16f84 problem?

Ok You say you have compared the contents of the 16F84 with the hex file and it looks good.

I'd have to agree with VVV. Send us the hex file.

This is a strange one.

Enigma460

#### asic1984

##### Full Member level 5
Re: pic16f84 problem?

hi

here is the code:
Code:
        PROCESSOR 16f84
#include "p16f84a.inc"
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

org 0x00
goto start1
;*****Set up the Constants****
org 0x06

COUNT1 equ 0x09 ;First counter for our delay loops
COUNT2 equ 0x10 ;Second counter for our delay loops
Count3 equ 0x11

;****Set up the port****
start1       bsf STATUS,5 ;Switch to Bank 1
movlw 00h ;Set the Port A pins
movwf TRISA ;to output.
bcf STATUS,5 ;Switch back to Bank 0
;****Turn the LED on****
Start movlw 0xff ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then
;on the port
;****Start of the delay loop 1****
Loop1 decfsz COUNT1,1 ;Subtract 1 from 255
goto Loop1 ;If COUNT is zero, carry on.
decfsz COUNT2,1 ;Subtract 1 from 255
goto Loop1 ;Go back to the start of our loop.
decfsz Count3,1
goto Loop1

;This delay counts down from
;255 to zero, 255 times
;****Delay finished, now turn the LED off****
movlw 00h ;Turn the LED off by first putting
movwf PORTA ;it into the w register and then on
;the port
Loop2 decfsz COUNT1,1 ;This second loop keeps the
goto Loop2 ;LED turned off long enough for
decfsz COUNT2,1 ;us to see it turned off
goto Loop2 ;
decfsz Count3,1
goto Loop2

;****Now go back to the start of the program
goto Start ;go back to Start and turn LED
;on again
;****End of the program****
end ;Needed by some compilers,
;and also just in case we miss the goto instruction.

and i attach the hex file

thanks for your help too much

#### enigma460

##### Member level 4
Re: pic16f84 problem?

Hex file looks good. If this is the hex file you read back from the device then

this leads me to the only other option, The wiring is not correct???

You're sure that pin 1 is tied high through a 1k resister?

You're sure that the osc is working? Scope it.

Maybe send a clear close up picture of the circuit.

Sorry I'm at a dead end here.

Enigma460

Status
Not open for further replies.