Wednesday, November 25, 2015

Interface PIC12F675 with LCD display

Interface PIC12F675 with 2-wire LCD display:
With the help of 2-wire serial LCD we can easily interface the microcontroller PIC12F675 with 16x2 or 20x4 or any Lcd compatible with HD44780 controller. For this interfacing 2 lines only are needed which means that we still has 4 free pins on the microcontroller.
For that there is a MikroC library we have to install, to download and install see the following topic:
Serial 2-Wire LCD MikroC Library (for HD44780 compliant controllers) 

The idea is simple, the microcontroller sends data serially to a serial-in parallel-out shift register (74HC164, 74HC595, CD4094 .......) then the shift register sends this data to the Lcd display in parallel.
The library is very easy to use and it's nearly the same as the original Lcd library provided by the developers of mikroC compiler.
Interface PIC12F675 with LCD display circuit:
Circuit schematic diagram is shown below:
pic12f683 lcd example lcd interface

The internal oscillator of the PIC12F675 is used (4MHz) and the MCLR pin function is disabled.
Interface PIC12F675 with LCD display mikroC Code:

// Interface PIC12F675 with LCD display
// Serial LCD library must be installed
// Written by: BENCHEROUDA Okba
// Internal oscillator used @ 4MHz
// Use at your own risk

  // LCD module connections
 sbit Serial_LCD_DATA at GP0_bit;
 sbit Serial_LCD_CLK at GP1_bit;
 sbit Serial_LCD_DATA_Direction at TRISIO0_bit;
 sbit Serial_LCD_CLK_Direction at TRISIO1_bit;
  // End LCD module connections
 unsigned short i;
 void main() {
  GPIO = 0;
  TRISIO = 0;
  Serial_Lcd_Out(1, 3, "Hello world!");
  Serial_Lcd_Out(3, 6, "PIC12F675");
  Serial_Lcd_Out(4, 9, "LCD");
   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);