新闻  |   论坛  |   博客  |   在线研讨会
sed1520驱动(122X32点阵)
mayer | 2009-06-07 13:16:55    阅读:2135   发布文章

 

#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[i]);
}

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[i]=ASCII[index][i];
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[i]);
}


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[i]) 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++;
}
}

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客