- IC型号
企业档案
- 相关证件: 
- 会员类型:
- 会员年限:12年
- 阿库IM:
- 地址:杭州市余杭区仁和街道永泰路2号22幢
- E-mail:752574498@qq.com
HG2401286测试程序
发布时间: 2016/1/6 14:26:35 | 911 次阅读
HG2401286测试程序
#include <reg51.h>
HG2401286测试程序
#include <stdio.h>
#include <intrins.h>
#include <math.h>
#include <absacc.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
#define nop() _nop_()
sbit _WR=P3^1;
sbit _RD=P3^0;
sbit _CD=P3^4;
sbit _FS=P3^5;
sbit CE=P3^3;
sbit RES=P3^6;
uchar code tab[]={" TSINGTEK CO...,LTD "};
uchar code tab1[]={"**WEB:WWW.BEST-LCM.COM**"};
uchar code tab2[]={"EDITOR: MR QIN QQ:381198464"};
uchar code ttab[][32]={
/* 点阵:16x16
提取点阵方向:横向(先上->下, 再左->右)
字节掉转:否
字节方式:C语言 */
0x00,0x40,0x37,0x10,0x83,0x60,0x2F,0x08, // 清
0x13,0x22,0xE3,0x22,0x23,0x22,0x22,0x22,
0x40,0x48,0xFC,0x40,0xF8,0x40,0xFE,0x08,
0xFC,0x08,0xF8,0x08,0xF8,0x08,0x28,0x10,
0x00,0x40,0x20,0x20,0x00,0x0F,0xE0,0x21, // 达
0x21,0x22,0x22,0x24,0x28,0x50,0x8F,0x00,
0x80,0x80,0x80,0x80,0x88,0xFC,0x80,0x00,
0x40,0x20,0x10,0x18,0x08,0x06,0xFC,0x00,
0x01,0x21,0x11,0x09,0x09,0x01,0xFF,0x04, // 光
0x04,0x04,0x04,0x08,0x08,0x10,0x20,0x40,
0x00,0x08,0x0C,0x10,0x20,0x04,0xFE,0x40,
0x40,0x40,0x40,0x40,0x42,0x42,0x3E,0x00,
0x02,0x02,0x02,0x7F,0x42,0x42,0x7F,0x42, // 电
0x42,0x7F,0x42,0x02,0x02,0x02,0x01,0x00,
0x00,0x00,0x10,0xF8,0x10,0x10,0xF0,0x10,
0x10,0xF0,0x10,0x00,0x04,0x04,0xFC,0x00,
0x00,0x40,0x37,0x10,0x81,0x61,0x22,0x0A, // 液
0x16,0x2B,0xE2,0x22,0x22,0x22,0x23,0x22,
0x80,0x44,0xFE,0x20,0x20,0x3C,0x44,0x64,
0x98,0x48,0x50,0x20,0x50,0x8E,0x04,0x00,
0x0F,0x08,0x08,0x0F,0x08,0x08,0x0F,0x08, // 晶
0x7E,0x42,0x42,0x7E,0x42,0x42,0x7E,0x42,
0xE0,0x20,0x20,0xE0,0x20,0x20,0xE0,0x24,
0xFE,0x84,0x84,0xFC,0x84,0x84,0xFC,0x84,
0x00,0x1F,0x10,0x10,0x1F,0x10,0x10,0x1F, // 显
0x14,0x44,0x34,0x14,0x04,0x04,0xFF,0x00,
0x10,0xF8,0x10,0x10,0xF0,0x10,0x10,0xF0,
0x50,0x44,0x4C,0x50,0x40,0x44,0xFE,0x00,
0x00,0x3F,0x00,0x00,0x00,0x00,0xFF,0x01, // 示
0x01,0x09,0x19,0x21,0x41,0x01,0x05,0x02,
0x10,0xF8,0x00,0x00,0x00,0x04,0xFE,0x00,
0x00,0x20,0x18,0x0C,0x04,0x00,0x00,0x00,
0x11,0x11,0x1F,0x11,0xFD,0x13,0x32,0x3B, // 模
0x56,0x53,0x90,0x1F,0x10,0x10,0x11,0x16,
0x10,0x14,0xFE,0x10,0x18,0xFC,0x08,0xF8,
0x08,0xF8,0x40,0xFE,0x40,0xB0,0x0E,0x04,
0x10,0x10,0x10,0x10,0x13,0xFC,0x10,0x10, // 块
0x10,0x17,0x1C,0xF1,0x41,0x02,0x04,0x08,
0x80,0x80,0x80,0x88,0xFC,0x88,0x88,0x88,
0x88,0xFE,0x80,0x40,0x20,0x10,0x0E,0x04,
};
/**********延时***************/
void delay1ms(uint delay_xms)
{
uint i,j,m;
for(i=0;i<delay_xms;i++)
{
for(j=0;j<280;j++)
{
for(m=0;m<125;m++)
{
nop();
nop();
nop();
nop();
}
}
}
}
void delay50us(uchar count50us)
{
uchar data k ;
_nop_();
for(k=0;k<2*count50us;k++)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
/***数据指令读写功能***/
uchar sta01()
{
unsigned char sta;
P1=0x0ff;
_CD=1;
_RD=0;
sta=P1&0x03;
_RD=1;
while(sta!=0x03);
return sta;
}
/**数据自动读**/
void sta2()
{
unsigned char sta;
do{P1=0x0ff;
_CD=1;
_RD=0;
sta=P1&0x04;
_RD=1;;
}
while(sta!=0x04);
}
/**数据自动写 **/
void sta3()
{
unsigned char sta;
do
{
P1=0x0ff;
_CD=1;
_RD=0;
sta=P1&0x08;
_RD=1;
}
while(sta!=0x08);
}
/**屏拷贝**/
void sta6()
{
unsigned char sta;
do
{
P1=0x0ff;
_CD=1;
_RD=0;
sta=P1&0x40;
_RD=1;
}
while(sta!=0x40);
}
/******写入数据**********/
void Writedata(uchar dat1)
{
sta01();
_CD=0;
_WR=0;
P1=dat1;
_WR=1;
_CD=1;
}
/******写入命令************/
void Writecom(uchar command1)
{
sta01();
_CD=1;
_WR=0;
P1=command1;
_WR=1;
_CD=1;
}
/*************写单个字节******************/
void Writesingle(uchar dat2,uchar command2)
{
Writedata(dat2);
Writecom(command2);
}
/**********************写两个字节*********************/
void Writedouble(uchar data1,uchar data2,uchar command)
{
Writedata(data1);
Writedata(data2);
Writecom(command);
}
/***清除****/
void clear()
{
unsigned int i,j;
Writedouble(0x00,0x08,0x24);
Writecom(0xb0);
for(j=0;j<128;j++)
for(i=0;i<30;i++)
{
Writedata(0x00);
}
Writecom(0xb2);
}
/****文本方式初始化*****/
void text_initlcd(void)
{
unsigned int i,j;
Writedouble(0x01,0x00,0x21); //;光标显示地址设置置
Writedouble(0x00,0x00,0x40); // ;文本显示地址设置
Writedouble(0x1e,0x00,0x41); //;文本显示区宽度=显示屏的例数1行所占的字节数30*8=240
Writedouble(0x00,0x08,0x42); // ;文本显示地址设置
Writedouble(0x1e,0x00,0x43); //;文本显示区宽度=显示屏的例数1行所占的字节数30*8=240
Writecom(0x97); //;显示状态设置 1 0 1 0 N3 N2 N1 N0 启用图形显示方式 文本,光
标
Writecom(0xa7); //;光标形状设置1 0 1 0 0 N2 N1 N0
Writecom(0x80);
Writedouble(0x00,0x00,0x24);//;显示地址设置
Writecom(0xb0); //;自动写操作;数据读写设置1 1 0 0 0 N2 N1 N0 N2N1N0=000写操作地址自动
加一
for(j=0;j<240;j++)
for(i=0;i<30;i++)
{
Writedata(0x00);
}
delay50us(2);
Writecom(0xb2);
}
/**************写入一个字符串**********/
void Writestring(uchar x,uchar y,uchar *s)
{
uint j;
j=30*y+x;
Writedouble(j%256,j/256,0x24);
Writecom(0xb0);
while(*s!=0)
{Writedata(*s-0x20);s++;}
delay50us(2);
Writecom(0xb2);
}
/**自定义字符CGRAM ****/
void cgram()
{
uchar i,j;
Writedouble(0x03,0x00,0x22);
Writedouble(0x00,0x1c,0x24);
Writecom(0xb0);
for(i=0;i<10;i++)
for(j=0;j<32;j++)
{
sta3();
Writedata(ttab[i][j]);
}
delay50us(2);
Writecom(0xb2);
}
/**************文本写入汉字******************/
void Writetexthz(uchar x,uchar y,uchar coder)
{
uint j;
cgram();
j=y*30+x;
Writedouble(j%256,j/256,0x24);
Writecom(0xb0);
Writedata(coder);
Writedata(coder+2);
Writecom(0xb2);
j+=30;
Writedouble(j%256,j/256,0x24);
Writecom(0xb0);
Writedata(coder+1);
Writedata(coder+3);
delay50us(2);
Writecom(0xb2);
}
/************文本方式写入一串 汉字************/
void texthz(uchar x,uchar y,uchar m,uchar mend)
{
uchar i;
for(i=m;i<mend;i+=4)
{
Writetexthz(x,y,i);x=x+2;
}}
/********图形写入汉字*************/
void Writetmaphz(uchar x,uchar y)
{
uint i,j,t;
uchar x1,y1;
for(i=0;i<10;i++) ////写入10个字
{
x1=x+2*i; ////列地址变化
for(t=0;t<16;t++)
{
y1=y+t; ////行地址变化
j=30*y1+x1+0x0800; /////////////////物理地址值
Writedouble(j%256,j/256,0x24);
Writesingle(ttab[i][t],0xc0);
Writesingle(ttab[i][t+16],0xc0);
}}}
/** 主函数 **/
void main()
{
delay1ms(1);
_WR=1;
_RD=1;
_CD=1;
_FS=0;
CE=0;
RES=0;
delay50us(20);
RES=1;
delay50us(20);
text_initlcd();
texthz(2,0,0x80,0xa8);
texthz(2,12,0x80,0xa8);
Writestring(2,3,tab);
Writestring(1,5,tab1);
Writestring(0,15,tab2);
/* Writecom(0x98); ///切换到图形模式
clear();
Writetmaphz(0,90);*/
while(1);
}