Thursday, December 1, 2016

DISPLAY CUSTOM CHARACTER ON LCD USING 8051 MICROCONTROLLER


  • CIRCUIT DIAGRAM




  • CODE


/*-----------------------------------------------------------------------*/
/* Project Name: LCD 8bit Custom Character Generation     */
/* --------------------------------------------------------------------- */

#include <reg51.h>
#include <string.h>

/* Function declarations */

void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void writeline(char[]);
void ReturnHome(void);
void LCDBuildChar(unsigned char, unsigned char*);

/*-----------------------
Pin description
-------------------------
P2 is data bus
P3.0 is RS
P3.1 is E
-----------------------*/

// -----------------------   Define Custom Characters ----------------------- //
unsigned char Character1[8] = { 0x1c,0x16,0x1d,0x01,0x1d,0x16,0x1c,0x00 };   // Phone Up 1
unsigned char Character2[8] = { 0x07,0x0d,0x17,0x10,0x17,0x0d,0x07,0x00 };   // Phone Up 2
unsigned char Character3[8] = { 0x1f,0x1f,0x12,0x04,0x09,0x10,0x1f,0x00 };   // Phone Down 1
unsigned char Character4[8] = { 0x1f,0x1f,0x09,0x04,0x12,0x01,0x1f,0x00 };   // Phone Down 2
unsigned char Character5[8] = { 0x04,0x04,0x04,0x04,0x15,0x0e,0x04,0x00 };   // Downward Arrow
unsigned char Character6[8] = { 0x04,0x0e,0x15,0x04,0x04,0x04,0x04,0x00 };   // Upward Arrow
unsigned char Character7[8] = { 0x01,0x02,0x04,0x08,0x10,0x11,0x1f,0x00 };   // Curvy Object
unsigned char Character8[8] = { 0x00,0x1f,0x11,0x11,0x11,0x1f,0x00,0x00 };   // Square Box
/*---------------------------------------------------*/


/* Main program */
int main(void)
{
                                      /* Make all ports zero */
   lcdinit();                                      /* Initilize LCD */

   writedata(0x00);                                /* Write Custom Character 1 */
   writedata(0x01);                                /* Write Custom Character 2 */
      writedata(' ');                              // Space
   writedata(0x02);                                /* Write Custom Character 3 */
   writedata(0x03);                                /* Write Custom Character 4 */
      writedata(' ');                              // Space
   writedata(0x04);                                /* Write Custom Character 5 */
   writedata(0x05);                                /* Write Custom Character 6 */
      writedata(' ');                              // Space
   writedata(0x06);                                /* Write Custom Character 7 */
   writedata(0x07);                                /* Write Custom Character 8 */

   while(1)
   {;}
}


/*---------------------------------------------------*/

/* Function definitons */



void delay(int a)
{
   int i,j;
   for(i=0;i<a;i++)
   for(j=0;j<1275;j++);   /* null statement */
}

void writedata(char t)
{
   P3 |= 0x01;         /*   => RS = 1     */
   P2 = t;             /*   Data transfer */
   P3 |= 0x02;         /*   => E = 1      */
   delay(150);
   P3 &= 0xfd;         /*   => E = 0      */
   delay(150);
}


void writecmd(int z)
{
   P3 &= 0xfe;         /*   => RS = 1     */
   P2 = z;             /*   Data transfer */
   P3 |= 0x02;         /*   => E = 1      */
   delay(150);
   P3 &= 0xfd;         /*   => E = 0      */
   delay(150);
}

void lcdinit(void)
{
  /* ------------ Reset process from datasheet ----------- */
     delay(100);
   writecmd(0x30);
     delay(100);
   writecmd(0x30);
     delay(100);
   writecmd(0x30);
     delay(100);
  /* ----------------------------------------------------- */
   writecmd(0x38);    /* function set */
   writecmd(0x0e);    /* display on,cursor on*/
   writecmd(0x01);    /* clear display */
   writecmd(0x06);    /* entry mode, set increment */
 
   /* ---------- Build Custom Characters -----------------*/
 
   LCDBuildChar(0, Character1);                    /* Build Character1 at position 0 */
   LCDBuildChar(1, Character2);                    /* Build Character2 at position 1 */
   LCDBuildChar(2, Character3);                    /* Build Character3 at position 2 */
   LCDBuildChar(3, Character4);                    /* Build Character4 at position 3 */
   LCDBuildChar(4, Character5);                    /* Build Character5 at position 4 */
   LCDBuildChar(5, Character6);                    /* Build Character6 at position 5 */
   LCDBuildChar(6, Character7);                    /* Build Character6 at position 6 */
   LCDBuildChar(7, Character8);                    /* Build Character6 at position 7 */
}

void ReturnHome(void)     /* Return to 0 cursor location */
{
   writecmd(0x02);
   delay(1500);
}

void writeline(char Line[])
{
   int i;
   for(i=0;i<strlen(Line);i++)
   {
      writedata(Line[i]);     /* Write Character */
   }
 
   ReturnHome();          /* Return to 0 cursor position */
}

/**********************************************************
Function Name: LCDBuildChar
Input:
     loc: location where you want to store  0,1,2,....7        
     p: Pointer to pattern data
Usage:
     LCDBuildChar(1,pattern);
 ********************************************************* */

void LCDBuildChar(unsigned char loc, unsigned char *p)
{
     unsigned char i;

     if(loc<8)                                 //If valid address
{
         writecmd(0x40+(loc*8));               //Write to CGRAM
         for(i=0;i<8;i++)
            writedata(p[i]);                   //Write the character pattern to CGRAM
     }
writecmd(0x80);                           //shift back to DDRAM location 0
}

  • OUTPUT 




Wednesday, November 30, 2016

Arduino Temperature Sensor

Room temperature monitor plays an important role in day to day life. This project incorporates the design and development of a temperature monitoring using ARDUINO and LCD. The main target for this system is to have it designed and implemented such that it is cost-effective. This project consists of one module (temperature monitoring). The temperature sensor senses the temperature and the inbuilt ADC in the arduino produces corresponding analog signal which is further processed by the arduino and the temperature is displayed in the LCD. The temperature on the LCD will be displayed in °C and °F.

  • COMPONENTS
    • Arduino UNO board
    • Breadboard 
    • 16x2 LCD display
    • LM35 sensor
    • Jumpers - to connect everything

  • CIRCUIT DIAGRAM



  • CODE
#include <LiquidCrystal.h>
int tempPin = A0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup()
  lcd.begin(16, 2);
}
void loop()
{  while(1)
{
  int tempReading = analogRead(tempPin); 
  float tempVolts = map(tempReading, 0, 512, 0, 255); 
  float tempC = (tempVolts); 
  float tempF = tempC * 9.0 / 5.0 + 32.0;  
  lcd.print("Temp         C  "); 
  lcd.setCursor(6, 0); 
  lcd.print(tempC);     
  
  lcd.setCursor(0, 1); 
  lcd.print("Temp         F  ");   
  lcd.setCursor(6, 1); 
  lcd.print(tempF); 
  delay(500);
  }
}

  •  APPLICATION
    • Indoors, temperature sensors are used in several climate control systems including refrigerators, freezers, air conditioners, heaters and water heaters
    • They are found within roadways in cold weather climates in order to help determine if icing conditions exist. 
  •  ADVANTAGES
    • Sensitivity: This allows it to sense very small changes in temperature.
    • Accuracy: It offers both high absolute accuracy and interchangeability.
    • Cost: It is very cost-effective.
    • Ruggedness: Because of their construction, it is very rugged.
  •  DISADVANTAGES
    • Non-linear
    • Self-heating
    • Moisture failures
If you have any query regarding this project than you can contact by writing in comment or can mail directly.