we provide information about gadget news and price information and specs samsung, huawei, Tecno Price products, Specifications, Features and more information about software from blackberry and android

Tuesday, June 12, 2012

Custom characters on 16x2 LCD

Custom characters on 16x2 LCD - Did you know that every day there is always a new technology that is created? if you want to know please refer to the blog Gadget News well now we will discuss first about Custom characters on 16x2 LCD as you need now, we have compiled this article carefully, so please see to finish.

Articles : Custom characters on 16x2 LCD
full Link : Custom characters on 16x2 LCD
Article Embedded Zone,

You can also see our article on:


Custom characters on 16x2 LCD




Hi,
today we are display Custom characters on 16x2 LCD.
hear we are using tow good software keil and proteus same as older post lcd interfasing.


Most of the alpha numeric LCD like 16x2 char or 16x4 char has ability to generate few custom characters. In this example i will show you how to make and display these custom characters on a 16x2 char led.




THEORY FOR CUSTOM CHARACTER GENERATION 

the basic technology of lcd based on 3 type of   memory

CG ROM : this the memory which holds the permanent fonts you call to be displayed . this holds the pattern for every single character of  predefined lcd font. and you call the content of this memory by the placing corresponding ascii value on the lcd port . like for retrieval of   'A' you have to send the ascii value of 'A' which is 0x41 to the lcd.   CGROM can also be seen as computer hard drive from where you load your required program into ram to start working. but it is not modify able because it's rom.

DD RAM : DDRAM is the memory which holds only those characters which are currently on the screen . means if there is a message is currently being displayed on the screen then it has to be  on the DDRAM for example if you want to display "hello" on the screen then you have load pattern of h from the CG ROM TO DD RAM then do the same for 'e' ,'l' ,'l' and 'o'.

the address of cg ram is totally depends on the size of the lcd like for
16 x 2 LCD    Row1      0x80 0x81 0x82 0x83 0x84 0x85 0x86 through 0x8F
                    Row2     0xCO 0xC1 0xC2 0xC3 0xC4 0xC5 0xC6 through 0xCF

20 x 1 LCD    Row1     0x80 0x81 0x82 0x83 through 0x93
20 x 2 LCD    Row1     0x80 0x81 0x82 0x83 through 0x93
                    Row2     0xCO 0xC1 0xC2 0xC3 through 0xD3

20 x 4 LCD    Row1     0x80 0x81 0x82 0x83 through 0x93
            Row2     0xCO 0xC1 0xC2 0xC3 through 0xD3
                    Row3     0x94 0x95 0x96 0x97 through 0xA7
                    Row4     0xD4 0xD5 0xD6 0xD7 through 0xE7

40 x 2 L CD   Row1     0x80 0x81 0x82 0x83 through 0xA7
                    Row2     0xCO 0xC1 0xC2 0xC3 through 0xE7

CG RAM : this memory works same as CG ROM but as this is ram we can modify it's content any time . so this is the place where whe have to first store our custom character pattern. then that pattern can be sent to display. the HD44780 has total 8 CG RAM memory location . so we can generate only up to 8 custom characters . but you can always change the content of CG RAM on the fly to generate new characters. the addresses of 8 CG RAM location  goes from  0x00 to 0x07.
WHEN Ever we want something of these fonts to be displayed on the screen we write them to the DD RAM.

HOW TO DECIDE AND WRITE CUSTOM FONT TO CG RAM  ?

A standard 5x8 dots font is being shown in the image as you can see there are total 8 bytes of data on the whole to decide pattern of the font. As you can see all you need to do is decide the first row pattern like in the example image in first row the first pixel is off  so lsb bit 0 is 0 and pixel 1 is on so bit1 is 1 and pixel 2 is on so bit 2 is 1 this method apply on each row of the font ( 8 rows ). which gives us total 8 bytes of data first msb 3 bits are always 0. you can also use BASCOM AVR to decide this pattern  and code.










Program:

Lcd.h

#ifndef _leddatas_H
#define _leddatas_H

#include <reg51.h>

sbit lcd_en = P3^3;
sbit lcd_rs = P3^2;

void lcd_delay(unsigned char ms)
{
        unsigned char n;
        unsigned int i;
        for (n=0; n<ms; n++)
        {
                for (i=0; i<1272; i++);
        }
}

void lcd_enable()
{
    lcd_en = 0;
    lcd_delay(1);
    lcd_en = 1;
}

void lcd_command(unsigned char command)
{
    lcd_rs = 0;
    P2 = (P2 & 0x0f)|(((command>>4) & 0x0F)<<4);
    lcd_enable();
    P2 = (P2 & 0x0f)|((command & 0x0F)<<4);
    lcd_enable();
    lcd_delay(1);
}

void lcdinit()
{
    lcd_en = 1;
    lcd_rs = 0; 
    lcd_command(0x33);
    lcd_command(0x32);
    lcd_command(0x28);
    lcd_command(0x0C);
    lcd_command(0x06);
    lcd_command(0x01);
    lcd_delay(25);
}

void lcd_datac(unsigned char ascii)
{
    lcd_rs = 1;
    P2 = (P2 & 0x0f)|(((ascii>>4) & 0x0F)<<4);
    lcd_enable();
    P2 = (P2 & 0x0f)|((ascii & 0x0F)<<4);
    lcd_enable();
    lcd_delay(1);
}

void lcdrow(unsigned char no)
{
        if (no == 1)
        {     
                lcd_command(0x80);
        }
        if (no ==2)
        {
                lcd_command(0xC0);
        }
}

void lcddatas (unsigned char row,unsigned char *lcdstring)
{
        lcdrow(row);
        while (*lcdstring)
        {
                lcd_datac(*lcdstring++);
        }
}

void lcdblink(unsigned char no,unsigned char *lcdstring)
{
        unsigned char j;
        for(j=0;j<no;j++)
        {
        lcd_command(0x01);
        lcd_delay(50);
        lcddatas(1,lcdstring);
        lcd_delay(50);
        }
}

void lcdrotade(unsigned char no,unsigned char dir,unsigned char *lcdstring)
{
        unsigned char i;
        lcddatas(no,lcdstring);
        if (dir == 'l')
        {
                for (i=0;i<16;i++)
                {
                lcd_delay(100);
                lcd_command(0x18);
                }
        }
        if (dir == 'r')
        {
                for (i=0;i<16;i++)
                {
                lcd_delay(100);
                lcd_command(0x1C);
                }
        }     
}
       
void special_char(unsigned char cgram_loc, unsigned char lcd_loc, unsigned char *datas)
{
        unsigned int i=0;
        lcd_command(cgram_loc);                  
        while(i<8)
        {
                lcd_datac(datas[i]);            
                i++;
        }
        lcd_command(lcd_loc);                       
        lcd_datac((cgram_loc-64)/8);       
}

#endif

Lcd.c

#include <reg51.h>
#include "lcd.h"

unsigned char data1[]={28,2,2,28,8,4,3,32};
unsigned char data2[]={16,16,16,16,16,16,16,16};
unsigned char data3[]={17,9,5,31,21,29,1,32};
unsigned char data4[]={4,4,4,28,4,4,4,4};

void main( )
{   
        lcdinit();
        lcd_command(0x85);
        lcd_datac('"');
        special_char(64,0x86,data1);
        special_char(72,0x87,data2);
        special_char(80,0x88,data3);
        lcd_command(0x889);
        lcd_datac('"');
        while(1) {}
}


U can also download all sour coda and also emulation file from here.

so keep exploring 8051.....

see video of emulation