基于PIC16F877A單片機(jī)設(shè)計(jì)的萬(wàn)年歷程序
/*----------------------------------------------------*/
//寫(xiě)顯示數(shù)據(jù)
//dat:顯示數(shù)據(jù)
void WriteData(unsigned char dat)
{
CheckState();
DI=1; //寫(xiě)數(shù)據(jù)
RW=0;
PORTB=dat;
E=1;
E=0;
}
/*---------------------------------------------------*/
//寫(xiě)指令
//command:操作LCD的指令
void WriteCommand(unsigned char dat)
{
CheckState();
RW=0; //寫(xiě)指令
PORTB=dat;
E=1;
E=0;
}
/*---------------------------------------------------*/
//設(shè)定頁(yè)地址----X:0--7
void SetLine(unsigned char line)
{
line=line0x07; //0
//設(shè)定列地址----Y:0--63
void SetColumn(unsigned char column)
{
column=column0x3f; //0
//設(shè)定開(kāi)始行
void SetStartLine(unsigned char startline)
{
startline=startline0x3f; //0
//開(kāi)關(guān)顯示
//1:開(kāi)顯示 0:關(guān)顯示
void SetOnOff(unsigned char state)
{
state=state|0x3e;
WriteCommand(state);
}
/*--------------------------------------------------*/
//選擇屏幕
//screen: 1:左屏 2:右屏
void SlectScreen(unsigned char screen)
{
switch(screen)
{
case 1: CSA=0;
CSB=1;//左屏
break;
case 2: CSA=1;
CSB=0;//右屏
break;
}
}
/*--------------------------------------------------*/
//清屏
//screen: 1:左屏 2:右屏
void ClearScreen(unsigned char screen)
{
unsigned char i,j;
SlectScreen(screen);
for(i=0;i
//顯示一個(gè)16X16的漢字
void Show16X16(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;//
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)16X16的漢字帶上劃線
void Show16X16_2(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt|0x01); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)16X16的漢字帶下劃線
void Show16X16_3(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt|0x80);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)8X16的字符
void Show8X16(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
column=column_temp;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//顯示一個(gè)8X16的字符帶上劃線
void Show8X16_2(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp;
column_temp=column;
SlectScreen(1); //選通左屏
SetColumn(column); //設(shè)置起始列
SetLine(line); //設(shè)置行
for(i=0;i=64) //如果列>=64,則選通右屏
{
SlectScreen(2);
column=column%64; //設(shè)置右屏起始列
SetColumn(column);
SetLine(line);
}
WriteData(*pt|0x01); //寫(xiě)數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1); //設(shè)置漢字下半部分顯示頁(yè)
colu mn=column_temp;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
}
評(píng)論