楼主,我见好多液晶的帖子都是您解决的,能帮我分析什么问题会是这样的效果吗?谢谢!完整的程序如下:
#include "iom64v.h"
#include "LCD.h"
//#include "Data.h"
//主控单片机型号Atmega64;
//晶振:内部晶振8MHz,程序烧写时选择合适的选项;
//时钟周期: T1=1/fosc=1/8M;
//#pragma data:code
// 0 1 2 3 4 5 6 7 8 9
extern const char time[]={0x3F, 0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,};
//extern const char text[]={0x06,0x16,0x06,0x16,0x06,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0x61,0xFF,0X0F};
extern const char text[]={0x60,0x61,0x60,0x61,0x60,0x16,0x16,0x16,0x16,0x16,16,0x16,0x16,0xFF,0XF0};
extern const char ON[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF};
extern const char OFF[]={0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00};
/*================大玻璃數據======================*/
extern const char BigData1[]={0XE0,0XE0,0XE0,0XE0,0XE0,0X06,0X07,0X07,0X07,0X07,0X07,0X07};
extern const char BigData2[]={0XBE,0XBE,0XBE,0XBE,0XBE,0XEB,0X7D,0X7D,0X7D,0X7D,0X7D,0X7D};
extern const char BigData3[]={0XFA,0XFA,0XFA,0XFA,0XFA,0XAF,0X5F,0X5F,0X5F,0X5F,0X5F,0X5F};
extern const char BigData4[]={0XE3,0XE3,0XE3,0XE3,0XE3,0X3E,0XC7,0XC7,0XC7,0XC7,0XC7,0XC7};
extern const char BigData5[]={0XDB,0XDB,0XDB,0XDB,0XDB,0XBD,0XDB,0XDB,0XDB,0XDB,0XDB,0XDB};
extern const char BigData6[]={0XDF,0XDF,0XDF,0XDF,0XDF,0XFD,0XFB,0XFB,0XFB,0XFB,0XFB,0XFB};
extern const char BigData7[]={0XF0,0XF0,0XF0,0XF0,0XF0,0X0F,0X0F,0X0F,0X0F,0X0F,0X0F,0X0F};
extern const char BigData8[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF};
extern const char BigData9[]={0XFB,0XFB,0XFB,0XFB,0XFB,0XBF,0XDF,0XDF,0XDF,0XDF,0XDF,0XDF};
//================小玻璃數據======================
extern const char SmaData1[]={0XE0,0XE0,0X0E,0X0E};
extern const char SmaData2[]={0XBE,0XBE,0XEB,0XEB};
extern const char SmaData3[]={0XFA,0XFA,0XAF,0XAF};
extern const char SmaData4[]={0XE3,0XE3,0X3E,0X3E};
extern const char SmaData5[]={0XDB,0XDB,0XBD,0XBD};
extern const char SmaData6[]={0XDF,0XDF,0XFD,0XFD};
extern const char SmaData7[]={0XF0,0XF0,0X0F,0X0F};
extern const char SmaData8[]={0XFF,0XFF,0XFF,0XFF};
extern const char SmaData9[]={0XFB,0XFB,0XBF,0XBF};
//#pragma data:data
/*============================================
函数功能:延时函数
入口参数:无
返回参数:无
备 注:延时时间1ms
============================================*/
void Delay_1ms (volatile uint cuont)
{
volatile uchar j;
volatile uint i;
for(i=cuont;i>0;i--)
{
for(j=100;j>0;j--)
{;}
}
}
/*============================================
函数功能:写ID
入口参数:ID号,模式
返回参数:无
备 注:写完ID后,写CMD,CS不能拉高
============================================*/
void Write_ID(volatile uchar ID)
{
volatile uchar i,jemp;
SET_LCD_WR;
Delay_1ms(3);
for(i=0;i<3;i++)
{
CLR_LCD_WR; // /WR=0;
Delay_1ms(3);
jemp=(ID<<i)&0x04;
if(jemp==0x04)
{
SET_LCD_DATA; //DATA=1;
Delay_1ms(1);
}
else
{
CLR_LCD_DATA; //DATA=0;
Delay_1ms(1);
}
SET_LCD_WR; // /WR=1;
Delay_1ms(3);
}
}
/*============================================
函数功能:写命令
入口参数:CMD:指令数据
返回参数:无
备 注:无
============================================*/
void Write_CMD(volatile uchar CMD)
{
volatile uchar i,jemp;
SET_LCD_WR;
Delay_1ms(5);
for(i=0;i<8;i++)
{
CLR_LCD_WR; // /WR=0;
Delay_1ms(3);
jemp=(CMD<<i)&0x80;
if(jemp==0x80)
{
SET_LCD_DATA; //DATA=1;
Delay_1ms(3);
}
else
{
CLR_LCD_DATA; //DATA=0;
Delay_1ms(3);
}
SET_LCD_WR; // /WR=1;
Delay_1ms(3);
}
CLR_LCD_DATA;
Delay_1ms(3);
CLR_LCD_WR;
Delay_1ms(3);
SET_LCD_WR; //WR=1;
Delay_1ms(3);
}
/*============================================
函数功能:写地址
入口参数:ADR:起始地址
返回参数:无
备 注:无
============================================*/
void Write_Adr(volatile uchar Adr)
{
volatile uchar i,jemp;
Write_ID(0x05);
//CLR_LCD_WR;
//Delay_1ms(5);
//CLR_LCD_DATA; //DATA=0;
//Delay_1ms(1);
for(i=0;i<6;i++)
{
CLR_LCD_WR; //WR=1;
Delay_1ms(3);
jemp=(Adr>>(5-i))&0x01;
if(jemp==0x01)
{
SET_LCD_DATA; //DATA=1;
//Delay_1ms(3);
}
else
{
CLR_LCD_DATA; //DATA=0;
//Delay_1ms(3);
}
//Delay_1ms(2);
SET_LCD_WR;
Delay_1ms(3);
}
}
/*============================================
函数功能:写数据
入口参数:Dat:数据,每写4bit后,地址自动++
返回参数:无
备 注:无
============================================*/
void Write_Data(volatile uchar Dat)
{
volatile uchar i,jemp;
SET_LCD_WR;
Delay_1ms(5);
for(i=0;i<8;i++)
{
CLR_LCD_WR;
Delay_1ms(5);
jemp=(Dat>>i)&0x01;
if(jemp==0x01)
{
SET_LCD_DATA;
Delay_1ms(5);
}
else
{
CLR_LCD_DATA;
Delay_1ms(5);
}
SET_LCD_WR;
Delay_1ms(5);
}
CLR_LCD_WR;
Delay_1ms(5);
}
/*============================================
函数功能:初始化LCD
入口参数:Dat:数据,CMD:操作码,ADR:RAM地址
返回参数:无
备 注:定义模块:(100 0010 1001) 0X0429;
内部RC 振荡方式:(100 0001 1000) 0X0418;
开振荡器:(100 0000 0001) 0X0401;
开显示器:(100 0000 0011) 0X0403;
==============================================*/
void Init_LCD(void)
{
SET_LCD_CS1;
SET_LCD_CS2;
SET_LCD_DATA;
Delay_1ms(3);
//====================初始化U1================
CLR_LCD_CS1;
Write_ID(0x04); //定义模块
Write_CMD(0x29);
SET_LCD_CS1;
Delay_1ms(3);
CLR_LCD_CS1;
Write_ID(0x04); //定义内部振荡方式
Write_CMD(0x18);
SET_LCD_CS1;
Delay_1ms(3);
CLR_LCD_CS1;
Write_ID(0x04);
Write_CMD(0x01); //开振荡器
SET_LCD_CS1;
Delay_1ms(3);
CLR_LCD_CS1;
Write_ID(0x04);
Write_CMD(0x03); //开显示
SET_LCD_CS1;
//====================初始化U2================
Delay_1ms(3);
CLR_LCD_CS2;
Write_ID(0x04); //定义模块
Write_CMD(0x29);
SET_LCD_CS2;
Delay_1ms(3);
CLR_LCD_CS2;
Write_ID(0x04); //定义内部振荡方式
Write_CMD(0x18);
SET_LCD_CS2;
Delay_1ms(3);
CLR_LCD_CS2;
Write_ID(0x04);
Write_CMD(0x01); //开振荡器
SET_LCD_CS2;
Delay_1ms(3);
CLR_LCD_CS2;
Write_ID(0x04);
Write_CMD(0x03); //开显示
SET_LCD_CS2;
Delay_1ms(3);
}
/*============================================
函数功能:不显示"体温、体重"函数
入口参数:无
返回参数:无
备 注:无
============================================*/
void OFF_Addr_IC2(void)
{
volatile uchar i,dat1,dat2,Addr;
CLR_LCD_CS2;
Addr=0x00;
Write_Adr(Addr);
Delay_1ms(3);
for(i=0;i<4;i++)
{
Write_Data(0x00);
}
SET_LCD_CS2;
Delay_1ms(1000);
}
void OFF_Addr_IC1(void)
{
volatile uchar i,dat1,dat2;
CLR_LCD_CS1;
Delay_1ms(3);
Write_Adr(0x00);
for(i=0;i<7;i++)
{
Write_Data(0x00);
}
SET_LCD_CS1;
Delay_1ms(1000);
}
void ON_Addr_IC1(void)
{
volatile uchar i,dat1,dat2,Addr;
SET_LCD_CS2;
CLR_LCD_CS1;
Delay_1ms(3);
Addr=0x00;
Write_Adr(Addr);
for(i=0;i<29;i++)
{
Write_Data(0xFF);
//Addr++;
}
SET_LCD_CS1;
Delay_1ms(1000);
}
/*============================================
函数功能:显示测试
入口参数:无
返回参数:无
备 注:无
============================================*/
void test_Addr_IC1(const char *IC1Data1)
{
volatile uint i,j;
CLR_LCD_CS1;
Delay_1ms(5);
Write_Adr(0x00);
for(i=0;i<12;i++)
{
Write_Data( *IC1Data1);
IC1Data1++;
Delay_1ms(5000);
}
SET_LCD_CS1;
Delay_1ms(5);
}
void test_Addr_IC2(const char *IC2Data2)
{
volatile uint i,j;
CLR_LCD_CS2;
Delay_1ms(5);
Write_Adr(0x00);
for(i=0;i<4;i++)
{
Write_Data(*IC2Data2);
IC2Data2++;
Delay_1ms(5000);
}
SET_LCD_CS2;
Delay_1ms(5);
}
void Show_ON(void)
{
volatile uint i,j;
CLR_LCD_CS1;
Delay_1ms(5);
Write_Adr(0x00);
for(i=0;i<15;i++)
{
Write_Data(0xFF);
}
SET_LCD_CS1;
Delay_1ms(5);
CLR_LCD_CS2;
Delay_1ms(5);
Write_Adr(0x00);
for(j=0;j<16;j++)
{
Write_Data(0xFF);
}
SET_LCD_CS2;
Delay_1ms(5);
}
void Show_OFF(void)
{
volatile uint i,j;
CLR_LCD_CS2;
Delay_1ms(5);
Write_Adr(0x00);
for(j=0;j<16;j++)
{
Write_Data(0x00);
}
SET_LCD_CS2;
Delay_1ms(5);
CLR_LCD_CS1;
Delay_1ms(5);
Write_Adr(0x00);
for(i=0;i<15;i++)
{
Write_Data(0x00);
}
SET_LCD_CS1;
Delay_1ms(5);
}
/*============================================
函数功能:液晶显示函数
入口参数:无
返回参数:无
备 注:无
============================================*/
void LCD_DISPLAY(void)
{
Show_ON();
Show_text(text);
}
/*============================================
函数功能:同时显示大小玻璃数据
入口参数:BigDat:大玻璃数据;SmallDat:小玻璃数据
返回参数:无
备 注:无
============================================*/
void Showdata(const char *BigDat,const char*SmallDat) //显示数据
{
uchar i;
CLR_LCD_CS1;
Write_Adr(0x00);
Delay_1ms(5);
for(i=1;i<12;i++)
{
Write_Data(*BigDat);
BigDat++;
}
SET_LCD_CS1;
Delay_1ms(5);
CLR_LCD_CS2;
Write_Adr(0x00);
for(i=0;i<4;i++)
{
Write_Data(*SmallDat);
SmallDat++;
}
SET_LCD_CS2;
Delay_1ms(5);
}
void Show_text(const char *text)
{
uchar i,Addr;
CLR_LCD_CS1;
Write_Adr(0x00);
Delay_1ms(5);
for(i=0;i<16;i++)
{
Write_Data(*text);
text++;
Delay_1ms(10000);
}
SET_LCD_CS1;
Delay_1ms(5);
}
第一次弄液晶,没有经验,哪有写的不好的,请指教,谢谢
|