Saturday, January 10, 2015

PIC16F84A LCD Example with mikroC

PIC16F84A LCD Example, mikroC code + Proteus simulation:
This is just an example to interface microchip pic16f84a with 16x2 lcd display. The code of this project is written using miKroC pro for PIC version 5.01. The lcd should display on the first line a counting number that counts from 0 to 99 and 'PIC16F84A', and on the second line it should display 'LCD Example'. I added the proteus simulation to users who did not have the hardware to build this tiny project.The schematic of the circuit and simulation file are below:
Note that I have Proteus version 8.0.
Proteus Simulation download
PIC16F84A LCD Example circuit:

Interface PIC16F84A with LCD using mikroC

PIC16F84A LCD Example mikroC code:

//PIC16F84A LCD example mikroc code.
//electronnote@gmail.com
//Use at your own risk

// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
// End LCD module connections
char *text, mynumber[4];
unsigned int i = 0;
void main() {
TRISB = 0;
PORTB = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);        // cursor off
Lcd_Cmd(_LCD_CLEAR);             // clear LCD
text = "PIC16F84A" ;
Lcd_Out(1, 6, text);
text = "LCD Example";
Lcd_Out(2, 5, text);
while(1){
 ByteToStr(i, mynumber);
 Lcd_Out(1, 2, mynumber);
 i++; 
 if (i > 99) i = 0;                //if i > 99 set i to zero
 delay_ms(1000);}
                                 }


PIC16F84A LCD display hardware image:

PIC16F84A lcd mikroc