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.

ASM code working on PIC18 not working in PIC16

Status
Not open for further replies.

kyru27

New Member
I've had to adapt an asm code done in PIC18F to one done in PIC16F, theorically it shouldn't be anything more than putting the needed banksel references, but in practice I'm finding a strange problem:

This piece of code:

Code:
P1			BTFSC PORTA,4

			GOTO P1

P0			BTFSS PORTA,4

			GOTO P0

"More instructions"

GOTO P1

Works right on PIC18F, so when my button is pressed, and has been stopped being pressed before P0, I can execute "more instructions" but in PIC16F I can't get to them and when I press the button nothing happens, despite the high level going to RA4, moreover, something "funny" occurs, if I put a terminal of a wire in contact with RA4 without it being connected nowhere is starts executing the instructions until I put the terminal away from RA4, I don't know for what reason.

Any idea of what to do to make it work on PIC16F?
 
Last edited:
if I put a terminal of a wire in contact with RA4 without it being connected nowhere is starts executing the instructions for I don't know for what reason.
This may be because you are providing a nice aerial that will pick up 50 or 60Hz mains hum and provide it to a high impedance input. It is like pressing and releasing your button 50 or 60 times a second.

This may suggest that the problem is a hardware problem with your switch. Perhaps it is not providing a reliable 0V to Vcc swing.

Post your schematic, then we might spot the problem
 
Last edited:
RA4 is "open drain" in several (if not all) 16F micros.

Does it ring a bell?

Do you know that PC works basis a different length of words?

The way you comment this, suggests that you are not aware of ALL the differencies. Not a big deal in fact, but worth knowing them anyway.
 
It was just question of PIC16F being more sensitive (I mean needing more voltage on RA4) to work properly as my initial 5 V were a bit off at this point, but PIC18F didn't notice the difference.

Anyway, I'm into a new problem right now about adapting the code as on PIC16F as now it resets every few seconds with no apparent reason, which didn't happen on PIC18F.

It's not problem of MCLR as 4,87 V are sent there all the time, can't be that for 0,13 V is not working...

I guess it maybe has to do something with the oscillator used in PIC16F as in PIC18F I was using the INTIO67 mode which PIC16F doesn't seem to have as an internal oscillator mode, I used XT mode but the PIC didn't work at all on this mode, so tested it on RC mode where it "works" but continuoslly resets when I think it should work.


I'm uploading my schematic to check possible mistakes.

Oh well... I uploaded the one with XT instead of RC oscillator, but whatever, the only change is the one shown in extra.jpg

PD: I managed to do it also on XT according to the schematic, but still the same problem, so I guess it's not a fault from the oscillator.

PD2: There's a mistake on the schematic I'm using PIC18F877 not 887, although I don't think this would make a difference.
 
Last edited:
Yup... I ran into that one before.
Yes, I have been caught out the same way, but I would suggest that this is not relevant in this thread, since the OP is using RA4 for an INPUT :)

(Of course we have since found out, the OP is using a PIC without open drain RA4 anyway)
 
To find more infomation on the reset problem, change your code to just be an infinite loop that flashes an LED. If it still resets then it's hardware, if it doesn't then post your code as it's software.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top