BSF command will not work as it should HELP

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
User avatar
chloe4479
Posts: 19
Joined: Fri Jan 06, 2017 4:19 pm
Has thanked: 10 times
Been thanked: 5 times
Contact:

BSF command will not work as it should HELP

Post by chloe4479 »

with a great deal of help from Martin medelec35

we have come stuck on a simple command that is not doing what it should, so im asking if anyone else could shed some light on to this for me please

I using the EB006v9 board with the pic16f1937 that come with it
uisng pic basic assembly NOT FLOWCODE

I have a program that lights up portb leds in order from portb 0 to 7 then repeats.

It's meant to light them up in order and keep the last led lit showing all 8 lights lit at the end then repeat all over again

The program is very simple just using the bsf command, However when we run the program on the board, the port b led comes on 1 by 1, like the knight rider, however portb 0 comes on then portb 1 comes on but turns off portb 0 led this should not be happening

why are the led's turning off during the sequence??

See attached e03 v2 asm

I then modified the program completely removing the bsf command And instead added the Movlw command Now the program does what it should do,

Attached is the sequence asm file

My question is why is the simple bsf command not doing what it should The leds are turning off by themselves, there is no bcf command We are at a loss. Please help

chloe
Attachments
E03 V2.HEX
(408 Bytes) Downloaded 404 times
sequence.ASM
(2.48 KiB) Downloaded 432 times
E03 V2.asm
(2.07 KiB) Downloaded 443 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: BSF command will not work as it should HELP

Post by kersing »

You are directly writing to the output port, however you should be writing to the LATCH for the port. (LATB in your case), check this document for an explanation. (A led connected to a pin will drain a charge rapidly)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
chloe4479
Posts: 19
Joined: Fri Jan 06, 2017 4:19 pm
Has thanked: 10 times
Been thanked: 5 times
Contact:

Re: BSF command will not work as it should HELP

Post by chloe4479 »

Hi kerbing

Could u please show me the code I need to enter please
I am a beginner to this,
And that would help a great deal

Thanks

Chloe

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: BSF command will not work as it should HELP

Post by kersing »

LATB is at the same memory position PORTB is at, only in bank 2. So you need to add

Code: Select all

#DEFINE   PAGE2  MOVLB 2
next to the other definitions and where you use bsf you need to add PAGE2 before it and PAGE0 after. Or consider moving COUNT to page 2 memory location 20 as well so you can switch to page 2 at the start of the code and stay at that page (after initializing the clock etc)
To get the addresses for registers you can check the data sheet of the micro controller. Page 31 lists all registers.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
chloe4479
Posts: 19
Joined: Fri Jan 06, 2017 4:19 pm
Has thanked: 10 times
Been thanked: 5 times
Contact:

Re: BSF command will not work as it should HELP

Post by chloe4479 »

hi C.S. Lewis

Thanks so much for that info and that documentation

yes that should be available in all tutorials, i think matrix should give this out with every board, very useful information inded

I have the project now working using the LATB register, something i did not even know about or how to use, so thanks
the good thing with forums is you learn alot.

the pic16f1987 is new to me, i am a beginner, and its fun making mistakes to learn what went wrong but frustrating too

Thanks
Chloe

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: BSF command will not work as it should HELP

Post by Steve »

Please see here for an update to this issue:

http://www.matrixtsl.com/mmforums/viewt ... 165#p79165

Post Reply