Friday, November 27, 2015

Interface PIC12F683 with LCD display

Interface PIC12F683 with 2-wire serial LCD display

Interface PIC12F683 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 PIC12F683 with LCD display circuit:
Circuit schematic diagram is shown below:
pic12f683 interfacing lcd example mikroc
The internal oscillator of the PIC12F675 is used at 8MHz and the MCLR pin function is disabled.
Interface PIC12F683 with LCD display mikroC Code:
2-WIRE SERIAL LCD LIBRARY MUST BE INSTALLED.

 // Interface PIC12F683 with LCD display
 // Serial LCD library must be installed
 // Written by: BENCHEROUDA Okba
 // electronnote@gmail.com
 // http://elecnote.blogspot.com/
 // Internal oscillator used @ 8MHz
 // 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() {
  OSCCON = 0x71;       // Configure internal oscillator (8MHz)
  ANSEL = 0;           // All I/O pins are configured as digital
  ADCON0 = 0;         // Disable ADC module
  GPIO = 0;
  TRISIO = 0;
  Serial_Lcd_Init();
  Serial_Lcd_Cmd(_LCD_CURSOR_OFF);
  Serial_Lcd_Cmd(_LCD_CLEAR);
  Serial_Lcd_Out(1, 3, "Hello world!");
  Serial_Lcd_Out(3, 3, "http://elecnote.");
  Serial_Lcd_Out(4, 5, "blogspot.com");
  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);
  }
 }

The following video shows Proteus simulation of the interfacing where both types 16x2 and 20x4 of LCD are used: