Saturday, December 5, 2015

Interface PIC12F1822 with LCD display



PIC12F1822 LCD Example

Interface PIC12F1822 with 2-wire LCD display:
With the help of MikroC library for a 2-wire serial LCD display we can easily interface the microcontroller PIC12F1822 with LCDs like 16x2 or 20x4.
This interfacing uses only two lines one for data and the other for clock. To build this interfacing we need a serial-in parallel-out shift register such as CD4094, 74HC595, 74HC164 or any other types. The shift register is very cheap IC and it can be found in many types of electronic devices. To see how to install the 2-wire serial LCD display library go to the following topic:

Interface PIC12F1822 with LCD display circuit:
Circuit schematic diagram of interfacing PIC12F1822 with LCD display is shown in the next image where internal oscillator of the PIC12F1822 microcontroller is used and MCLR pin function is disabled which means we don't have to pull-up the MCLR pin.
Here the shift register 74HC164 is used.
pic12f1822 interfacing lcd example mikroc

Interface PIC12F1822 with LCD display mikroC Code:
The internal oscillator of the microcontroller is used at 8MHz with PLL enabled which means that the microcontroller is running at 8 x 4 = 32MHz.
Used mikroC configurations are as shown below:
lcd mikroc

2 wire serial lcd mikroc

 // Interface PIC12F1822 with LCD display
 // Serial LCD library must be installed
 // Written by: BENCHEROUDA Okba
 // electronnote@gmail.com
 // http://elecnote.blogspot.com/
 // Internal oscillator used @ 32MHz
 // Use at your own risk
 
  // LCD module connections
 sbit Serial_LCD_DATA at RA4_bit;
 sbit Serial_LCD_CLK at RA5_bit;
 sbit Serial_LCD_DATA_Direction at TRISA4_bit;
 sbit Serial_LCD_CLK_Direction at TRISA5_bit;
  // End LCD module connections
  
 unsigned short i;
void main() {
 OSCCON = 0xF0; // Internal oscillator 8MHz and PLL enabled (gives 32MHz)
 ANSELA = 0;    // All I/O pins are configured as digital
 ADCON0 = 0;    // Disable ADC module
 PORTA = 0;     // Initial value of port A bits
 TRISA = 0;     // Port A pins are configured as outputs
 Serial_Lcd_Init();
 Serial_Lcd_Cmd(_LCD_CURSOR_OFF);
 Serial_Lcd_Cmd(_LCD_CLEAR);
 Serial_Lcd_Out(1,17,"PIC12F1822");
 Serial_Lcd_Out(2,17,"LCD Example");
 for(i = 0; i < 13; i++) {             // Move text to the left 13 times
      Serial_Lcd_Cmd(_LCD_SHIFT_LEFT);
      Delay_ms(100);
  }
 Delay_ms(2000);
 Serial_Lcd_Cmd(_LCD_CLEAR);
 Serial_Lcd_Out(1,17,"www.elecnote.");
 Serial_Lcd_Out(2,17,"blogspot.com");
 for(i=0; i<14; i++) {
      Serial_Lcd_Cmd(_LCD_SHIFT_LEFT);
      Delay_ms(100);
  }
 Delay_ms(2000);
 Serial_Lcd_Cmd(_LCD_CLEAR);
  Serial_Lcd_Out(1, 3, "Hello world!");
  i = 0;
  while(1){
   if (i > 199) i = 0;
   Serial_Lcd_Chr(2, 8, i/100 + 48);
   Serial_Lcd_Chr(2, 9, (i/10) % 10 + 48);
   Serial_Lcd_Chr(2, 10, (i % 10) + 48);
   i++;
   Delay_ms(1000);
  }
 }

Interface PIC12F1822 with LCD display video:
This video shows this project where the circuit is built with actual hardware.