![]() |
Forum Index : Microcontroller and PC projects : 'flags' in interrupt routine
![]() ![]() |
|||||
Author | Message | ||||
PhenixRising Guru ![]() Joined: 07/11/2023 Location: United KingdomPosts: 1139 |
if pin(gp0) then ![]() |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4854 |
Even better... . PicomiteVGA PETSCII ROBOTS |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2139 |
arghh!!! it burns! IT BURNS!!! ![]() Quite right, single variables will be faster, but the SET/RESET subs only take around 300uS on a 48MHz Micromite (further optimisations are available at the expense of legibility) and I really hate wasting 8 bytes to represent a bit and all the extra variables... if MMBasic had a Bit (or even Byte) datatype these routines would likely not exist. my firmly entrenched miserness (years of assembler). It's also nice to be able to see the all the flags using BIN$(flags,64). I guess personal preferences are playing here - I like to see stuff like Every 47,DuskDawnTimer FlagSet DuskDawnTimer Every 60,PipeTempTimer ... If FlagTest(PipeTempTimer) Then FlagRes PipeTempTimer PipeTemp=Fix(Tempr(TempSense)) If FlagTest(HeaterForce) ... in my progs... which are derivations of the Z80 BIT,SET & RES mnemonics... but I felt going full 8-bit on them is a step too-far - maybe a questionable decision the version of MMBasic I use (MicroMites) doesn't have INV(), the FotS article does show a version at the bottom that uses INV. Edited 2025-03-06 21:03 by CaptainBoing |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Unless you're going to be doing something else with pin(gp0) inside the IF statement--like save the state value of the pin. It may have changed by the time you say "pin0State%=pin(pgo)"; better to be able to say "pin0State%=a%" and then deal with any new change the next time you check pin(gp0). This probably implies that your IF statement is going to be "if pin0State%<>a%". ~ Edited 2025-03-07 03:31 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
58kk90 Regular Member ![]() Joined: 14/06/2023 Location: United KingdomPosts: 59 |
I am really grateful for the guidance given, and thought I had decided on using one integer per flag, but I do like the @CaptainBoing idea as it is similar to what I have always done in the 8048 / 8051 / arduino / Pic days where a single bit of a byte represented a particular flag so I decided to give that a try. Seting and clearing the bit work fine, but I cannot get the 'Test a flag' function to work. Most likely it's due to my limited knowledge, but I cannot see what the issue is Dim Flags as integer Flags = 1 ' set a bit for testing do if FlagTest(0) = 0 then print "bit is 0" loop End Function FlagTest(b As Integer) FlagTest=Abs(Sgn(Flags And (&o1<<b))) End Function When I try and run this I get [12] If FlagTest(0) = 0 Then Print "bit is 0" "Error : Variable type not specified" I am using PicoMite MMBasic Version 6.00.00b4 Any suggestions please. Tony |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6219 |
My guess is that you have option default none set If so, you have to give the function a type. Jim VK7JH MMedit |
||||
58kk90 Regular Member ![]() Joined: 14/06/2023 Location: United KingdomPosts: 59 |
Jim, you are correct I do have Option default none set. How do I give the function a type? I have defined b as integer Tony |
||||
58kk90 Regular Member ![]() Joined: 14/06/2023 Location: United KingdomPosts: 59 |
Cancel the last, I have figured that i've done :- Function FlagTest(b As Integer) as integer Now it works :-) Tony Edited 2025-03-08 18:12 by 58kk90 |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |