I have some code that reads serial data into a byte, certain "bits" of the byte contain various status flags. I then refer to the status flags using SerialByte.0 SerialByte.1 and so on. It struck me that this might be more understandable if the "bits" could be assigned to a readable name.
I thought that Alias might be the command I should use but that seems to be for bytes rather than bits.
Is it possible to do this using something like dim?
Or #Define?
Is the sort of thing I was imagining would be a neater way to code, rather than just referring to SerialByte.x every time, or having to have "bit" variables and assigning the value each time SerialByte is updated.
;ProgramcompiledbyGCBASIC;Needhelp?;SeetheGCBASICforumsathttp://sourceforge.net/projects/gcbasic/forums,;CheckthedocumentationandHelpathttp://gcbasic.sourceforge.net/help/,;or,emailus:;w_cholmondeleyatusersdotsourceforgedotnet;evanvennnatusersdotsourceforgedotnet;********************************************************************************;Setuptheassembleroptions(Chiptype,clocksource,otherbitsandpieces)LISTp=16F1825,r=DEC#include<P16F1825.inc>__CONFIG_CONFIG1,_FCMEN_ON&_CLKOUTEN_OFF&_CPD_OFF&_CP_ON&_MCLRE_OFF&_WDTE_OFF&_FOSC_INTOSC__CONFIG_CONFIG2,_LVP_OFF&_PLLEN_OFF&_WRT_OFF;********************************************************************************;SetasidememorylocationsforvariablesSERIALBYTEEQU32;0x20;********************************************************************************;VectorsORG0pageselBASPROGRAMSTARTgotoBASPROGRAMSTARTORG4retfie;********************************************************************************;Startofprogrammemorypage0ORG5BASPROGRAMSTART;CallinitialisationroutinescallINITSYS;Startofthemainprogram;Readprotected;DimSerialByteAsByte;LetSerialByte=0clrfSERIALBYTE;DoSysDoLoop_S1;LetSerialByte=SerialByte+1incfSERIALBYTE,F;IfStatusReady=1ThenbtfscSERIALBYTE,0;LetStatusError=0bcfSERIALBYTE,1;EndIf;IfStatusError=1ThenbtfscSERIALBYTE,1;LetStatusMotor=0bcfSERIALBYTE,2;EndIf;IfStatusMotor=1ThenbtfscSERIALBYTE,2;LetStatusOkBut=0bcfSERIALBYTE,3;EndIf;IfStatusOkBut=1ThenbtfscSERIALBYTE,3;LetStatusUpBut=0bcfSERIALBYTE,4;EndIf;IfStatusUpBut=1ThenbtfscSERIALBYTE,4;LetStatusDnBut=0bcfSERIALBYTE,5;EndIf;IfStatusDnBut=1ThenbtfscSERIALBYTE,5;LetStatusLeBut=0bcfSERIALBYTE,6;EndIf;IfStatusLeBut=1ThenbtfscSERIALBYTE,6;LetStatusReady=0bcfSERIALBYTE,0;EndIf;LoopgotoSysDoLoop_S1SysDoLoop_E1BASPROGRAMENDsleepgotoBASPROGRAMEND;********************************************************************************;Source:system.h(174)INITSYS;asmshowdebugThiscodeblocksetstheinternaloscillatortoChipMHz;asmshowdebugOSCCONtypeis105'Bit(SPLLEN) Or Bit(IRCF3) And NoBit(INTSRC) and ifdef Bit(IRCF3);equatestoOSCCON=OSCCONANDb'10000111' & OSCCON = OSCCON OR b'11110000';=32Mhz;SetIRCF3OnbankselOSCCONbsfOSCCON,IRCF3;SetIRCF2OnbsfOSCCON,IRCF2;SetIRCF1OnbsfOSCCON,IRCF1;SetIRCF0OffbcfOSCCON,IRCF0;SetSPLLENOnbsfOSCCON,SPLLEN;asmshowdebug_Complete_the_chip_setup_of_BSR_ADCs_ANSEL_and_other_key_setup_registers_or_register_bits;EnsureallportsaresetfordigitalI/Oand,turnoffA/D;SETADFMOFFbcfADCON1,ADFM;SwitchoffA/DVar(ADCON0);SETADCON0.ADONOFFbcfADCON0,ADON;ANSELA=0bankselANSELAclrfANSELA;ANSELC=0clrfANSELC;SetcomparatorregisterbitsformanyMCUswithregisterCM2CON0;C2ON=0bankselCM2CON0bcfCM2CON0,C2ON;C1ON=0bcfCM1CON0,C1ON;;'Turn off all ports;PORTA=0bankselPORTAclrfPORTA;PORTC=0clrfPORTCreturn;********************************************************************************;Startofprogrammemorypage1ORG2048;Startofprogrammemorypage2ORG4096;Startofprogrammemorypage3ORG6144END
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is something that I've been thinking about for a while now. I finally got around to checking the help pages for 'Alias' this morning and realised that wasn't going to work for bits in the way I wanted.
As I was posting my question, I wondered if #Define might work. I thought it should. Gave it a try and hey presto.
Glad you like it and I'm pleased to have helped..
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have some code that reads serial data into a byte, certain "bits" of the byte contain various status flags. I then refer to the status flags using SerialByte.0 SerialByte.1 and so on. It struck me that this might be more understandable if the "bits" could be assigned to a readable name.
I thought that Alias might be the command I should use but that seems to be for bytes rather than bits.
Is it possible to do this using something like dim?
Or #Define?
Is the sort of thing I was imagining would be a neater way to code, rather than just referring to SerialByte.x every time, or having to have "bit" variables and assigning the value each time SerialByte is updated.
I think I've answered my own question.
This seems to work, and the status "bits" appear to reference "SerialByte.x" in the .asm file as I was hoping.
I realise the logic of the test program probably won't work, but I wanted to refer to all the variables, quickly.
This is genius!
I have often wanted use aliases with BITs but ALIASing BITs does not work. I guess is should.
Your method works.
I shall put into the Help NOW!!
See https://gcbasic.sourceforge.io/help/_dim.html
Thanks!
It is something that I've been thinking about for a while now. I finally got around to checking the help pages for 'Alias' this morning and realised that wasn't going to work for bits in the way I wanted.
As I was posting my question, I wondered if #Define might work. I thought it should. Gave it a try and hey presto.
Glad you like it and I'm pleased to have helped..