You are on page 1of 2

Next step is writing the program.

All the information about writing programs which include its


commands, operations and the microcontroller registers are available on the datasheet and Hi-
Tech Toolsuite guide. But I will also tr to ma!e ou understand the first steps so that the
datasheet and guide ma prove useful. "ou can start ma!ing our own programs at the end of
this tutorial.
Now let us view a program for #$%&''A where & ()* are connected at the +,-T B .& pins of
port B, from pin no //-012. This programs blin!s the ()*s which means the ()*s remain on for a
second and off for another second.
Hi-Tech 3 3ode
4include 5htc.h6
4define 78TA(7%-)9 &111111
void main.2
:
T-I;B<1811=
+,-TB<1811=
while.#2
:
+,-TB<18%%=
7dela7ms.#112=
+,-TB<1811=
7dela7ms.#112=
>
>
This is the core stle of writing the microcontroller program. As ou can see, the stle is
completel similar to that of the normal 3 programs. ?ust some additional !ewords here.
-emember that all the sntax and mathematical and logical operations supported b stdio and
conio libraries are accepted here in htc librar with some additional ones also.
In the first line, we start the program b including the librar. This step is nothing new.
Now we need to define the fre@uenc of oscillator used in the sstem. This is the stle of
defining the oscillator fre@uenc. The value &111111 means its fre@uenc is &AHB.
;tart of the main program code
T-I; is the command used for initialiBing the ports of the microcontroller. T-I;B is an & bit
register, in fact ever word written in capital represents a register inside the microcontroller and
ou can get all the information about the register in the datasheet. Csing this line will start the use
of +,-T B and if the value is D#E in the respective register bit, that pin will be made input and if the
value is D1E, the pin will be made output. ,ne more thing, the use of D1xE in that line represents that
we are giving the data in hexadecimal number sstem. "ou can use D1bE if ou wish to give the
data in binar and use nothing if ou use decimal number sstem. ;o this line ma!es each & lines
of port B output. ,ther wa to give the same command isF T-I;B<1= .decimal2 and
T-I;B<1b11111111= .binar2.
+,-TB is also a register li!e T-I;B. This register passes the value out of port B. This means
+,-TB<1x11 will give low output from each eight line of port B. This is e@uivalent to clearing of
port B at the start from an stra values. This line is not needed because there are no stra
values at the start.
;tart of while loop. Ge write the entire program inside the while loop. After all initialiBations
have been done, the main code is written here. This is done because this segment of program
has to repeat over and over but the initialiBations do not need to be repeated. That is wh the
main program is written inside the while loop.
+,-TB is also a register li!e T-I;B. This register passes the value out of port B. This means
+,-TB<1xff will give high output from each eight line of port B.
This line is written to have a dela of #111ms. ;o high logic will pass from port B pins for
H11ms.
This line will ma!e the output from port B get down to 1I, ie logic D1E. It is to be considered that
until the value in +,-TB or an other port register is changed, the output from the corresponding
port will also not change. ;o the output will drop from HI .logic #2 to 1I .logic 12 onl when this
line is executed.
Again a dela of #111ms.
)nd

You might also like