;timer on off control
AD_DIP equ 0x6 ;selects if DIP is read
;for input select (Bits 1
;and 2)
AD_JUS equ 0x7 ;set right if set
We could have easily kept the assembler syntax and
tested bits within the UF and CF SRAM locations. In that
case, we would use the CCS C compiler’s built-in functions
bit_clear, bit_set, and bit_test. For instance, here’s the C
code to set UF flag bit ADCR:
bit_set(UF,ADCR);
To test the ADCR bit, we use the built-in function
bit_test:
value = bit_test(UF,ADCR);
Clearing and setting the ADCR bit using assember looks
like this:
bcf
bsf
UF,ADCR
UF,ADCR
On the other hand, we can make the C source code a
bit easier to follow by rounding up all of the flag bits into
their respective UF and CF corrals using special C structures:
//User Flags
typedef struct{
int8 NU:1;
int8 DBu:1;
int8 TK:1;
int8 SW_CH:1;
int8 BCD0:1;
int8 BCD1:1;
int8 TPWM:1;
int8 ADCR:1;
}UFFLAGS;
//Control Flags
typedef struct{
int8 na:3;
int8 FQ:1;
int8 TRG:1;
int8 CNT_ON:1;
int8 AD_DIP:1;
int8 AD_JUS:1;
}CFFLAGS;
//debounce control buffer
//tick set from timer 0
//change in reed switch
//BCD Display Counter
//BCD Display Counter H
//Display and read dip
//switch off
//AD New Read
//used for FQ mode select
//trigger bit used to store
//last trigger
//counter on bit counter
//timer on off control
//selects if DIP is read
//for input select (Bits
//1 and 2)
//set right if set
Once the UF and CF structures are defined, we must
instantiate an instance of each of the structures before we
can use them. Here’s the code:
UFFLAGSUF;
CFFLAGSCF;
Now, using the CCS compiler, we can set, clear, and
test user and control flag bits like this:
UF.ADCR = 1;
CF.CNT_ON = 0;
//set ADCR bit
//clear CNT_ON bit
if(CF.AD_DIP == 1)
{
//do something here
}
Here are the last of the assembler equate statements in
the eMate.asm file we’ve been porting:
;***** Display Bit Def
SO0 equ 0x0
SO1 equ 0x1
SO2 equ 0x2
SO3 equ 0x5
SO_SEL equ 0x1
;******* COM PORT
SRX
equ
0x6
STX
equ
0x7
;******** Button Locations
But1 equ 0x2
But2 equ
But3 equ
But4 equ
0x3
0x4
0x0
; BCD bit 0 RC0
; BCD bit 1 RC1
; BCD bit 2 RC2
; BCD bit 3 RC5
; RB1 Control for
; DIP or display
; 1 = Display
; Display Select
; 0 RC6
; Display Select
; 1 RC7
; location of
; buttons on port b
I think you have an idea of what the equivalent C
source will look like:
// Display Bit Def
#define SO0 0x00
#define SO1 0x01
#define SO2 0x02
#define SO3 0x05
#define SO_SEL 0x01
//COM Port
#define SRX 0x06
#define STX 0x07
//Button Locations
#define But1 0x02
#define But2
#define But3
#define But4
0x03
0x04
0x00
//BCD bit 0 RC0
//BCD bit 1 RC1
//BCD bit 2 RC2
//BCD bit 3 RC5
//RB1 Control for DIP or
//Ddisplay 1 = Display
//Display Select 0 RC6
//display Select 1 RC7
//location of buttons on
//port b
What’s Next?
We’ve ported what I believe to be one of the most
important parts of any program — the initial definitions. The
next set of assembler code we will tackle is the application
setup portion of the eMate.asm file. The eM8 application is
made up of a number of peripheral-specific include files
which are called from eMate.asm. So, as we move through
the eMate.asm code, we’ll branch off and port dependent
peripheral-specific include files as we come to them. If there
is anything exciting we can do with our ported code and
the eM8 hardware along the way, you can count on us
getting out of the truck and walking down those trails. SV
Fred Eady can be reached via email at fred@edtp.com.
SERVO 11.2010 55