N
N
Nikita Silchenko2020-06-13 02:01:13
Electronics
Nikita Silchenko, 2020-06-13 02:01:13

How to pass variable to BSF/BCF commands?

I have the following task:
10) A line of LEDs (8 pcs.) Is connected to port D. A button is connected to port B. When the button is pressed, one light runs cyclically on the LEDs of port D. When the button is pressed again, two adjacent lights, etc. until the 8 LEDs are completely filled.

10.a After filling, with each press, the number of running lights decreases by 1.
----
Just before the session, I began to study this topic. I want to make a loop so that I have a variable that changes from 0 to 7 and from 7 to 0 (so that the light runs, as instructed). Spent, literally, the whole day on solving this simple problem. So I didn't decide. Ask for help from experts!
PS It will be nice if you help build the logic of the task itself as a whole, because after making the loop I have no idea what to do next, but if you tell me at least with a variable in these BSF / BCF - I will be very grateful!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-06-13
@jcmvbkbc

tell me at least with a variable in these BSF / BCF

You type in Google "pic datasheet", (if you know which PIC you have - specify, you will get a more relevant result) you get a link to the specification of a particular processor. You open it and look in the table of contents for the section "Instruction Set" or similar in meaning, in it you look for your instructions. If you do this, you will find the following text:
For bit-oriented instructions, ‘b’ represents a bit field designator
which selects the bit affected by the operation, while ‘f’ represents
the address of the file in which the bit is located.

and such a picture:
5ee43a094f624209976491.png
from which you can conclude that these instructions cannot change the bit by the number recorded in the variable, you can only explicitly indicate in the instruction the number of the bit that needs to be changed.
There are several ways to get out of the situation, the easiest in my opinion is to have a register in which a single bit is set, corresponding to the most significant bit that must be set in the set of lights (and the set is continuous, if I understood the task correctly). This bit can be moved by 1 left and right with the rlf/rrf instructions and the xorwf operation to add/remove from the set of lights.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question