Declaring Variables and Setting Microcontroller Ports in mikroC
We know how to declare variables and how to set microcontroller ports in assembly language. Lets see how easy to do this in mikroC.
unsigned char counter1;
The word “counter1” is the name of the variable. “unsigned char” is the variable type. char stands for character and its a 8 bit variable. What does unsigned means? There are three types of characters in C. They are char, signed char, unsigned char.
unsigned char – holds values 0-255
signed char – holds value (–128-127) (has the minus sign when you want)
char – allows using texts. (a-z or 0-9)
TRISA = 0b00001111;
0b represents binary, and we are telling the microcontroller to set the pins RA0 -RA3 as inputs and RA4-RA7 as outputs.
TRISA = 0xFF;
0x represents hexadecimal, and we are telling the microcontroller to set all pins of port A as inputs.
TRISA = 0;
Now we are talking in decimal. We are telling the microcontroller to set all pins of port A as outputs.
Setting Port bits
Sometimes we want to set individual pins. Here’s how to do that.
PORTA.F3 = 1; TRISA.F1 = 1;
For most projects programming can be made further easy by using sbit syntax. This allows to set a name for a port bit.
sbit p1 @ PORTA.F3;
From now on, whenever ever you say p1, mikroC knows you are refering to PORTA.F3 bit.
I recommend you to refer mikroC help. It gives you all the info you want. Check what other variables available.