📄 5110.c
字号:
#include<reg52.h>
#include<all.h>
#include<ziku.h>
#define uchar unsigned char
#define uint unsigned int
sbit sce = P2^4; //片选
sbit res = P2^3; //复位,0复位
sbit dc = P2^2; //1写数据,0写指令
sbit sdin = P2^1; //数据
sbit sclk = P2^0; //时钟
void delay_1ms(void)//1ms延时函数
{
unsigned int i;
for (i=0;i<500;i++) ;
;
}
/*--------------------------------------------
LCD_write_byte: 使用SPI接口写数据到LCD
输入参数:dt:写入的数据;
command :写数据/命令选择;
编写日期:20080918
----------------------------------------------*/
void LCD_write_byte(unsigned char dt, unsigned char command)
{
unsigned char i;
sce=0; //片选
dc=command; //command为1写数据,0写指令
for(i=0;i<8;i++) //模拟串行口发送数据,高位在前,低位在后
{
if(dt&0x80) //按位与,dt
sdin=1; //数据 最高位为1,发送1
else
sdin=0; //最高位为0,发送0
dt=dt<<1;
sclk=0;
sclk=1; //时钟
}
dc=1; //1写数据,0写指令
sce=1;
sdin=1;
}
/*---------------------------------------
LCD_init: 3310LCD初始化
编写日期:20080918
----------------------------------------- */
void LCD_init(void)
{
res=0; //片选
delay_1ms();
res=1;
LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
LCD_write_byte(0xd0,0);//设定液晶偏置电压
LCD_write_byte(0x20,0);//使用基本指令
LCD_write_byte(0x0C,0);//设定显示模式,正常显示
}
/*-------------------------------------------
LCD_set_XY: 设置LCD坐标函数
输入参数:X:0-83 Y:0-5
编写日期:20080918
---------------------------------------------*/
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0);// column
LCD_write_byte(0x80 | X, 0);// row
}
/*------------------------------------------
LCD_clear: LCD清屏函数
编写日期:20080918
--------------------------------------------*/
void LCD_clear(void)
{
unsigned char t;
unsigned char k;
LCD_set_XY(0,0);
for(t=0;t<6;t++)
{
for(k=0;k<84;k++)
{
LCD_write_byte(0x00,1);
}
}
}
/*---------------------------------------------
LCD_write_shu: 显示8(宽)*16(高)点阵列数字字母符号等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_shu(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i;
LCD_set_XY(row*8, page);// 列,页
for(i=0; i<8;i++)
{
LCD_write_byte(shuzi[c*16+i],1);
}
LCD_set_XY(row*8, page+1);// 列,页
for(i=8; i<16;i++)
{
LCD_write_byte(shuzi[c*16+i],1);
}
}
/*---------------------------------------------
LCD_write_hanzi: 显示16(宽)*16(高)点阵列汉字等半角类
输入参数:c:显示的字符;
编写日期:20080918
-----------------------------------------------*/
void LCD_write_hanzi(unsigned char row, unsigned char page,unsigned char c) //row:列 page:页 dd:字符
{
unsigned char i;
LCD_set_XY(row*12, page);// 列,页
for(i=0; i<12;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
LCD_set_XY(row*12, page+1);// 列,页
for(i=12; i<24;i++)
{
LCD_write_byte(hanzi[c*24+i],1);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -