MikroC Introduction Lab Report
MikroC Introduction Lab Report
4
Introduction to MicroC Program
Simulation Lab ENEE4104
Section: Saturday 2:00-5:00pm
Date: 22/10/16
Abstract:
The aim of this experiment was familiarize students with the MicroC Pro by
simulating and testing out some basic, and straight-forward programs/codes, and
run them on a PIC Microcontroller simulator using programs such as Proteus,
without loading them on a real PIC Microcontroller.
Introduction:
PIC Microcontrollers are chips family that mainly consists of I/O ports, memory,
processor, and converters like Analog-to-Digital Converters/Digital-to-Analog
Converters and so on, and some other features, such as, Pulse Width Modulation
(PMW) modules. These Microcontrollers can be programmed by higher level
language like C, and as any processor, it has its own instruction set, thus, it requires
a special compilers; e.g. mikroC PRO for PIC.
microC PRO is a software that is used to write programs for Microcontrollers, its
official language is C, but this program has its own compiler that is specially made
to compile the code to fit the processor of the PIC Microcontrollers since, they differ
from the ordinary computer processors like Intel, and has their own instruction set.
Procedure
PART I:
1. microC Pro was opened, and a new project was created with the following
specifications:
a. The device was chosen to be P16F84A
b. The clock was chosen to be 4MHz
was
PRO:
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;
// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;
void main()
{
TRISA = 0x00; // set all pins of port A as output
TRISB = 0x00; // set all pins of port B as output
while(1)
{ lcd_init(); // initialize the lcd
lcd_out(1,1,"ENEE413 EXP#3");
Lcd_Cmd(_LCD_CURSOR_OFF);
}
3. After the code was written, it got built right away, in order to extract the hex
file of the project!
PARTI Simulation:
1. Proteus software was opened and the following circuit was drawn as shown in
Figure below:
PART II:
1. microC Pro was opened, and a new project was created with the following
specifications:
a. The device was chosen to be P16F877A
b. The clock was chosen to be 8MHz
void main() {
TRISA = 0xFF; // PORTA is input
TRISC = 0; // PORTC is output
TRISB = 0; // PORTB is output
do {
a = ADC_Read(0); // Get 10-bit results of
AD conversion PORTB = a; // Send
lower 8 bits to PORTB
PORTC = a >> 8; // Send 2 most
significant bits to RC1, RC0 } while(1);
}
PART II Simulation:
1. Proteus software was opened and the following circuit was drawn:
2. The output of the microC code hex file was loaded onto the Proteus
PIC16F877A model, with clock set to 8MHz
3. The circuit was simulated and the results of simulation were observed and
snap shot of the output was taken
Results
1.
PART I:
2. PART II:
a. With pot set to 100%:
Discussion
1. We observed that in PART I, that microC program has its own
libraries for various of electronic parts such as the LCD which has its
own library and instructions(functions)
That helps and eases the programming operation.
2. In part two we observed that the Analog to Digital Converter is
limited to 10 bits, which may result in errors if we want to make a
system to be highly accurate, but in this case its not important
3. The code in part two consists of an infinite while loop which will
never ever end since its ending option cant be attained, and also
the analog input is just a fraction of the bias/reference voltage,
ranging from between
Vfull > Vfraction > 0
4. When the analog input is at maximum full range input the microC is
programmed then to drive all the LEDs at its defined outputs,
which these LEDs will represent the digital equivalent code of the
analog input