Saturday, 23 May 2015

Interfacing LCD with 8051 microcontroller


Source code for LCD interfacing

/*------ PIN CONNECTION OF LCD WITH 8051 MCU -----------*/

LCD data lines (D0-D7) -----> ( P1.0 - P1.7 )
LCD control lines, RS(register select) ------> P2.0
                               RW(read write)     ------>  P2.1
                               EN( enable)          -------> P2.2
 /* ----------- Software for LCD interfacing-----------------------------*/

1. #include<AT89x51.h> /* header for 8051 family Micro controller*/
/* defining lcd control pin connection*/
2. #define register_select P2_0
3. #define read_write       P2_1
4. #define enable              P2_2
5. #define data_lines        P1

/*-------declaring function or function prototyping--------*/
void millidelay(unsigned int);
void send_command(unsigned char);
void send_data(unsigned char);
void lcd_init();
void send_string(unsigned int *);
/*------  end of function prototyping------------------------*/
 

void main(void) // main program or program execution starting point.
{
    lcd_init(); // first lcd will be initialized
    send_string("HELLO WORLD"); // print and display the string.
while(1) // continue display.repeating manner.
{
   }
}

void millidelay(unsigned int t) /* function that will create milly second delay*/
{
    int x,y;
for(x=0;x<t;x++)
for(y=0;y<1275;y++);
}  

 void send_command(unsigned char x)  /* function to send command to lcd*/
{
    data_lines=x;
    register_select=0;
    read_write=0;
    enable=1;
    millidelay(10);
    enable=0;
    millidelay(10);
 }

void send_data(unsigned char x)   /* function to send data to the lcd*/
{
deta_lines=x;
register_select=1;
read_write=0
enable=1;
millidelay(10);
enable=0;
millidelay(1);
}

void lcd_init()   /* function for lcd initialization*/
{
send_command(0x38);
send_command(0x01);
send_command(0x0E);
send_command(0x0F);
millidelay(1);   
 }

void send_string(unsigned char *x)
{
  int x;
for(x=0;data[x]!=0;x++)
{
   send_data(data[x]);
  }
}



Friday, 15 May 2015

Interfacing LED with AT89C51/S52




Background Theory

LED stands for "light emitting diode"  a semiconductor device that converts electricity into light or it emits visible light when electric current is passes over it. A LED can be constructed using a PN junction diode where a P type semiconductor material is sandwitched with a N type semiconductor material which will emit light when energy is applied on it. This phenomenon is generally called      electroluminance, which can be defined as the emission of light from a semi conductor under the influence of an electric field.

 The charge carriers recombine in a forward P-N junction as the electrons cross from the N-region and recombine with the holes existing in the P-region. Free electrons are in the conduction band of energy levels, while holes are in the valence energy band. Thus the energy level of the holes will be lesser than the energy levels of the electrons. Some part of the energy must be dissipated in order to recombine the electrons and the holes. This energy is emitted in the form of heat and light.

 Interfacing With AT89C51/C52/S51/S52


#include<AT89x51.h>
#define LED P1_1
void milli_delay(unsigned int t);
void main( )
{
   LED=1;
   milli_delay(100);
   LED=0;
   milli_delay(100);

 void milli_delay(unsigned int t)
{
    int x,y;
    for(x=t;x>0;x--)
    for(y=1275;y>0;y--);
}