Skip to main content

The future of AI in business and its potential to transform industries

Interfacing 16x2 LCD display with PIC18F4520 controller

Interfacing 16x2 LCD display with PIC18F4520 controller

intro page of interfacing DC motor

The LCD display is also one of the most important and most used peripheral devices in embedded systems. Whenever we required to display some information or some status we usually prefer an LCD display.

In this article, we will talk about how to interface a 16x2 LCD display to the PIC18F4520 controller.

We will cover this article in the following steps:-

  • About the project
  • Required components
  • Software tools
  • Circuit diagram
  • Writing code for the controller
  • Upload the Hex file to the controller
  • Simulating the project

About the project

This would be a simple LCD interfacing task.

In this LCD interfacing project, we will display the reverse count from 3 to 1 and then display the "Code Somenplus" text (name of this blog page) on the LCD display. 

Required components

The required components for the simulations are
  • PIC18F4520 controller
  • LM016L (16x2 LCD display)

Software tools

The software tools that require are

  • Proteus 8 professional
  • MPlab IDE

Circuit diagram

The circuit diagram for the LCD interfacing is given below.

interfacing of DC motor circuit diagram

Here, the rs, rw, en pin of the LCD display is connected to Port C0, Port C1, Port C2 and Port D is connected from D0 to D7 pin.

Writing code for the controller

Now, after connecting all the required components, it's time to write the code for the controller.

The code for the controller is given below


#include <xc.h>

#define _XTAL_FREQ 20000000

#define rs RC0

#define rw RC1

#define en RC2


void lcd_data(unsigned char data);

void lcd_cmd(unsigned char command);

void lcd_string(const unsigned char *string, unsigned char length);

void lcd_initialize();


void main()

{

    TRISD=0;

    TRISC0=0;

    TRISC1=0;

    TRISC2=0;

    

    lcd_initialize();

    

    while(1)

    {

        lcd_cmd(0x01);

        lcd_cmd(0xc7);

        lcd_data('3');

        __delay_ms(1000);

        

        lcd_cmd(0xc7);

        lcd_data('2');

        __delay_ms(1000);

        

        lcd_cmd(0xc7);

        lcd_data('1');

        __delay_ms(1000);

        

        lcd_cmd(0x01);

        lcd_cmd(0x80);

        lcd_string("Code Somenplus",14);

        __delay_ms(1000);

       

        

    }

}

    

void lcd_data(unsigned char data)

{

    PORTD=data;

    rs=1;

    rw=0;

    en=1;

    __delay_ms(5);

    en=0;

}


void lcd_cmd(unsigned char command)

{

    PORTD=command;

    rs=0;

    rw=0;

    en=1;

    __delay_ms(5);

    en=0;

}


void lcd_string(const unsigned char *string, unsigned char length)

{

    unsigned char i;

    for(i=0;i<length;i++)

    {

        lcd_data(string[i]);

    }

}


void lcd_initialize()

{

    lcd_cmd(0x38);

    lcd_cmd(0x06);

    lcd_cmd(0x0c);

    lcd_cmd(0x01);

}

After writing the above code all you need is to compile, run and generate the Hex file.

Uploading the Hex file to the controller

uploading hex file to the PIC controller

After generating the Hex file all you need is to upload the hex file to the controller. To upload the Hex file to the controller all you need is to double click on the microcontroller and select the Hex file you created.

Simulate the project

To simulate the project, just click the play button given on the bottom left corner of the simulator.

Video


Popular posts from this blog

PIC18 Timer programming in C

The PIC18 timer is divided into 4 types Timer 0 Timer 1 Timer 2 Timer 3 PIC18 timers can be used to generate a time delay or as a counter to count external event happening outside the microcontroller. In this article, we will see how to generate a time delay by programming the PIC18 timer. Timer 0 The timer 0 module has the following features Software is scalable as an 8 bit or 16-bit timer/counter. Readable and writable Dedicated 8 bit software programmable Prescaler Clock source selectable to be internal or external Edge select for external clock Register required for Timer 0 Control register Each timer has a control register called TCON to set the various timer operation modes. T0CON is an 8-bit register used for control of timer 0. TOCON TMR0ON (Timer0 on/off control bit)                                       1 = Enable timer 0                ...

What is machine learning and it's types?

 What is machine learning(ML)? Machine learning is a subset of artificial intelligence. Machine learning enables computers or machines to make data-driven decisions rather than being explicitly programmed for a certain task. These programs or algorithms are designed in a way that they learn and improve over time when are exposed to new data. Examples:- 1. Product recommendations   While checking for a product did you noticed when it recommends a product similar to what you are looking for? or did you noticed "the person bought this product also bought this" combination of products? How are they doing this recommendation? This is machine learning. 2. Email spam and malware filtering  There are a number of spam filtering approaches that email clients use.  To ascertain that these spam filters are continuously updated they are powered by machine learning. 3. Online customer support A number of websites nowadays offer the option to chat with customer support representati...

Top 7 domains to expertise after learning python

Top 7 domains to expertise after learning python Python is one of the most popular programming languages. It is an object-oriented, dynamic semantics and high-level programming language. It's high-level built-in data structure combined with dynamic binding and dynamic typing makes it attractive for rapid application development. Often programmers fall in love with python because of the increased productivity it provides. Python is one of the most readable languages in the world right now. This language is very popular among developers and is widely used by many programmers to create application and programs. The implementation of this programming language is simple and at the same time, the language has a very clean structure as compared to other languages.  So if you mastered your python concepts and skills, you can dominate these 7 domains. Machine learning / Artificial intelligence Desktop GUI Data analytics and data visualization  Web development Game development Mobile ap...