Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] PIC10F202- Bit toggling confusion

Status
Not open for further replies.

NallS

Newbie
Joined
Mar 10, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
1615428444333.png

This piece of code sets the state of GP1 as the state of GP0. Using the stimulus Debug tool I can toggle the state of GP0 to make GP1 follow the state change. My issue is figuring out how to make GP1 only change state when GP0 goes from high-to-low. There is no bit toggle instruction for this PIC10F202 so I've tried using the COMF instruction but that just flips the byte not a single chosen bit. I've also tried to use BSF and BCF in multiple different ways to manipulate each single bit value but they don't work when I feed the 00000001 value to the WREG before the TRIS GPIO line, after removing this is was able to manipulate the bit of GP0 with BSF/BCF. What I want find out is:
1)Why when I use TRIS, after giving that binary value to the WREG to set the bits, am I not able to use BCF/BSF on GP0 to change its state?- (I think this has something to do with Tristate and High Impedance but this is all new to me)
2) If that isn't issue being in my code then how do I go about manipulating the bit belonging to GP1 to toggle only when GP0 goes from 1 to 0 state?
 

Hi,

These are very basic questions.
Each of them probably is already answered many thousand times in the internet.
You need to learn to
* do useful internet search,
* read documentation
* read through code examples
* view video tutorials
* and so on
...to find informations and solutions on your own, since a forum can't replace school.

And you need to learn good programming style.
In your current code the loop consists of 10 instructions, 50% of them is "goto".
Usually one wants to avoid "goto". One wants straight code (pieces, functions) from top to bottom. Unconditionsl branches.
(Conditional branches are only used where unavoidable, unconditional branches are allowed)

You currently do "conditional branching"
Instead consider to do:
* read input data (into registers, memory cells...)
* process the data (logically, mathematically...)
* output the processed data.

In your case: (pseudo code)
* declare some variables: current_state, previous_state, tmp_state, output_state ...
( for assembly this means: considervwhich registor (or memory cell) contains what informations
* read the pin state into current_state
* process it with the previous state into tmp_state
* process it further to get output_state (AND, OR, XOR, multiply, masking, shifting, inverting, ....)
* previous_state = current_state
* send output_state to the port
* restart the loop (unconditional branch)

Logic for detecting a rising edge is:
* Rising = current_state AND NOT previous state
In words: a rising edge is when it is currently HIGH AND it was NOT HIGH before
AND, OR reacts on HIGH. If you want to react on LOW you need to use NOT

Klaus
 

Hi,

These are very basic questions.
Each of them probably is already answered many thousand times in the internet.
You need to learn to
* do useful internet search,
* read documentation
* read through code examples
* view video tutorials
* and so on
...to find informations and solutions on your own, since a forum can't replace school.

And you need to learn good programming style.
In your current code the loop consists of 10 instructions, 50% of them is "goto".
Usually one wants to avoid "goto". One wants straight code (pieces, functions) from top to bottom. Unconditionsl branches.
(Conditional branches are only used where unavoidable, unconditional branches are allowed)

You currently do "conditional branching"
Instead consider to do:
* read input data (into registers, memory cells...)
* process the data (logically, mathematically...)
* output the processed data.

In your case: (pseudo code)
* declare some variables: current_state, previous_state, tmp_state, output_state ...
( for assembly this means: considervwhich registor (or memory cell) contains what informations
* read the pin state into current_state
* process it with the previous state into tmp_state
* process it further to get output_state (AND, OR, XOR, multiply, masking, shifting, inverting, ....)
* previous_state = current_state
* send output_state to the port
* restart the loop (unconditional branch)

Logic for detecting a rising edge is:
* Rising = current_state AND NOT previous state
In words: a rising edge is when it is currently HIGH AND it was NOT HIGH before
AND, OR reacts on HIGH. If you want to react on LOW you need to use NOT

Klaus
A forum obviously doesn’t replace school but I went to the internet to find my answer. After googling multiple times I can’t come across any PIC10 examples of toggling a single bit, youtube has nothing to offer either- it’s around 3am and I couldn’t contact a lecturer since they are obviously asleep, I can’t even go into university since covid restrictions are still in place. I didn’t realise this was a place “basic questions”couldn’t be asked? Everybody starts somewhere Klaus this is my first time even dealing with PIC Assembly language- I didn’t even write this code it’s the example given to me to modify as an exercise so next time could you lower the scrutiny in your explaining. Thank you nonetheless.
 

It is easy to think of TRIS as "TRI-State" but is actually just enables or disables the output driver behind the pin. Any bit set to '1' has it's driver disabled so the pin can only be used as an input and driving it high or low with BSF or BCF will have no effect.

To check if a bit has changed state you need to record what it is so you can look for it being different. Load the recorded value in W then XORWF with the port contents. Any bits set to '1' will have changed since the last check, you can then check if GPIO,0 is low, if it is, you have detected it changing from the only other possible state '1'.

Brian.
 
Hi,

Use the internet.
A simple "pic10 assembly tutorial" gives more than enough results.
Many videos. From the microchip and many others.
It's unavoidable to spend some time to learn.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top