Read Chip Huyen's answer to Who do you think is the best professor in the world and why? on Quora

Monday, 30 September 2013

Microcontroller - A Beginners Guide - Writing the First Program to Display on LCD "Microncontroller-Made-Easy"

I know that you are ready to write the first program. You have been through a lot so far! While we are on the subject, let's recap the events. You went out and purchased th PIC microcontroller of your choice. I chose the PIC16F877A for my uses. You were introduced to the concept of microcontrollers how they work; and were also introduced to the programmer, the device that helps transfer the program into the microcontroller.
I write a program in C using mikroC PRO for PIC v5.6.1 compiler. I know its difficult to work with but it’s time that matters. Now I’m successfully write a program and below is the program:
//---------------------------------------------------------------------------------------------------------
//Programmer: Qamar Ul Islam
//Compiler: mikroC PRO for PIC v.5.6.1
//Target PIC: PIC16F877A
//Program for Display on LCD
//---------------------------------------------------------------------------------------------------------
#include<pic.h>
__CONFIG(WDTDIS & XT & UNPROTECT);       
char name1[40]={"  Microcontroller-Made-Easy  "};

void delay(int x)
{
         int d,l;
        for(l=0;l<x;l++)
         {
        for(d=0;d<4000;d++);
        }
}

void instwrt(void)
        {
       
        RC0=0;
        RC1=0;
        RC2=1;
        delay(1);
        RC2=0;
        delay(1);       
}

void datawrt(void)
        {
        RC0=1;
        RC1=0;
        RC2=1;
        delay(1);
        RC2=0;
        delay(1);
        }
void lcdin()
        {
        PORTD=0x38;
        instwrt();
        PORTD=0x0c;
        instwrt();
        PORTD=0x01;
        instwrt();
        PORTD=0x06;
        instwrt();
        PORTD=0x80;
        instwrt();
        }
void main(void)
        {
        int a;
        TRISD=0x00;
        TRISC=0X00;
        lcdin();
        for(a=0;a<32;a++)
        {
                   PORTD=name1[a];
                datawrt();
        }
while(1)
{
        PORTD=0x18;
        instwrt();
        delay(50);
}
}
And Here is a snapshot of the experimental setup shown below:


Hope you’ll find interesting as your hobbyist project.
Don’t forget to write us.

No comments:

Post a Comment