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

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

Postby chloe4479 » Wed Jan 11, 2017 1:03 am

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
(422 Bytes) Downloaded 155 times
sequence.ASM
(2.59 KiB) Downloaded 172 times
E03 V2.asm
(2.18 KiB) Downloaded 183 times

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: BSF command will not work as it should HELP

Postby kersing » Wed Jan 11, 2017 1:50 am

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)
These users thanked the author kersing for the post:
medelec35 (Wed Jan 11, 2017 10:13 am)
Rating: 5.26%
 
“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

Postby chloe4479 » Wed Jan 11, 2017 2:30 am

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: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: BSF command will not work as it should HELP

Postby kersing » Wed Jan 11, 2017 9:55 am

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.
These users thanked the author kersing for the post (total 2):
medelec35 (Wed Jan 11, 2017 10:26 am) • chloe4479 (Wed Jan 11, 2017 10:40 am)
Rating: 10.53%
 
“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

Postby chloe4479 » Wed Jan 11, 2017 10:43 am

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: 3073
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 87 times
Been thanked: 387 times
Contact:

Re: BSF command will not work as it should HELP

Postby Steve » Wed Jan 11, 2017 12:35 pm