Using the C-compiler for Holtek MCUs
Using the C-compiler for Holtek MCUs
D/N:HA0046E
Introduction
Regarding HT-IDE3000 editing, all of the HT-IDE2000 functions are included. However it
is important to note that some of the HT-IDE2000 functions, such as peek PX etc, have
already been replaced by different style function. If it is necessary to transfer a program
then some modification will be necessary.
The objective here is to inform the user, when realising certain functions using mixed
language, how to realise them in Holtek C. Also to help the user when using both how to
discriminate and about their limitations. For more details consult the HT-IDE3000 User’s
Guide.
1
Using the C-compiler for Holtek MCUs
The I/O ports can be directly read and written using C. At the beginning of the program,
an include statement must be provided for the corresponding MCU as shown below:
#include ″ht48r70a-1.h″
…
main(){
…
_pa=_pb=_pc=0; //clear PA,PB,PC to 0
_pac=_pbc=_pcc=0; //setup PA,PB,PC as outputs
…
}
→ Table Control
• Construct a Table
const var-type name[num]={date0, data1, data2,…}
The ability to create data tables in an indidpensable feature of any programming
language, and enables data to be placed into Program Memory spaced and retrieved
by the program. In C, const is used to define a constant, at the same time is placed in
the Program Memory space. Therefore a constant statement has been defined, which
will write a series of indicated values into the Program Memory.
“var-type” is a constant type, and can be an integer or character; “name” is the constant
statement name; “num” is the statement size; “data0, data1, data2” is the constant
statement contents, and table contents. “data0, data1, data2” can be a byte or a word.
− Example1
const long array[3]={0x1234,0x5678,0xabcd};
long temp;
main(){
temp=array[0]; //temp=0x1234
}
− Example2
const char array[2]={′a′, ′b′};
long temp;
main(){
temp=array[1]; //temp=′a′,a character is 61h
}
2
Using the C-compiler for Holtek MCUs
This will generate a table. It is worth noting that each table size must be less than 256
bytes, if the table size exceeds this range, errors will be created.
3
Using the C-compiler for Holtek MCUs
void timer_i1(){
}
//MAIN program
void main(){
_clrwdt();
_intc=00;
_tmr0c=0x87;
_tmr0=0xe1;
_pac=_pbc=00; //setup PA, PB as outputs
light0=0x80;
light1=0x00;
_et0i=1; //enable interrupt
_emi=1;
_te=1;
while (1)
{_clrwdt();
_pa=light0; //PA, PB ouput
_pb=light1;
}
}