Beruflich Dokumente
Kultur Dokumente
Project Program
MIKEOC PRO FOR PIC
When the program is started, the following menu will be displayed
on the PC screen:
TEMPERATURE DATA LOGGER
1. Send temperature data to the PC
2. Save temperature data in a new file
3. Append temperature data to an existing file
Choice ?
The user is then expected to choose the required option. At the end
of an option, the program does not return to the menu and the
system should be restarted to display the menu again.
The mikroC Pro for PIC program listing of the project is shown
in Figure 7.86 (MIKROC-SD2.C). In this project, a file called
“TEMPERTR.TXT” is created on the SD card to store the
temperature readings.
The following functions are created at the beginning of the program,
before the main program:
Newline: This function sends a carriage return and a line feed to the
UART so that the cursor moves to the next line.
Get_Temperature: This function starts the A/D conversion and
receives the converted data into a variable called Vin. The voltage
corresponding to this value is then calculated in millivolts and
divided by 10 to find the actual measured temperature in degrees
Celsius. The decimal part of the temperature found is then
converted into string form using function LongToStr. The leading
spaces are removed from this string, and the resulting string is
stored in character array temperature. Then the fractional parts of the
measured temperature, a carriage return, and a line feed are added
to this character array, which is later written onto the SD card.
mikroC Pro for PIC Program.
FIGURE 7.86
Default: If the user entry is a number outside 1–3, then this option
runs and displays the error message “Wrong choice…Try again…”
on the PC screen.
The project can be tested by connecting the output of the
microcontroller to the serial port of a PC (e.g. COM1) and then
running a terminal emulation software (e.g. Hyperterm or mikroC
Pro for PIC built-in terminal emulator—USART Terminal). Set
communication parameters to 2400 baud, 8 data bits, 1 stop bit, no
parity bit, and no flow control. Figure 7.87 shows a snapshot of the
PC screen when Option 2 is selected to save temperature records in
a new file. Note that the current record numbers are displayed on
the screen as they are written to the SD card.
Figure 7.88 shows a screen snapshot where Option 1 is selected to
read the temperature records from the SD card and display them on
the PC screen.
Finally, Figure 7.89 shows a screen snapshot when option 3 is
selected to append the temperature readings to the existing file.
MPLAB XC8
The MPLAB XC8 version of the program is left as an exercise to the
reader.