Thursday, May 26, 2016

Custom characters on 16x2 L

Hi,today we aredisplayCustom characters on 16x2 we are using tow good softwarekeilandproteussame as older postl interfasing.

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


thebasic technology of l based on 3 type of memory
CG ROM: this the memory which holds the permanent fonts you call to be displayed . thisholdsthe pattern foreverysingle character of predefined l font. and you call the content of this memory by the placingcorresponding ascii value on the l port . like for retrieval of 'A' you have to send the ascii value of 'A' which is 0x41 to the l. 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 . mns if there is a message is currently being displayed on thescreen then it has to beon the DDRAM for example if you want to display "hello" on the screen thenyou 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 l like for16 x 2 LRow1 0x80 0x81 0x82 0x83 0x84 0x85 0x86 through 0x8F Row2 0xCO 0xC1 0xC2 0xC3 0xC4 0xC5 0xC6 through 0xCF
20 x 1 L Row1 0x80 0x81 0x82 0x83 through 0x93 20 x 2 L Row1 0x80 0x81 0x82 0x83 through 0x93 Row2 0xCO 0xC1 0xC2 0xC3 through 0xD3
20 x 4 L 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 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 loion . so we canerateonly up to 8 custom characters . but you can always change the content of CG RAM on the fly toeratenew characters. the addresses of 8 CG RAM loion 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.
A standard 5x8 dots font is being shown in the 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 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 ch 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 .

#ifndef _leddatas_H#define _leddatas_H
#include <reg51.h>
sbit l_en = P3^3;sbit l_rs = P3^2;
void l_delay(unsigned char ms){ unsigned char n; unsigned int i; for (n=0; n<ms; n++) { for (i=0; i<1272; i++); }}
void l_enable(){ l_en = 0; l_delay(1); l_en = 1; }
void l_command(unsigned char command){ l_rs = 0; P2 = (P2 & 0x0f)|(((command>>4) & 0x0F)<<4); l_enable(); P2 = (P2 & 0x0f)|((command & 0x0F)<<4); l_enable(); l_delay(1);}
void linit(){ l_en = 1; l_rs = 0; l_command(0x33); l_command(0x32); l_command(0x28); l_command(0x0C); l_command(0x06); l_command(0x01); l_delay(25);}
void l_datac(unsigned char ascii){ l_rs = 1; P2 = (P2 & 0x0f)|(((ascii>>4) & 0x0F)<<4); l_enable(); P2 = (P2 & 0x0f)|((ascii & 0x0F)<<4); l_enable(); l_delay(1);}
void lrow(unsigned char no){ if (no == 1) { l_command(0x80); } if (no ==2) { l_command(0xC0); }}
void ldatas (unsigned char row,unsigned char *lstring){ lrow(row); while (*lstring) { l_datac(*lstring++); }}
void lblink(unsigned char no,unsigned char *lstring){ unsigned char j; for(j=0;j<no;j++) { l_command(0x01); l_delay(50); ldatas(1,lstring); l_delay(50); }}
void lrotade(unsigned char no,unsigned char dir,unsigned char *lstring){ unsigned char i; ldatas(no,lstring); if (dir == 'l') { for (i=0;i<16;i++) { l_delay(100); l_command(0x18); } } if (dir == 'r') { for (i=0;i<16;i++) { l_delay(100); l_command(0x1C); } } } void special_char(unsigned char cgram_loc, unsigned char l_loc, unsigned char *datas){ unsigned int i=0; l_command(cgram_loc); while(i<8) { l_datac(datas[i]); i++; } l_command(l_loc); l_datac((cgram_loc-64)/8); }
#include <reg51.h>#include "l.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( ){ linit(); l_command(0x85); l_datac('"'); special_char(64,0x86,data1); special_char(72,0x87,data2); special_char(80,0x88,data3); l_command(0x889); l_datac('"'); while(1) {}}

U can also download all sourcodaand alsoemulationfile fromhere.
so keep exploring 8051.....
see of emulation

No comments:

Post a Comment