CGRAM 1602 can store 8 custom characters. The first addresses of these 8 custom character storage spaces are: 0X40, 0X48, 0X50, 0X58, 0X60, 0X68, 0X70, 0X78. In the case of 0x40, its storage space is as shown
:
If you use 5 * 7 characters, then the data of the leftmost 3 and last lines is actually useless, usually set to 0. If you want to customize a °C symbol, then fill in the box first, as shown in the figure (red 1 white 0)
Fill these codes into CGRAM first when using
Just use the 8*8 modulo software to draw two characters. Below is 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 and write control port
Uchar t_code1[]={0x15,0x1F,0x04,0x04,0x1C,0x11,0x1F,0x00};//Customize a code in a 5*7 dot matrix screenshot
Uchar t_code2[]={0x15,0x1F,0x04,0x00,0x04,0x1F,0x15,0x00};
Void read_sta() //read status
{
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 wait for a nop about 1us with the above j=1000 to do 1ms timeout judgment
En=0; //en pulled 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 are 0
Data=com; // put the data to be written into the data port
En=0; //E A positive pulse writes a data. A positive pulse means a low-low transition of E from 0-"1-"0. So first pull low en=0
En=1;
En=0;
}
Void write_data(uchar date)
{
Read_sta();
Rs=1; //rs=1 write data
Rw=0;
Data=date;
En=0; //same as above
En=1;
En=0;
}
Void lcd1602_init()
{
Write_com(0x38); //8-bit data port, two lines display, 5*7 dot matrix 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 returns 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 corresponding to one character
Write_data(t_code1[i]);
}
For(i=0;i"8;i++)
{
Write_com(0x78+i); //Address 0x40-0x78 8 corresponding characters to write the eighth character
Write_data(t_code2[i]);
}
For(i=0;i"16;i++)
{
Write_com(0x80+i); //one line
Write_data(0x00); //0x00 is the first
}
For(i=0;i"16;i++)
{
Write_com(0x80+0x40+i); //second line
Write_data(0x07); //0x07 is the 8th because it starts from 0
}
While(1)
{
}
}
16+ Years Experience Smart Watch manufacturer, ITOPNOO Provide One-stop Smart Wearable devices Solutions For You.
Our Smart Wearable products include android smart watches, Watch For iPhone, Bracelet and Wristband etc.
Leading healthcare navigation services for individuals and families who are generally healthy or face serious medical issues, and health services for employers.
The Trends New Watches Designs. Custom smart watch products designed with the vision of our clients' brands in mind.
Wholesale smart watches,Best Smart Watches,Gifts Wholesalers, smart watch manufacturer
TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.micbluetooth.com