Skip to main content

Interfacing 16X2 LCD With PIC Microcontroller using miKroC ,CSS and proteus

LCD  Interfacing with PIC microcontroller 

 LCD (Liquid Crystal Display):

In recent years the Alphanumeric display(Liquid Crystal Display) has been finding widespread and replacing "Seven segment display".

 Why we prefer LCDs over LEDs.............. 

1. The declining cost of LCDs.

2. The LCD's can display numbers, characters, and graphics. In contrast,
LEDs, which are confined to display numbers and a few characters.

3.Manfacturers provide built in controller with LCD to control refresh rate as a result no need to write code in PIC18 for that task. Conversely, separate routine is required to refresh LEDs to carry displaying the information. 

4. Simple programming for characters and graphics.

More importantly, LCD current(mA) requirement in comparison of  seven segment displays is considerably low. Furthermore, Latest LCDs modules permit the coder to define custom  character and graphics.

Once you find out how to interface it, it'll be the best and extremely reliable output device utilized by you.  Moreover, to debug the code LCD can be easily utilized if you don't have debugger.


Pin Configuration table for a 16X2 LCD character display:-

Pin Number
Symbol
Function
1
Vss
Ground Terminal
2
Vcc
Positive Supply
3
Vdd
Contrast adjustment
4
RS
Register Select; 0→Instruction Register, 1→Data Register
5
R/W
Read/write Signal; 1→Read, 0→ Write
6
E
Enable; Falling edge
7
DB0
Bi-directional data bus, data transfer is performed once, thru DB0 to DB7, in the case of interface data length is 8-bits; and twice, through DB4 to DB7 in the case of interface data length is 4-bits. Upper four bits first then lower four bits.
8
DB1
9
DB2
10
DB3
11
DB4
12
DB5
13
DB6
14
DB7
15
LED-(K)
Back light LED cathode terminal
16
LED+(A)
Back Light LED anode terminal
Now that was all regarding the signals and also the hardware .Next, we discuss how one can send signals to LCD to display required information. 
The information you want to display on LCD is kind of data signals and RS,E and RW categorized as control signals. To display data on LCD, First we send data then we put logic LOW on RS pin and RW pin and send high to low pulse to enable pin.
LCD needs a time of 39-43µS to display a character or if you want to execute any command like move the cursor on the right or left. In a similar manner,  some operations like clearing display requires more time (1.63ms).Programmer must consider required time intervals when sending data, because if the defined time duration is not provided LCD controller may not display or execute commands. 
Generally, Manufacturer provides two different kinds of RAMs within the LCD module ,Display data RAM which is responsible to hold the letters and the other one is Character Graphic RAM which permits user to define their custom or non standard characters.
Don't worry the above all operation can be automatically handle by using predefined library in miKroC and CSS.  

Commands:

Instruction
Instruction Code
Instruction Code DescriptionExecution time
RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
Read Data From RAM
1
1
D7
D6
D5
D4
D3
D2
D1
D0
Read data from internal RAM
1.53-1.64ms
Write data to RAM
1
0
D7
D6
D5
D4
D3
D2
D1
D0
Write data into internal RAM (DDRAM/CGRAM)
1.53-1.64ms
Busy flag & Address
0
1
BF
AC6
AC5
AC4
AC3
AC2
AC1
AC0
Busy flag (BF: 1→ LCD Busy) and contents of address counter in bits AC6-AC0.
39 µs
Set DDRAM Address
0
0
1
AC6
AC5
AC4
AC3
AC2
AC1
AC0
Set DDRAM address in address counter.
39 µs
Set CGRAM Address
0
0
0
1
AC5
AC4
AC3
AC2
AC1
AC0
Set CGRAM Address in address counter.
39 µs
Function Set
0
0
0
0
1
DL
N
F
X
X
Set interface data length (DL: 4bit/8bit), Numbers of display line (N: 1-line/2-line) display font type (F:0→ 5×8 dots, F:1→ 5×11 dots)
39 µs
Cursor or Display Shift
0
0
0
0
0
1
S/C
R/L
X
X
Set cursor moving and display shift control bit, and the direction without changing DDRAM data
39 µs
Display & Cursor On/Off
0
0
0
0
0
0
1
D
C
B
Set Display(D),Cursor(C) and cursor blink(b) on/off control
39 µs
Entry Mode Set
0
0
0
0
0
0
0
1
I/D
SH
Assign cursor moving direction and enable shift entire display.
0µs
Return Home
0
0
0
0
0
0
0
0
1
X
Set DDRAM Address to “00H” from AC and return cursor to its original position if shifted.
43µs
Clear Display
0
0
0
0
0
0
0
0
0
1
Write “20H” to DDRAM and set DDRAM Address to “00H” from AC -Address
Counter

Proteus Simulation of Interfacing 16X2 LCD With PIC18F4580  Microcontroller 





miKroC Code for Interfacing 16X2 LCD With PIC 18F4580 Microcontroller

// LCD module connections



sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

char txt1[] = "Welcome";
char txt2[] = "Lcd Example";
char txt3[] = "PIC18F4580";
char txt4[] = "Hello!";

char i;                              // Loop variable





void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){
  ADCON1 = 0xff;
  CMCON = 0x7;

  Lcd_Init();                        // Initialize LCDa

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt4);                 // Write text in first row

  Lcd_Out(2,6,txt1);                 // Write text in second row
  Delay_ms(2000);
 Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt3);                 // Write text in first row

  Lcd_Out(2,5,txt2);                 // Write text in second row

  Delay_ms(2000);

  //Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }
}


Proteus Simulation of Interfacing 16X2 LCD With PIC18F4580  using CSS Code


CSS Code for Interfacing 16X2 LCD With PIC 18F4580 Microcontroller







#define LCD_TYPE 2
#include <flex_lcd.c>
void main()
{
   



   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

lcd_init();  // Always call this first.

lcd_putc("\fHello World\n");

lcd_putc("");


while(1){
lcd_putc("\fHello World\n");

lcd_putc("CSS CODE Test");
  delay_ms (1);



}
}
         
                Friends for further learning about PIC18 checkout
https://microcontrollerpicavr.blogspot.com/2017/08/counter-programming-of-pic18f-using.html

Comments

Popular posts from this blog

How to use SPI Debugger

  SPI Debugger Hi Friends, in this post, we will discuss how to use SPI Debugger available in proteus for serial peripheral interface (SPI) which is a built-in feature of PIC microcontroller to communicate and data exchange between PIC and other devices. SPI Debugger Introduction to SPI Guys, SPI can be considered as a programmable shift  register, The SPI module is a synchronous serial I/O port that shifts a serial bit stream of variable length and data rate between the PIC and other peripheral devices. Here “synchronous” means that the data transmission is synchronized to a clock signal. To avoid further delay, let's see some important connections and different configurations to effectively use SPI Debugger. How to use SPI Debugger in MASTER & SLAVE configuration Select the virtual instrument and from the instrument, list selects "SPI Debugger". SPI Debugger Insert two SPI Debugger on the working area, select any one of them,

PIC18f4580 Timer0 calculation using miKroC , CSS and proteus

PIC18f4580 TIMER PROGRAMMING The PIC18f4580 has four timers. they're named as Timers zero, one, two, and three. they will be used either as timers to come up with a time delay or as counters to count events happening outside the microcontroller. First, we see however Timers zero is employed to come up with time delays. Every timer wants a clock pulse to tick. The clock supply will be internal or external. If we have a tendency to use the inner clock supply, then 1/ fourth of the frequency of the crystal oscillator on the OSC1 and OSC2 pins (Fosc/4) is fed into the timer. Therefore, it's used for time delay generation and for that reason is termed a timer. By selecting the external clock choice, we have a tendency to feed pulses through one among the PIC18's pins: this is often known as a counter. GIF  taken from  https://exploreembedded.com Basic registers of the timer Majority of t timers in 18F are 16 bits wide. Because the PIC 18 has an 8- bit ar

Frequency Counter using Interrupts PIC18f4580 Project

Frequency Counter  using PIC18f458 0 Proje ct This POST describes the construction of small frequency counter with a cheap PIC18f4580 microcontroller with 16 x 2 LCD.   Prerequisites: PIC18F4580 TIMER Programming. PIC18F4580 COUNTER Programming. PIC18F4580 Interfacing with 16x2 LCD. PIC18F4580 Interrupts Programming  ( we will cover in this POST) Concept: Frequency  is the number of occurrences of a repeating event per unit time. in our case we will measure a number of clocks generated by clock source per unit time. In this project, LCD is used to display the frequency and PIC timer 1 to measure the input signal and Timer0 to generate an indication that one second has gone. System software utilizes Timer-1 in the 16-bit counter mode to count the input signal and overflows of the counter are added to provide the aggregate count in multiples of 65536. Totaling the existing value of the counter at the conclusion provides the full count.