HG122321演示程序

发布时间:2016/10/26 15:43:32

#include <reg52.h>
#include <stdio.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define buslcd P1
uchar coder,count;
sbit A0=P3^4;//////////////RS
sbit E1=P3^0;
sbit E2=P3^1;
sbit RW=P3^3;
uchar code tab[]={ 
 0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00,    /*"0"=10h*/
 0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00,    /*"3"=13h*/
 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
 0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
 0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
 0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00,    /*"9"=19h*/
 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
 0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/
 0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00,    /*"6"=16h*/
 0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/ 
  0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00,    /*"3"=13h*/
 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
 0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
 0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,    /*"1"=11h*/
 0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00,    /*"9"=19h*/
 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,    /*"8"=18h*/
 0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/
 0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00,    /*"6"=16h*/
 0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,    /*"4"=14h*/ 
 };
unsigned char code tab16[]={
0x80,0x40,0x20,0xF8,0x47,0x48,0x48,0x48,    // 佳
0x48,0xFF,0x48,0x48,0x4C,0x68,0x40,0x00,
0x00,0x00,0x00,0xFF,0x40,0x44,0x44,0x44,
0x44,0x7F,0x44,0x44,0x46,0x64,0x40,0x00,


0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,    // 显
0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x00,
0x40,0x42,0x44,0x4D,0x40,0x7F,0x40,0x40,
0x40,0x7F,0x40,0x49,0x44,0x66,0x40,0x00,


0x24,0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,    // 科
0x24,0x48,0x00,0xFF,0x00,0x80,0x00,0x00,
0x10,0x08,0x06,0x01,0xFF,0x00,0x01,0x02,
0x02,0x02,0x02,0xFF,0x01,0x01,0x01,0x00,


0x10,0x10,0x10,0xFF,0x10,0x10,0x88,0x88,    // 技
0x88,0xFF,0x88,0x88,0x8C,0x08,0x00,0x00,
0x04,0x44,0x82,0x7F,0x01,0x80,0x81,0x46,
0x28,0x10,0x28,0x26,0x41,0xC0,0x40,0x00,
0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,    // 有
0x24,0x24,0x24,0xF4,0x24,0x06,0x04,0x00,
0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,
0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,


0x00,0xFE,0x02,0x22,0xDA,0x06,0x00,0xFE,    // 限
0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,
0x00,0xFF,0x08,0x10,0x08,0x07,0x00,0xFF,
0x42,0x24,0x08,0x14,0x22,0x61,0x20,0x00,


0x00,0x00,0x80,0x40,0x30,0x0C,0x00,0xC0,    // 公
0x06,0x18,0x20,0x40,0x80,0x80,0x80,0x00,
0x01,0x01,0x00,0x30,0x28,0x24,0x23,0x20,
0x20,0x28,0x30,0x60,0x00,0x01,0x00,0x00,


0x10,0x10,0x92,0x92,0x92,0x92,0x92,0x92,    // 司
0xD2,0x9A,0x12,0x02,0xFF,0x02,0x00,0x00,
0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x10,
0x3F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,


}; 


/***************************************************
  延时
****************************************************/
void Delay(uint t)
{uint i,j;
for(i=0;i<t;i++)
for(j=0;j<305;j++)
_nop_();_nop_();_nop_();_nop_();
}
/***************************************************
 忙判断
*****************************************************/
void Busy1()
{
 A0=0;
 RW=1;
buslcd=0xff;
E1=1;
_nop_();
 while(buslcd&0x80);
E1=0;
_nop_();
}
////////////////////////////
void Busy2()
{
 A0=0;
 RW=1;
buslcd=0xff;
E2=1;
_nop_();
 while(buslcd&0x80);
E2=0;
_nop_();
}
/********************************************************
  指令写人
*******************************************************/
void Writecom1(uchar wcom)
{


 Busy1();
 buslcd=wcom;
 A0=0;
 RW=0;
E1=1;
_nop_();
E1=0;
_nop_();}
////////////////////////////////
void Writedata1(uchar wdata)
{


 Busy1();
 buslcd=wdata;
 A0=1;
 RW=0;
E1=1;
_nop_();
E1=0;
_nop_();}
/********************************************************
  指令写人
*******************************************************/
void Writecom2(uchar wcom)
{


 Busy2();
 buslcd=wcom;
 A0=0;
 RW=0;
 E2=1;
_nop_();
  E2=0;
_nop_();}
////////////////////////////////
void Writedata2(uchar wdata)
{


 Busy2();
 buslcd=wdata;
 A0=1;
 RW=0;
 E2=1;
_nop_();
 E2=0;
_nop_();}
///////////////////////////////////////
void Readdata1(uchar rdata)
{


 Busy1();
 buslcd=rdata;
 A0=1;
 RW=1;
 E1=1;
_nop_();_nop_();_nop_();
 E1=0;
_nop_();}
////////////////////////////////
void Readdata2(uchar rdata)
{


 Busy2();
 buslcd=rdata;
 A0=1;
 RW=1;
 E2=1;
_nop_();_nop_();_nop_();
 E2=0;
_nop_();}
/********************************************************
  清除
*******************************************************/
void Clear(uchar m)
{uchar i,j;
for(i=0;i<4;i++)
{Writecom1(0xb8+i);Writecom1(0x00);/////起始页面和列设置
Writecom2(0xb8+i);;Writecom2(0x00);
for(j=0;j<61;j++)
{Writedata1(m);Writedata2(m);}}
Delay(10);}
void revert(uchar m)
{uchar i,j;
for(i=0;i<4;i++)
{Writecom1(0xb8+i);Writecom1(0x00);
Writecom2(0xb8+i);;Writecom2(0x00);
for(j=0;j<61;j++)
{Writedata1(m);Writedata1(~m);
Writedata2(m);Writedata2(~m);}}
Delay(10);}
/********************************************************
初始化写人
*******************************************************/
void INT()
{
Delay(3);
Writecom1(0xe2);
Writecom2(0xe2);//复位
Writecom1(0xa0);
Writecom2(0xa0);//ADC方向
Writecom1(0xa9);
Writecom2(0xa9);//占空比
Writecom1(0xa4);
Writecom2(0xa4);//休闲
Writecom1(0xc0);
Writecom2(0xc0);//起始行
Writecom1(0xaf);
Writecom2(0xaf);//开显示
Clear(0x00);
}
/********************************************************
写人 8*8字体
*******************************************************/
void display8(uchar x,uchar y,uchar coder)
{
uchar i,*p;
p=tab+coder*8;
for(i=0;i<8;i++)
{
if(x<61)
{
Writecom1(0xb8+y);
Writecom1(x);
Writedata1(*p);
}
else
{
Writecom2(0xb8+y);
Writecom2(x-61);
Writedata2(*p);}
x++;p++;
}}
void display_88(uchar x,uchar y)
{
uchar i;
for(i=0;i<15;i++)
 {display8(x,y,i);x+=8;}
}
/******************************************
汉字
***********************************************/
void hz(uchar x,uchar y,uchar coder,uchar *s)
{
uchar x1,y1;
uchar i;
uchar *p;
x1=x;y1=y;
p=s+coder*32;
for(i=0;i<16;i++)
{
if(x<61)
{
 Writecom1(0xb8+y);
 Writecom1(x);
 Writedata1(*p);
}
 else
 {
   Writecom2(0xb8+y);
   Writecom2(x-61);
   Writedata2(*p);
}
x++;p++;
}
   x=x1;y=y1+1;
   _nop_(); _nop_();
 for(i=0;i<16;i++)
 {
  if(x<61)
{
 Writecom1(0xb8+y);
 Writecom1(0x00+x);
 Writedata1(*p);
}
 else
 {
   Writecom2(0xb8+y);
   Writecom2(x-61);
   Writedata2(*p);
}
x++;p++;
}
}
void display_16(uchar x,uchar y,uchar *s)
{
uchar i;
  for(i=0;i<7;i++)
  {hz(x,y,i,s);x+=16;}
}
/********************************************************
主函数
*******************************************************/
void main()
{
Delay(3);
INT();
Clear(0x00);
display_88(0,0);
display_16(0,1,tab16);
display_88(0,3);
while(1);
}


上一篇:HG1223211演示程序
下一篇:HG2401283演示程序