原创 sed1520驱动(122X32点阵)(zz)

2007-12-28 15:29 4037 0 分类: 电源/新能源
#define LCD_DISPLAYON 0xaf
#define LCD_DISPLAYOFF 0xae
#define LCD_DRIVERON 0xa5
#define LCD_DRIVEROFF 0xa4
#define LCD_DUTY16 0xa8
#define LCD_DUTY32 0xa9

#define LCD_END 0xee
#define LCD_RESET 0xe2
#define LCD_RWMODE 0xe0
#define LCD_STARTLINE0 0xc0
#define LCD_PAGE0 0xb8
#define LCD_COLUMNADDR0 0x00

#define LCD_ON() LCD_Command(LCD_DISPLAYON)
#define LCD_OFF() LCD_Command(LCD_DISPLAYOFF)
#define LCD_StaticON() LCD_Command(LCD_DRIVERON)
#define LCD_StaticOFF() LCD_Command(LCD_DRIVEROFF)
#define LCD_Select16() LCD_Command(LCD_DUTY16)
#define LCD_Select32() LCD_Command(LCD_DUTY32)
#define LCD_StartRW() LCD_Command(LCD_RWMODE)
#define LCD_EndRW() LCD_Command(LCD_END)
#define LCD_Reset() LCD_Command(LCD_RESET)
#define LCD_SetStartLine(i) LCD_Command(LCD_STARTLINE0+i)
#define LCD_SetPage(i) LCD_Command(LCD_PAGE0+i)
#define LCD_SetColumn(i) LCD_Command(LCD_COLUMNADDR0+i)

#define TIME 10
#define nop _nop_
sbit A0=P1^3;
sbit RW="P1"^4;
sbit E1=P1^5;
sbit E2=P1^6;
#define DATA P2

/*ASCII字体,大小6X8,上到下D0~D7,左到右*/
unsigned char code ASCII[][6]={{0x00,0x00,0x00,0x00,0x00,0x00},/*SPACE*/
   
{0x00,0x7e,0x21,0x21,0x21,0x7e},/*A*/
   
{0x00,0x7f,0x49,0x49,0x49,0x36},/*B*/
   
{0x00,0x3e,0x41,0x41,0x41,0x22},/*C*/
   
{0x00,0x7f,0x41,0x41,0x22,0x1c},/*D*/
   
{0x00,0x7f,0x49,0x49,0x49,0x49},/*E*/
   
{0x00,0x7f,0x09,0x09,0x09,0x01},/*F*/
   
{0x00,0x3e,0x41,0x49,0x49,0x7a},/*G*/
   
{0x00,0x7f,0x08,0x08,0x08,0x7f},/*H*/
   
{0x00,0x41,0x7f,0x41,0x00,0x00},/*I*/
   
{0x00,0x20,0x40,0x41,0x3f,0x01},/*J*/
   
{0x00,0x7f,0x08,0x14,0x22,0x41},/*K*/
   
{0x00,0x7f,0x40,0x40,0x40,0x40},/*L*/
   
{0x00,0x7f,0x02,0x0c,0x02,0x7f},/*M*/
   
{0x00,0x7f,0x04,0x08,0x10,0x7f},/*N*/
   
{0x00,0x3e,0x41,0x41,0x41,0x3e},/*O*/
   
{0x00,0x7f,0x09,0x09,0x09,0x06},/*P*/
   
{0x00,0x3e,0x41,0x41,0x41,0x3e},/*Q*/
   
{0x00,0x7f,0x09,0x19,0x29,0x46},/*R*/
   
{0x00,0x46,0x49,0x49,0x49,0x31},/*S*/
   
{0x00,0x01,0x01,0x7f,0x01,0x01},/*T*/
   
{0x00,0x3f,0x40,0x40,0x40,0x3f},/*U*/
   
{0x00,0x1f,0x20,0x40,0x20,0x1f},/*V*/
   
{0x00,0x3f,0x40,0x38,0x40,0x3f},/*W*/
   
{0x00,0x63,0x14,0x08,0x14,0x63},/*X*/
   
{0x00,0x07,0x08,0x70,0x08,0x07},/*Y*/
   
{0x00,0x61,0x51,0x49,0x45,0x43},/*Z*/
   
{0x00,0x20,0x54,0x54,0x54,0x7c},/*a*/
   
{0x00,0x7f,0x48,0x44,0x44,0x38},/*b*/
   
{0x00,0x38,0x44,0x44,0x44,0x20},/*c*/
   
{0x00,0x38,0x44,0x44,0x48,0x7f},/*d*/
   
{0x00,0x38,0x54,0x54,0x54,0x18},/*e*/
   
{0x00,0x08,0x7e,0x09,0x01,0x02},/*f*/
   
{0x00,0x0c,0x52,0x52,0x52,0x3e},/*g*/
   
{0x00,0x7f,0x08,0x04,0x04,0x78},/*h*/
   
{0x00,0x00,0x44,0x7d,0x40,0x00},/*i*/
   
{0x00,0x40,0x40,0x44,0x3d,0x00},/*j*/
   
{0x00,0x7f,0x10,0x28,0x44,0x00},/*k*/
      
{0x00,0x00,0x41,0x7e,0x40,0x00},/*l*/
   
{0x00,0x7c,0x04,0x18,0x04,0x78},/*m*/
   
{0x00,0x7c,0x08,0x04,0x04,0x78},/*n*/
   
{0x00,0x38,0x44,0x44,0x44,0x38},/*o*/
   
{0x00,0x7c,0x14,0x14,0x14,0x08},/*p*/
   
{0x00,0x08,0x14,0x14,0x14,0x7c},/*q*/
   
{0x00,0x7c,0x08,0x04,0x04,0x08},/*r*/
   
{0x00,0x48,0x54,0x54,0x54,0x20},/*s*/
     
{0x00,0x04,0x3f,0x44,0x44,0x24},/*t*/
   
{0x00,0x3c,0x40,0x40,0x20,0x7e},/*u*/
   
{0x00,0x1d,0x20,0x40,0x20,0x1c},/*v*/
   
{0x00,0x3c,0x40,0x30,0x40,0x3c},/*w*/
   
{0x00,0x44,0x28,0x10,0x28,0x44},/*x*/
   
{0x00,0x06,0x48,0x48,0x48,0x3e},/*y*/
   
{0x00,0x44,0x64,0x54,0x4c,0x44},/*z*/
   
{0x00,0x00,0x01,0x02,0x04,0x00},/*`*/
   
{0x00,0x00,0x42,0x7f,0x40,0x40},/*1*/
   
{0x00,0x62,0x51,0x51,0x49,0x46},/*2*/
   
{0x00,0x21,0x41,0x45,0x4b,0x31},/*3*/
   
{0x00,0x18,0x14,0x12,0x7f,0x10},/*4*/
   
{0x00,0x27,0x45,0x45,0x45,0x39},/*5*/
   
{0x00,0x3c,0x4a,0x49,0x49,0x30},/*6*/
   
{0x00,0x01,0x71,0x09,0x05,0x03},/*7*/
   
{0x00,0x36,0x49,0x49,0x49,0x36},/*8*/
   
{0x00,0x06,0x49,0x49,0x29,0x1e},/*9*/
   
{0x00,0x3e,0x51,0x49,0x45,0x3e},/*0*/
   
{0x00,0x08,0x08,0x08,0x08,0x08},/*-*/
   
{0x00,0x14,0x14,0x14,0x14,0x14},/*=*/
   
{0x00,0x01,0x02,0x08,0x10,0x20},/*\*/
   
{0x00,0x04,0x08,0x04,0x08,0x04},/*~*/
   
{0x00,0x00,0x00,0x4f,0x00,0x00},/*!*/
   
{0x00,0x3e,0x59,0x55,0x79,0x3e},/*@*/
   
{0x00,0x14,0x7f,0x14,0x7f,0x14},/*#*/
   
{0x00,0x24,0x2a,0x7f,0x2a,0x12},/*$*/
   
{0x00,0x23,0x13,0x08,0x62,0x61},/*%*/
   
{0x00,0x04,0x02,0x01,0x02,0x04},/*^*/
   
{0x00,0x36,0x49,0x55,0x22,0x50},/*&*/
   
{0x00,0x14,0x08,0x3e,0x08,0x14},/***/
   
{0x00,0x00,0x1c,0x22,0x41,0x00},/*(*/
   
{0x00,0x00,0x41,0x22,0x1c,0x00},/*)*/
   
{0x00,0x40,0x40,0x40,0x40,0x40},/*_*/
   
{0x00,0x08,0x08,0x3e,0x08,0x08},/*+*/
   
{0x00,0x00,0x00,0x7e,0x00,0x00},/*|*/
   
{0x00,0x00,0x7f,0x41,0x41,0x00},/*[*/
   
{0x00,0x00,0x41,0x41,0x7f,0x00},/*]*/
   
{0x00,0x00,0x56,0x36,0x00,0x00},/*;*/
   
{0x00,0x00,0x00,0x05,0x03,0x00},/*'*/
   
{0x00,0x00,0x00,0x28,0x18,0x00},/*,*/
   
{0x00,0x00,0x00,0x60,0x60,0x00},/*.*/
   
{0x00,0x20,0x10,0x08,0x04,0x02},/*//*/
   
{0x00,0x00,0x08,0x36,0x41,0x00},/*{*/
   
{0x00,0x00,0x41,0x36,0x08,0x00},/*}*/
   
{0x00,0x00,0x36,0x36,0x00,0x00},/*:*/
   
{0x00,0x00,0x00,0x07,0x00,0x07},/*"*/
   
{0x00,0x08,0x14,0x22,0x41,0x00},/*<*/
   
{0x00,0x00,0x41,0x22,0x14,0x08},/*>*/
   
{0x00,0x02,0x01,0x51,0x09,0x06}/*?*/
   };


void LCD_Command(unsigned char nCommand)
{
unsigned char i;
A0=0;
RW=0;
E1=1;
DATA=nCommand;
i=TIME;
while(--i);
E1=0;
i=TIME;
while(--i);

A0=0;
RW=0;
E2=1;
DATA=nCommand;
i=TIME;
while(--i);
E2=0;
i=TIME;
while(--i);
}

void LCD_SetRam(bit bChip2,unsigned char ndata)
{
unsigned char i;
A0=1;
RW=0;
if(!bChip2)
{
E1=1;
DATA=ndata;
i=TIME;
while(--i);
E1=0;
i=TIME;
while(--i);
}
else
{
E2=1;
DATA=ndata;
i=TIME;
while(--i);
E2=0;
i=TIME;
while(--i);
}
}

void LCD_Write(unsigned char npage,unsigned char ncolumn,unsigned char ndata)
{
LCD_SetPage(npage%4);
LCD_SetColumn(ncolumn);
LCD_SetRam(npage>3,ndata);

}

void LCD_PageWrite(unsigned char npage,unsigned char idata *ndata)
{
unsigned char i;
bit bChip2=npage>3;
LCD_SetPage(npage%4);
LCD_SetColumn(0);
for(i=0;i<61;i++)
LCD_SetRam(bChip2,ndata);
}

void LCD_Init()
{
LCD_Command(LCD_RESET);
LCD_Command(0xa0);
LCD_Command(LCD_DUTY32);
LCD_Command(0xa4);
}


unsigned char *GetTextFont(unsigned char index)
{
static unsigned char Font[6];
unsigned char i;
for(i=0;i<6;i++)
Font=ASCII[index];
return Font;
}

/*
x:0~19
y:0~3
*/
void LCD_TextOut(unsigned char x,unsigned char y,unsigned char *szText)
{
unsigned char i;
bit bChip2;
x%=20;
y%=4;
if(x>=10)
{
x-=10;
y+=4;
}
bChip2=y>3;
LCD_SetPage(y%4);
LCD_SetColumn(x*6);
for(i=0;i<6;i++) LCD_SetRam(bChip2,szText);
}


unsigned char GetIndex(unsigned char szText)
{
unsigned char code TAB[]={' ',

  'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q'
,'R','S','T','U','V','W','X','Y','Z',

  'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q'
,'r','s','t','u','v','w','x','y','z',

  '`','1','2','3','4','5','6','7','8','9','0','-','=','\\',

  '~','!','@','#','$','%','^','&','*','(',')','_','+','|',

  '[',']',';','\'',',','.','/',

  '{','}',':','"','<','>','?'
 
};
unsigned char i;
for(i=0;i<sizeof(TAB);i++)
if(szText==TAB) return i;
return 0x00;
}

void Printf(unsigned char x,unsigned char y,unsigned char *szText)
{
unsigned char *Text;
while(*szText)
{
Text=GetTextFont(GetIndex(*szText));
LCD_TextOut(x++,y,Text);
if(x==20) break;
szText++;
}
}

文章评论0条评论)

登录后参与讨论
相关推荐阅读
mrainborn_377601204 2009-09-07 10:23
朽而不锈看模拟应用设计之二电容很需要(转载)
 2.电容很需要,但不是放在哪里都有效―――门窗漏风盖被子依然冷前面已经讲过对于LDO的输出电容品种很重要,实际上数值,位置也很重要,包括TI等公司在自己的LDO芯片说明手册上都提出关键电容的布置图和...
mrainborn_377601204 2009-09-07 10:06
朽而不锈看模拟应用设计(转载)
第一章       电源设计到位要注意的―――固本1.  开关电源这5V输出有时还真不是东西,真扎手----。经常听兄弟们抱怨自己的设计的系统在实验室或生产车间里调试老化时一点问题都没有,可一到现查就...
mrainborn_377601204 2009-08-23 20:22
仪表放大器
三运放组成的仪表放大器电路分析      仪表放大器与运算放大器的区别是什么?仪表放大器是一种具有差分输入和相对参考端单端输出的闭环增益单元。大多数情况下,仪表放大器的两个输入端阻抗平衡并且阻值很高,...
mrainborn_377601204 2009-03-13 12:44
项目完成之感
             回味一下自己走过的技术之路,工作将近三年,独立完成小项目一个,为期一个月,包括制版、调试、成型、生产。另一个项目从07的5月开始到现在接近尾声,从一开始的负责显示模块到后来整...
mrainborn_377601204 2008-12-06 14:06
C语言,结构体(struct) 用法 (ZZ)
 转自:匠人百宝箱                                             C语言,结构体(struct) 用法结构(struct)      结构是由基本数据类型构成...
mrainborn_377601204 2008-10-24 15:26
浅谈单片机程序设计中的“分层思想”(zt)
浅谈单片机程序设计中的“分层思想”   随便写下的一点东西,本来打算去发表,不过想想还是算了,不是什么重要的东西,不过这个东西确实很有用。文章烂的去组织和修改了,随便看看吧。 分层的思想,并不是什么神...
我要评论
0
0
1
2
3
4
5
6
7
8
9
0
关闭 热点推荐上一条 /2 下一条