?? text1.c
字號:
#include <reg51.h>
/*unsigned char table1[]={0x03,0x07,0x0f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x18,0x1E,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x07,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
0x10,0x18,0x1c,0x1E,0x1E,0x1E,0x1E,0x1E,
0x0f,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
0x1f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x01,
0x1f,0x1f,0x1f,0x1f,0x1f,0x1c,0x18,0x00,
0x1c,0x18,0x10,0x00,0x00,0x00,0x00,0x00};//心圖案 */
unsigned char table1[]={0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02, //"年"代碼=00H
0x0F,0x09,0x0F,0x09,0x0F,0x09,0x11,0x00, //"月"代碼=01H
0x1F,0x11,0x11,0x1F,0x11,0x11,0x1F,0x00, //"日"代碼=02H
0x11,0x0A,0x04,0x1F,0x04,0x1F,0x04,0x00, //"$"代碼=03H
0x0E,0x00,0x1F,0x0A,0x0A,0x0A,0x13,0x00, //"元"代碼=04H
0x18,0x18,0x07,0x08,0x08,0x08,0x07,0x00, //"℃"代碼=05H
0x04,0x0A,0x15,0x04,0x04,0x04,0x04,0x00, //"↑"代碼=06H
0x17,0x15,0x15,0x15,0x15,0x15,0x17,0x00}; //字符℃
unsigned char table[]={0x10,0x06,0x09,0x08,0x08,0x09,0x06,0x00};
#define CLEARSCREEN LCD_write_command(0x01)
/**************定義接口************************/
#define LCDIO P1
sbit LCD1602_RS=P3^4;
sbit LCD1602_RW=P3^5;
sbit LCD1602_EN=P3^6;
/**************定義函數************************/
void LCD_write_command(unsigned char command);//寫入指令函數
void LCD_write_dat(unsigned char dat);//寫入數據函數
void LCD_set_xy( unsigned char x, unsigned char y );//設置顯示位置函數
void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//顯示一個字符函數
void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//顯示字符串函數
void LCD_init(void);//初始化函數
void delay_nms(unsigned int n);//延時函數
/********************************************/
/************初始化函數****************/
void LCD_init(void)
{
CLEARSCREEN;//clear screen
LCD_write_command(0x38);//set 8 bit data transmission mode
LCD_write_command(0x0c);//open display (enable lcd display)
LCD_write_command(0x80);//set lcd first display address
CLEARSCREEN;//clear screen
}
/****************************************************/
/**************寫指令函數********************************/
void LCD_write_command(unsigned char command)
{
LCDIO=command;
LCD1602_RS=0;
LCD1602_RW=0;
LCD1602_EN=0;
LCD1602_EN=1;
delay_nms(10);
}
/***************************************************/
/****************寫數據函數************************/
void LCD_write_dat(unsigned char dat)
{
LCDIO=dat;
LCD1602_RS=1;
LCD1602_RW=0;
LCD1602_EN=0;
delay_nms(1);
LCD1602_EN=1;
}
/****************************************************/
/***************設置顯示位置**************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == 1)
address = 0x80 + x;
else
address =0xc0+ x;
LCD_write_command(address);
}
/***************************************************/
/****************顯示一個字符**********************/
void LCD_dsp_char( unsigned char x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_write_dat(dat);
}
/**********************************************/
/***************顯示字符串函數***************/
void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_write_dat(*s);
s ++;
}
}
/***********************************************/
/********** 延時**********************/
void delay_nms(unsigned int n)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<10;j++);
}
/**************************************/
/***********主函數**************/
void main(void)
{
unsigned char i,j,k,tmp;
LCD_init();
delay_nms(100);
tmp=0x40;//設置CGRAM地址的格式字 CGRAM地址格式很復雜 01 000 000 01是固定的 左起第一個000是代碼的大小,最后的000是個偏移量(存儲每個代碼數據的偏移量)
k=0;
for(j=0;j<8;j++) {
for(i=0;i<8;i++) {
LCD_write_command(tmp+i); // 設置自定義字符的 CGRAM 地址
delay_nms(2);
LCD_write_dat(table1[k]); // 向CGRAM寫入自定義字符表的數據
k++;
delay_nms(2);
}
tmp=tmp+8; //寫完00H的8個數據后,轉入寫01H的8個數據
}
LCD_dsp_string(1,1,"LCD TEST ");//
LCD_dsp_string(1,2,"SUCCESSFUL ");//
for (i=0;i<4;i++)
{
LCD_dsp_char( 12+i,1,i);//在第一行第12列位置顯示心圖案的上半部
delay_nms(1);
}
for (i=4;i<8;i++)
{
LCD_dsp_char( 12+i-4,2,i);//在第二行第12列位置顯示心圖案的下半部
delay_nms(1);
}
for(i=0;i<30;i++){
delay_nms(1000);
}
CLEARSCREEN;
LCD_dsp_string(0,1,"XIONGJIALE");
LCD_dsp_string(5,2,"ICEXIONG");
while (1);
}
/********************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -