本帖最后由 15980990470 于 2016-6-23 17:19 编辑
int LCD_CE=7;
int LCD_RST=6;
int SCLK=3;
int SDIN=4;
int LCD_DC=5;
int xz[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,};
int c[]={0x00,0x00,0x00,0x00,0x00,0x90,0x90,0x90,0xF2,0xFE,0xFE,0x5E,0x48,0x48,0x48,0x48,
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8C,0xCC,0xE4,0x7C,0x7E,
0x5F,0x67,0xE6,0xF2,0xB6,0xBE,0x9E,0xBB,0x73,0xE3,0xE2,0xC0,0xC0,0x80,0x80,0x80,
0x0C,0x0E,0x07,0x43,0x61,0x33,0x3B,0x1D,0x0F,0x77,0xFF,0xFF,0x05,0x0C,0x1D,0x39,
0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,};//秦字24x24
int arduino[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0xF0,0xF8,0xFC,0xFE,0xFF,0x7F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x3F,
0x3F,0x7F,0xFF,0xFE,0xFC,0xF8,0xF8,0xE0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF,0x7F,0x3F,
0x3F,0x1F,0x9F,0x9F,0x9F,0x9F,0x1F,0x1F,0x3F,0x7F,0xFF,0xFE,0xFC,0xF8,0xF0,0xE0,
0xFF,0xFF,0xFF,0xFF,0xFF,0xE1,0x80,0x00,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,0x1E,
0x1E,0x80,0xC0,0xE1,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE1,0xC0,0x80,0x1E,
0x1E,0x1E,0x7F,0x7F,0x7F,0x7F,0x1E,0x1E,0x00,0x80,0xC0,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x03,0x07,0x0F,0x1F,0x3F,0x3F,0x7F,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,
0x7F,0x3F,0x3F,0x1F,0x0F,0x07,0x07,0x01,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x3F,0x7F,
0x7F,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x7F,0x3F,0x3F,0x1F,0x0F,0x07,0x03,0x01,
0x00,0xF8,0xFC,0xCE,0xCE,0xFC,0xF8,0x00,0xFC,0xFE,0x66,0xFE,0xDC,0x00,0xFE,0xFE,
0x86,0x86,0xFE,0xFC,0x00,0xFE,0xFE,0xC0,0xC0,0xFE,0xFE,0x00,0x86,0x86,0xFE,0xFE,
0x86,0x86,0x00,0xFE,0xFC,0x38,0x70,0xFE,0xFE,0x00,0x78,0xFC,0x86,0x86,0xFC,0x78,
0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x00,0x01,0x01,
0x01,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x01,0x01,0x01,0x01,
0x01,0x01,0x00,0x01,0x01,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x01,0x01,0x00,0x00
,};//arduino图标48x48
/************************LCD初始化函数********************************/
void LCD_init(void)
{
//先设置为输出
pinMode(SCLK,OUTPUT);
pinMode(SDIN,OUTPUT);
pinMode(LCD_DC,OUTPUT);
pinMode(LCD_CE,OUTPUT);
pinMode(LCD_RST,OUTPUT);
// 产生一个让LCD复位的低电平脉冲
digitalWrite( LCD_RST, LOW);
delayMicroseconds(1);
digitalWrite( LCD_RST, HIGH);
// 关闭LCD
digitalWrite( LCD_CE, LOW);
delayMicroseconds(1);
// 使能LCD
digitalWrite( LCD_CE, HIGH); //LCD_CE = 1;
delayMicroseconds(1);
LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式
LCD_write_byte(0xc8, 0); // 设置偏置电压
LCD_write_byte(0x06, 0); // 温度校正
LCD_write_byte(0x13, 0); // 1:48
LCD_write_byte(0x20, 0); // 使用基本命令
LCD_clear(); // 清屏
LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示
// 关闭LCD
digitalWrite( LCD_CE, LOW); //LCD_CE = 0;
}
/************************LCD清屏函数*******************************/
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
{
LCD_write_byte(0, 1);
}
}
/*************************设置字符位置函数**************************/
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_write_byte : 写数据到LCD
输入参数:data :写入的数据;
command :写数据/命令选择;
---------------------------------------------*/
void LCD_write_byte(unsigned char dat, unsigned char command)
{
unsigned char i;
digitalWrite( LCD_CE, LOW); // 使能LCD_CE = 0
if (command == 0)
{
digitalWrite( LCD_DC, LOW);// 传送命令 LCD_DC = 0;
}
else
{
digitalWrite( LCD_DC, HIGH);// 传送数据LCD_DC = 1;
}
for(i=0;i<8;i++)
{
if(dat&0x80)
{
digitalWrite( SDIN, HIGH);
}
else
{
digitalWrite( SDIN, LOW);;
}
digitalWrite( SCLK, LOW);/
dat = dat << 1;
digitalWrite( SCLK, HIGH);/
}
digitalWrite( LCD_CE, HIGH);
}
void point (int x,int y)//点函数
{
LCD_set_XY(x,int(y/8));
LCD_write_byte(xz[int(y%8)],1);
}
void ht (int x,int y ,int xc,int yc,int *l)//xy图片左上角点的x(0-83)y(0-5)值,xc为图标的宽度,yc为图标的长度,l为点阵数据
{
int i;
int ii;
int ys = yc/8;
for(ii=0;ii<ys;ii+=1)
{
for (i=ii*xc+0;i<xc+ii*xc;i++)
{
LCD_set_XY(x+int(i%xc),y+ii);
LCD_write_byte(l,1);
}
}
}
void setup()
{
LCD_init();
LCD_clear();
}
void loop()
{
ht(5,0,48,48,arduino);
ht(60,2,24,24,c);
point(83,47);
}
ht函数的的y取值只能为0到5对应第一行到第六行,与x0到83不同,这是因为5110屏幕只能是纵向取模,以纵向上的8个像素点为一个单位,0x00到0xff则是表示着一个单位的不同状态,所以液晶使用的字符活图像的高度只能为8的倍数,48/8=6.
再说说point函数,它可以直接屏幕使x轴定义域为0到83,y轴定义域0到47不是0到5,可以直接用一些基础的方程
|