液晶显示字符是不可少的,对于3510,自身没有字库,需要自己建,我用了LCDzimo取模,采用点阵显示。
//LCD3510.C
#include
#include "mytype.h"
#include "math.h"
#include "lcd3510.h"
#include "ascii.h"
#include "uart.h"
uint8 table[16]={"0123456789abcdef"};
void DelayXms(uint16 x)
{
uint8 i;
while(x--)
{
i="1275";
while(i--);
}
}
/************************************************************** ************
液晶硬件复位
******************************************************************************/
void LcdReset(void)
{
ClrLcdRst();
DelayXms(5);
SetLcdRst();
DelayXms(5);
}
/**************************************************************************************************
发送命令
******************************************************************************************************/
void LcdSendCommand(uint8 cmd)
{
uint8 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
ClrLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(cmd & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
cmd<<=1;
}
}
/*****************************************************************************
发送数据
****************************************************************************************/
void LcdSendData(uint32 Data)
{
uint32 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
SetLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(Data & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
Data<<=1;
}
}
/***************************************************************************
液晶端口初始化
************************************************************************/
void LcdPortInit(void)
{
DDR4|=((1<DDR2|=((1<SetLcdRst();
SetLcdCs();
SetLcdSclk();
}
/**********************************************************************
液晶初始化
*************************************************************************/
void LcdInit(void)
{
uint8 i;
LcdPortInit();
LcdReset();
LcdSendCommand(0x01); //soft reset
SetLcdCs();
DelayXms(5);
LcdSendCommand(0xc6); //initial escape
SetLcdCs();
LcdSendCommand(0xb9); //refresh set
LcdSendData(0x00);
SetLcdCs();
LcdSendCommand(0xb6); //display control
LcdSendData(0x80);
LcdSendData(0x80);
LcdSendData(0x81);
LcdSendData(84);
LcdSendData(69);
LcdSendData(82);
LcdSendData(67);
SetLcdCs();
LcdSendCommand(0xb3); //gray scale position set
LcdSendData(1);
LcdSendData(2);
LcdSendData(4);
LcdSendData(8);
LcdSendData(16);
LcdSendData(30);
LcdSendData(40);
LcdSendData(50);
LcdSendData(60);
LcdSendData(70);
LcdSendData(80);
LcdSendData(90);
LcdSendData(100);
LcdSendData(110);
LcdSendData(127);
SetLcdCs();
LcdSendCommand(0xb5); //gamma curve set
LcdSendData(0x01);
SetLcdCs();
LcdSendCommand(0xbd); //common driver output select
LcdSendData(0x00);
SetLcdCs();
LcdSendCommand(0xbe); //power control
LcdSendData(0x04);
SetLcdCs();
LcdSendCommand(0x11); //sleep out
SetLcdCs();
LcdSendCommand(0xba); //voltage control
LcdSendData(127);
LcdSendData(3);
SetLcdCs();
LcdSendCommand(0xb7); //temperature gradient set
for(i=0; i<14; i++)
{
LcdSendData(0x00);
}
SetLcdCs();
LcdSendCommand(0x29); //display ON
SetLcdCs();
LcdSendCommand(0x03); //booster voltage ON
SetLcdCs();
DelayXms(5);
LcdSendCommand(0x20); //display inversion OFF
SetLcdCs();
LcdSendCommand(0x25); //write contrast
LcdSendData(63);
SetLcdCs();
}
/* ************************************************************************
液晶清屏
*****************************************************************************/
void LcdClr(void)
{
uint8 x, y;
LcdSendCommand(0x2a); //column address set
LcdSendData(0);
LcdSendData(97);
SetLcdCs();
LcdSendCommand(0x2b); //page address set
LcdSendData(0);
LcdSendData(66);
SetLcdCs();
LcdSendCommand(0x2c); //memory write
for(y=0;y<67;y++)
{
for(x=0;x<98;x+=2)
{
LcdSendData(0);
LcdSendData(0);
LcdSendData(0);
}
}
SetLcdCs();
}
/*******************************************************************************************
画点
*******************************************************************************************/
void LcdPointWrite(uint8 x, uint8 y,uint8 rr,uint8 gg,uint8 bb)
{
uint8 b1,b2;
b1=~(((rr<<4)&0xf0)|(gg&0x0f));
b2=~(((bb<<4)&0xf0)|(rr&0x0f));
LcdSendCommand(0x2a); //column address set
LcdSendData(x);
LcdSendData(x);
SetLcdCs();
LcdSendCommand(0x2b); //page address set
LcdSendData(y);
LcdSendData(y);
SetLcdCs();
LcdSendCommand(0x2c); //memory write
LcdSendData(b1);
LcdSendData(b2);
SetLcdCs();
}
/**************************************************************************
16*8字符
***************************************************************************/
void LCD_Drawletter(uint8 x,uint8 y,uint8 p,uint8 rr,uint8 gg,uint8 bb)
{
uint8 x1,y1,p1;
for(y1=y;y1<=(y+15);y1++)
{p1=ASCII[(uint16)((uint16)(y1-y)+(uint16)((p-32)*16))];
for(x1=x;x1<=(x+7);x1++)
{if((p1&0x80)==0x80)
LcdPointWrite(x1, y1,rr,gg,bb);
else ;
p1=p1<<1;
}
}
}
//ascii.h
// ------------------ ASCII字模的数据表 ------------------------ //
// 码表从0x20~0x7e //
// 字库: E:\LcmZimo\Asc8X16E.dat 横向取模左高位 //
// -------------------------------------------------------------- //
unsigned char ASCII[] = // ASCII
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // - -
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18, // -!-
0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00, // -"-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x6C,0x6C,0xFE,0x6C,0x6C, // -#-
0x6C,0xFE,0x6C,0x6C,0x00,0x00,0x00,0x00,
0x18,0x18,0x7C,0xC6,0xC2,0xC0,0x7C,0x06, // -$-
0x86,0xC6,0x7C,0x18,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC2,0xC6,0x0C,0x18, // -%-
0x30,0x60,0xC6,0x86,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0x6C,0x38,0x76,0xDC, // -&-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00, // -'-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x18,0x30,0x30,0x30,0x30, // -(-
0x30,0x30,0x18,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x30,0x18,0x0C,0x0C,0x0C,0x0C, // -)-
0x0C,0x0C,0x18,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x66,0x3C,0xFF, // -*-
0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E, // -+-
0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -,-
0x00,0x18,0x18,0x18,0x30,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE, // ---
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -.-
0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x06,0x0C,0x18, // -/-
0x30,0x60,0xC0,0x80,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6, // -0-
0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18, // -1-
0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30, // -2-
0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06, // -3-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE, // -4-
0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E, // -5-
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6, // -6-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18, // -7-
0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6, // -8-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06, // -9-
0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, // -:-
0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00, // -;-
0x00,0x18,0x18,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60, // -<-
0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00, // -=-
0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06, // ->-
0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0x0C,0x18,0x18, // -?-
0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7C,0xC6,0xC6,0xDE,0xDE, // -@-
0xDE,0xDC,0xC0,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x38,0x6C,0xC6,0xC6,0xFE, // -A-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x66, // -B-
0x66,0x66,0x66,0xFC,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x66,0xC2,0xC0,0xC0,0xC0, // -C-
0xC0,0xC2,0x66,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0xF8,0x6C,0x66,0x66,0x66,0x66, // -D-
0x66,0x66,0x6C,0xF8,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0x66,0x62,0x68,0x78,0x68, // -E-
0x60,0x62,0x66,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0x66,0x62,0x68,0x78,0x68, // -F-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x66,0xC2,0xC0,0xC0,0xDE, // -G-
0xC6,0xC6,0x66,0x3A,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xFE,0xC6, // -H-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18, // -I-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x1E,0x0C,0x0C,0x0C,0x0C,0x0C, // -J-
0xCC,0xCC,0xCC,0x78,0x00,0x00,0x00,0x00,
0x00,0x00,0xE6,0x66,0x6C,0x6C,0x78,0x78, // -K-
0x6C,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
0x00,0x00,0xF0,0x60,0x60,0x60,0x60,0x60, // -L-
0x60,0x62,0x66,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xEE,0xFE,0xFE,0xD6,0xC6, // -M-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xE6,0xF6,0xFE,0xDE,0xCE, // -N-
0xC6,0xC6,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0xC6,0xC6,0xC6,0xC6, // -O-
0xC6,0xC6,0x6C,0x38,0x00,0x00,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x60, // -P-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0xC6,0xC6, // -Q-
0xC6,0xD6,0xDE,0x7C,0x0C,0x0E,0x00,0x00,
0x00,0x00,0xFC,0x66,0x66,0x66,0x7C,0x6C, // -R-
0x66,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
0x00,0x00,0x7C,0xC6,0xC6,0x60,0x38,0x0C, // -S-
0x06,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x7E,0x7E,0x5A,0x18,0x18,0x18, // -T-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6, // -U-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6, // -V-
0xC6,0x6C,0x38,0x10,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0xC6,0xC6,0xC6,0xD6, // -W-
0xD6,0xFE,0x6C,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0xC6,0xC6,0x6C,0x6C,0x38,0x38, // -X-
0x6C,0x6C,0xC6,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x18, // -Y-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0xFE,0xC6,0x86,0x0C,0x18,0x30, // -Z-
0x60,0xC2,0xC6,0xFE,0x00,0x00,0x00,0x00,
/*0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30, // -[-
0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x38, // -\-
0x1C,0x0E,0x06,0x02,0x00,0x00,0x00,0x00,
0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C, // -]-
0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00,
0x10,0x38,0x6C,0xC6,0x00,0x00,0x00,0x00, // -^-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -_-
0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,
0x30,0x30,0x18,0x00,0x00,0x00,0x00,0x00, // -`-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0x0C,0x7C, // -a-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0xE0,0x60,0x60,0x78,0x6C,0x66, // -b-
0x66,0x66,0x66,0xDC,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xC0, // -c-
0xC0,0xC0,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x1C,0x0C,0x0C,0x3C,0x6C,0xCC, // -d-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xFE, // -e-
0xC0,0xC0,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x6C,0x64,0x60,0xF0,0x60, // -f-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x76,0xCC,0xCC, // -g-
0xCC,0xCC,0xCC,0x7C,0x0C,0xCC,0x78,0x00,
0x00,0x00,0xE0,0x60,0x60,0x6C,0x76,0x66, // -h-
0x66,0x66,0x66,0xE6,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x18,0x00,0x38,0x18,0x18, // -i-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06, // -j-
0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,
0x00,0x00,0xE0,0x60,0x60,0x66,0x6C,0x78, // -k-
0x78,0x6C,0x66,0xE6,0x00,0x00,0x00,0x00,
0x00,0x00,0x38,0x18,0x18,0x18,0x18,0x18, // -l-
0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xEC,0xFE,0xD6, // -m-
0xD6,0xD6,0xD6,0xD6,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xDC,0x66,0x66, // -n-
0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0xC6, // -o-
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xDC,0x66,0x66, // -p-
0x66,0x66,0x66,0x7C,0x60,0x60,0xF0,0x00,
0x00,0x00,0x00,0x00,0x00,0x76,0xCC,0xCC, // -q-
0xCC,0xCC,0xCC,0x7C,0x0C,0x0C,0x1E,0x00,
0x00,0x00,0x00,0x00,0x00,0xDC,0x76,0x62, // -r-
0x60,0x60,0x60,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0xC6,0x60, // -s-
0x38,0x0C,0xC6,0x7C,0x00,0x00,0x00,0x00,
0x00,0x00,0x10,0x30,0x30,0xFC,0x30,0x30, // -t-
0x30,0x30,0x36,0x1C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC, // -u-
0xCC,0xCC,0xCC,0x76,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66, // -v-
0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0xC6,0xC6, // -w-
0xD6,0xD6,0xFE,0x6C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0x6C,0x38, // -x-
0x38,0x38,0x6C,0xC6,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC6,0xC6,0xC6, // -y-
0xC6,0xC6,0xC6,0x7E,0x06,0x0C,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0xFE,0xCC,0x18, // -z-
0x30,0x60,0xC6,0xFE,0x00,0x00,0x00,0x00,
/*0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18, // -{-
0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00,
0x00,0x00,0x18,0x18,0x18,0x18,0x00,0x18, // -|-
0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00,
0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18, // -}-
0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x76,0xDC,0x00,0x00,0x00,0x00, // -~-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x10,0x38,0x6C,0xC6, // --
0xC6,0xC6,0xFE,0x00,0x00,0x00,0x00,0x00,*/
};
文章评论(0条评论)
登录后参与讨论