The Lesson 2: Let's C some more... LCD now active introduce several key learning points and I'll cover them individually. They are:
Variables are placeholders, kinda like scratch pad, i.e., a place for you to keep temporary information, intermediate values and so on. Variable must be of a data type (already explained by 9W2GU below). Variable name can be anything as long as it is not the same as those already defined by C (such as integer, for, while, if, etc) and must start with an alphabet.
In the example, four (4) variables were used (bCount, iCount, BoutText, ioutText). In C, ALL variables must be defined before use, otherwise the compiler will give you error(s). If you refer to the codes:
bCount defined as unsigned char (thus maximum value is 255).
iCount defined as unsigned integer (thus maximum value is 65535).
BoutText/IoutText are defined as unsigned character array. Note that array uses  square bracket. In C, array size is one less than defined, thus BoutText can hold 3 characters only. In this example, it will be used to store ASCII characters for the LCD functions.
The functions related to LCD are explained in detailed in the help file and manual. Before using the LCD, it must be initialized (reseting the LCD). This is done using the LCD_Init() function. This function assumes that the wiring is done as per the schematic given in the help file. In our case, we use PortD for the connections thus the function is LCD_Init(&PORTD). There is another function call LCD_Config() provided by MikroC. Use this function IF you wiring is not as per the schematic in the help file.
LCD_Cmd() sends specific command to the LCD such as clearing the screen, turning off the cursor and so on.
It must be noted that the LCD functions that display text only accept ASCII characters, i.e., it will not automatically convert a number into a meaningful display. This is what and why we have line 29 & 31. Line 29 convert an integer into the ASCII equivalent while Line 31 convert a byte into the ASCII equivalent. IntToStr and ByteToStr are built-in functions. Look up the help file and you'll see why I've made the BoutText and ioutText variable definitions.
More C Syntax
Line 23, 27, 33 introduce a C notations.
bCount++; means increment variable bCount by 1 thus is equivalent to the statement bCount=bCount+1;
Similarly bCount--; means decrement variable bCount by 1 (equivalent to bCount=bCount-1;).
PIC-Based Battery Monitor - My friends, as usual, drove me to craziness again and led me to design, fabricate and test a smart battery monitor... The usual blinking lights and so on.....
8 years ago