Cgram 1602 can store 8 custom characters, the first address of the 8 custom character storage spaces is: 0x40,0x48,0x50,0x58,0x60,0x68,0x70,0x78. With 0x40
, it's storage space
:
If you use the 5*7 character, then the leftmost 3-bit and last-line data is actually useless, usually 0. If you want to customize a ℃ symbol, then fill the box first (Red 1 white 0)
Use these codes to populate the Cgram
Use the 8*8 software to draw two characters below the sample code
#include <reg51.h>
#include <string.h>
#include <intrins.h>
#define UINT unsigned int
#define UCHAR unsigned char
#define Data P0 Data port
Sbit en=p2^2; e Pulse control Signal port
Sbit rs=p2^0; Command Control port
Sbit rw=p2^1; Read/write Control port
Uchar t_code1[]={0x15,0x1f,0x04,0x04,0x1c,0x11,0x1f,0x00};//Custom code in a 5*7 lattice
Uchar t_code2[]={0x15,0x1f,0x04,0x00,0x04,0x1f,0x15,0x00};
void Read_sta ()//Read state
{
UINT j=1000;//Timeout variable
data=0x80;
rs=0; Rs=0 rw=1 e=1 Read status
Rw=1;
En=1;
while ((data&0x80) &&j--) _nop_ ();//Busy is waiting for a NOP probably 1us with above j=1000 do 1ms timeout judgment
en=0; En pull Low
}
void write_com (Uchar com)
{
Read_sta (); Read Busy signal
rs=0; Write command rs=0 write data Rs=1
rw=0; Write RW all for 0
data=com; Put the data you want to write on the data port.
en=0; e a positive pulse to write a data so-called a positive pulse is an e from the 0->1->0 of a low-high transformation so here first pull down en=0
En=1;
en=0;
}
void Write_data (Uchar date)
{
Read_sta ();
Rs=1; Rs=1 Writing data
rw=0;
Data=date;
en=0; Ditto
En=1;
en=0;
}
void Lcd1602_init ()
{
Write_com (0x38);8-bit data port, two-line display, 5*7 lattice characters
Write_com (0x0c); No cursor does not blink
Write_com (0x06); Read and write pointer plus 1 screen does not move 0101
Write_com (0x01); Clear screen cursor return to 00H position
}
void Main ()
{
Uchar Flag=0,off_on=1,i;
Lcd1602_init ();
for (i=0;i<8;i++)
{
Write_com (0x40+i); Address 0x40-0x78 8 corresponds to one character
Write_data (T_code1[i]);
}
for (i=0;i<8;i++)
{
Write_com (0x78+i); Address 0x40-0x78 8 corresponds to one character write the eighth character
Write_data (T_code2[i]);
}
for (i=0;i<16;i++)
{
Write_com (0x80+i); Line
Write_data (0x00); 0x00 is the first one
}
for (i=0;i<16;i++)
{
Write_com (0x80+0x40+i); Second line
Write_data (0x07); 0X07 is the 8th because it's starting from 0.
}
while (1)
{
}
}
LCD1602 Custom Bitmap characters