基于PIC16F877A單片機設(shè)計的萬年歷程序
/*-------------------------------------------------------*/
//顯示一個16X32的字符
void Show16X32(unsigned char line,unsigned char column,const unsigned char *pt)
{
unsigned char i,column_temp1,column_temp2,column_temp3;
column_temp1=column;
column_temp2=column;
column_temp3=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); //寫數(shù)據(jù)
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+1);
column=column_temp1;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+1);
}
WriteData(*pt);
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+2);
column=column_temp2;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+2);
}
WriteData(*pt);
*pt++;
column++;
}
SlectScreen(1);
SetLine(line+3);
column=column_temp3;
SetColumn(column);
for(i=0;i=64)
{
SlectScreen(2);
column=column%64;
SetColumn(column);
SetLine(line+3);
}
WriteData(*pt);
*pt++;
column++;
}
}
/*-------------------------------------------------------*/
//LCD初始化子程序
void LCDinit()
{
ADCON1=0x06;
TRISA=0x00;
TRISB=0x00;
PORTB=0x00;
SetOnOff(1);
}
/*----------------------------------------------------------*/
//調(diào)用LCD顯示子程序
void ChangeToLCD(uch line,uch column,uch data)
{
int D_ge,D_shi;
D_ge=data%10; //取個位
D_shi=data%100/10; //取十位
switch(D_ge)
{
case 0:{Show8X16(line,column+8,s0);break;}
case 1:{Show8X16(line,column+8,s1);break;}
case 2:{Show8X16(line,column+8,s2);break;}
case 3:{Show8X16(line,column+8,s3);break;}
case 4:{Show8X16(line,column+8,s4);break;}
case 5:{Show8X16(line,column+8,s5);break;}
case 6:{Show8X16(line,column+8,s6);break;}
case 7:{Show8X16(line,column+8,s7);break;}
case 8:{Show8X16(line,column+8,s8);break;}
case 9:{Show8X16(line,column+8,s9);break;}
}
switch(D_shi)
{
case 0:{Show8X16(line,column,s0);break;}
case 1:{Show8X16(line,column,s1);break;}
case 2:{Show8X16(line,column,s2);break;}
case 3:{Show8X16(line,column,s3);break;}
case 4:{Show8X16(line,column,s4);break;}
case 5:{Show8X16(line,column,s5);break;}
case 6:{Show8X16(line,column,s6);break;}
case 7:{Show8X16(line,column,s7);break;}
case 8:{Show8X16(line,column,s8);break;}
case 9:{Show8X16(line,column,s9);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD2(uch line,uch column,uch data)//帶上劃線
{
int D_ge,D_shi;
D_ge=data%10; //取個位
D_shi=data%100/10; //取十位
switch(D_ge)
{
case 0:{Show8X16_2(line,column+8,s0);break;}
case 1:{Show8X16_2(line,column+8,s1);break;}
case 2:{Show8X16_2(line,column+8,s2);break;}
case 3:{Show8X16_2(line,column+8,s3);break;}
case 4:{Show8X16_2(line,column+8,s4);break;}
case 5:{Show8X16_2(line,column+8,s5);break;}
case 6:{Show8X16_2(line,column+8,s6);break;}
case 7:{Show8X16_2(line,column+8,s7);break;}
case 8:{Show8X16_2(line,column+8,s8);break;}
case 9:{Show8X16_2(line,column+8,s9);break;}
}
switch(D_shi)
{
case 0:{Show8X16_2(line,column,s0);break;}
case 1:{Show8X16_2(line,column,s1);break;}
case 2:{Show8X16_2(line,column,s2);break;}
case 3:{Show8X16_2(line,column,s3);break;}
case 4:{Show8X16_2(line,column,s4);break;}
case 5:{Show8X16_2(line,column,s5);break;}
case 6:{Show8X16_2(line,column,s6);break;}
case 7:{Show8X16_2(line,column,s7);break;}
case 8:{Show8X16_2(line,column,s8);break;}
case 9:{Show8X16_2(line,column,s9);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD3(uch line,uch column,uch data)//帶下劃線
{
int D_ge,D_shi;
D_ge=data%10; //取個位
D_shi=data%100/10; //取十位
switch(D_ge)
{
case 0:{Show16X32(line,column+16,ss0);break;}
case 1:{Show16X32(line,column+16,ss1);break;}
case 2:{Show16X32(line,column+16,ss2);break;}
case 3:{Show16X32(line,column+16,ss3);break;}
case 4:{Show16X32(line,column+16,ss4);break;}
case 5:{Show16X32(line,column+16,ss5);break;}
case 6:{Show16X32(line,column+16,ss6);break;}
case 7:{Show16X32(line,column+16,ss7);break;}
case 8:{Show16X32(line,column+16,ss8);break;}
case 9:{Show16X32(line,column+16,ss9);break;}
}
switch(D_shi)
{
case 0:{Show16X32(line,column,ss0);break;}
case 1:{Show16X32(line,column,ss1);break;}
case 2:{Show16X32(line,column,ss2);break;}
case 3:{Show16X32(line,column,ss3);break;}
case 4:{Show16X32(line,column,ss4);break;}
case 5:{Show16X32(line,column,ss5);break;}
case 6:{Show16X32(line,column,ss6);break;}
case 7:{Show16X32(line,column,ss7);break;}
case 8:{Show16X32(line,column,ss8);break;}
case 9:{Show16X32(line,column,ss9);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD4(uch line,uch column,uch data)//星期轉(zhuǎn)換
{
switch(data)
{
case 1:{Show16X16_3(line,column,ri);break;}
case 2:{Show16X16_3(line,column,yi);break;}
case 3:{Show16X16_3(line,column,er);break;}
case 4:{Show16X16_3(line,column,san);break;}
case 5:{Show16X16_3(line,column,si);break;}
case 6:{Show16X16_3(line,column,wu);break;}
case 7:{Show16X16_3(line,column,liu);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD5(uch line,uch column,uch data)//生肖轉(zhuǎn)換
{
data=data%12;
switch(data)
{
case 0:{Show16X16_3(line,column,llong);break;}
case 1:{Show16X16_3(line,column,she);break;}
case 2:{Show16X16_3(line,column,ma);break;}
case 3:{Show16X16_3(line,column,yang);break;}
case 4:{Show16X16_3(line,column,hou);break;}
case 5:{Show16X16_3(line,column,ji);break;}
case 6:{Show16X16_3(line,column,gou);break;}
case 7:{Show16X16_3(line,column,zhu);break;}
case 8:{Show16X16_3(line,column,shu);break;}
case 9:{Show16X16_3(line,column,niu);break;}
case 10:{Show16X16_3(line,column,hu);break;}
case 11:{Show16X16_3(line,column,tu);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD6(uch line,uch column,uch data)//陰歷月轉(zhuǎn)換
{
data=data%12;
switch(data)
{
case 0:{Show16X16_2(line,column,zheng);break;}
case 1:{Show16X16_2(line,column,er);break;}
case 2:{Show16X16_2(line,column,san);break;}
case 3:{Show16X16_2(line,column,si);break;}
case 4:{Show16X16_2(line,column,wu);break;}
case 5:{Show16X16_2(line,column,liu);break;}
case 6:{Show16X16_2(line,column,qqi);break;}
case 7:{Show16X16_2(line,column,ba);break;}
case 8:{Show16X16_2(line,column,jiu);break;}
case 9:{Show16X16_2(line,column,shi);break;}
case 10:{Show16X16_2(line,column,shiyi);break;}
case 11:{Show16X16_2(line,column,la);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD7(uch line,uch column,uch data)//陰歷日
{
data=data%12;
switch(data)
{
case 0:{Show16X16_2(line,column,yi);break;}
case 1:{Show16X16_2(line,column,er);break;}
case 2:{Show16X16_2(line,column,san);break;}
case 3:{Show16X16_2(line,column,si);break;}
case 4:{Show16X16_2(line,column,wu);break;}
case 5:{Show16X16_2(line,column,liu);break;}
case 6:{Show16X16_2(line,column,qqi);break;}
case 7:{Show16X16_2(line,column,ba);break;}
case 8:{Show16X16_2(line,column,jiu);break;}
case 9:{Show16X16_2(line,column,shi);break;}
}
}
/*-----------------------------------------------------------------*/
void ChangeToLCD8(uch line,uch column,uch data)//陰歷日十位
{
data=data%3;
switch(data)
{
case 0:{Show16X16_2(line,column,chu);break;}
case 1:{Show16X16_2(line,column,er);break;}
case 2:{Show16X16_2(line,column,san);break;}
}
}
/*-----------------------------------------------------------------*/
程序結(jié)束
三,總結(jié)
到現(xiàn)在為止,我對KS0108系列液晶的操作已經(jīng)基本掌握了,并可以熟練應(yīng)用.但是本程序中陽歷轉(zhuǎn)陰歷的程序還是不對,我想不出更好的轉(zhuǎn)換辦法,希望大家能提供方法完善.由于篇幅原因,沒有將陽歷轉(zhuǎn)陰歷的程序,和液晶字庫的程序附載上面,
評論