新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)+lcd12864液晶萬年歷C程序

單片機(jī)+lcd12864液晶萬年歷C程序

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏

鬧鈴的界面,喇叭出現(xiàn)鈴聲。


生日倒計(jì)時(shí)提醒功能。

全部完整的源代碼下載:http://www.51hei.com/bbs/dpj-20391-1.html

下面是12864.h文件:/*------------------------------------
名稱:LCD9012驅(qū)動(dòng)模塊
編寫:YuMin_Dong
時(shí)間:2013.01.21
------------------------------------*/

#ifndef _LCD12864_H_
#define _LCD12864_H_

/*------------------------------------
I/O位定義
------------------------------------*/
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;

/*------------------------------------
宏定義
------------------------------------*/
#define DataPort P1
#define RS_CLR RS=0
#define RS_SET RS=1
#define RW_CLR RW=0
#define RW_SET RW=1
#define EN_CLR EN=0
#define EN_SET EN=1
//#define PSB_CLR PSB=0
//#define PSB_SET PSB=1
//#define RST_CLR RST=0
//#define RST_SET RST=1

#define MENU_NUM 7//表示有主菜單有7個(gè)選項(xiàng)

UINT8 guide,guide_old=1;//主菜單導(dǎo)航箭頭定義,guide_old在有按鍵前等于guide,有修改后guide_old變化用來作為刷新顯示的條件

/*------------------------------------
主菜單內(nèi)容
------------------------------------*/
code UINT8 *MainMenu[]={" 1.時(shí)間設(shè)置"," 2.日期設(shè)置"," 3.鬧鐘功能"," 4.背光開關(guān)"," 5.鍵音開關(guān)"," 6.生日提醒"," 7.返回"};

/*------------------------------------
判忙函數(shù)
------------------------------------*/
void LCD_CheckBusy()
{
RS_CLR;
RW_SET;
EN_SET;
DataPort=0xff;
while(DataPort&0x80)
;
EN_CLR;
}

/*------------------------------------
寫命令函數(shù)
------------------------------------*/
void LCD_WriteCommand(UINT8 byte)
{
LCD_CheckBusy();
RS_CLR;
RW_CLR;
EN_SET;
DataPort=byte;
DelayUs2x(5);
EN_CLR;
DelayUs2x(5);
}

/*------------------------------------
寫數(shù)據(jù)函數(shù)
------------------------------------*/
void LCD_WriteData(UINT8 byte)
{
LCD_CheckBusy();
RS_SET;
RW_CLR;
EN_SET;
DataPort=byte;
DelayUs2x(5);
EN_CLR;
DelayUs2x(5);
}

/*------------------------------------
LCD初始化
------------------------------------*/
void LCD_Init()
{
//DelayMs(30);
//PSB_SET;//設(shè)置并口模式
//DelayMs(1);
//RST_CLR;
//DelayMs(1);
//RST_SET;
//DelayMs(10);
LCD_WriteCommand(0x30);//選擇基礎(chǔ)指令集
DelayUs2x(50);//延時(shí)大于100us
//LCD_WriteCommand(0x30);//
//DelayUs2x(20);//延時(shí)大于37us
LCD_WriteCommand(0x0c);//開始顯示,無反白,無游標(biāo)
DelayUs2x(50);//延時(shí)大于100us
LCD_WriteCommand(0x01);//清屏
DelayMs(5);
//LCD_WriteCommand(0x06);//讀取或?qū)懭霑r(shí),游標(biāo)移動(dòng)方向,設(shè)定從右向左
//DelayUs2x(50);//延時(shí)大于100us
}

/*------------------------------------
設(shè)置坐標(biāo)
------------------------------------*/
/*void LCD_SetXY(UINT8 x,UINT8 y)
{
switch(y)
{
case 0: LCD_WriteCommand(0x80+x);
break;
case 1: LCD_WriteCommand(0x90+x);
break;
case 2: LCD_WriteCommand(0x88+x);
break;
case 3: LCD_WriteCommand(0x98+x);
break;
default:break;
}
}*/

/*------------------------------------
寫字符串
------------------------------------*/
void LCD_SendString(UINT8 *s)
{
//LCD_SetXY(x,y);
while(*s&&s)
{
LCD_WriteData(*s);
s++;
}
}

/*------------------------------------
設(shè)置CGRAM
------------------------------------*/
void LCD_SetCGRAM(UINT8 n,UINT8 *pic)//第n個(gè)自定義字符
{
UINT8 i;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x40+n*16);
for(i=0;i<16;i++)
{
LCD_WriteData(*(pic+2*i));
LCD_WriteData(*(pic+2*i+1));
}
}

/*------------------------------------
顯示CGRAM
------------------------------------*/
void LCD_DisplayCGRAM(UINT8 n)
{
//LCD_WriteCommand(0x30);
LCD_WriteData(0x00);
LCD_WriteData(0x02*n);
}

/*------------------------------------
GDRAM繪16x16圖
------------------------------------
void LCD_SendImg16x16(UINT8 x,UINT8 y,UINT8 *img,bit g)//(x,y)坐標(biāo) img指向16x16字模數(shù)組,g為是否反白
{
UINT8 i,j,base_x;
LCD_WriteCommand(0x34);
LCD_WriteCommand(0x36);
if(y==0||y==1)
{
base_x=0x80;
y=y*16;
}
else
{
base_x=0x88;
y=(y-2)*16;
}
for(i=0;i<16;i++)
{
LCD_WriteCommand(0x80+y+i);
LCD_WriteCommand(base_x+x);
for(j=0;j<2;j++)
{
if(g)
LCD_WriteData(~(*img++));
else
LCD_WriteData(*img++);
}
}
LCD_WriteCommand(0x36);
//LCD_WriteCommand(0x30);
}*/


/*------------------------------------
GDRAM繪16x32圖
------------------------------------*/
void LCD_SendImg16x32(UINT8 x,UINT8 y,UINT8 *img,bit g)//x標(biāo)志表示是否反白。
{
UINT8 i,j,base_x;
LCD_WriteCommand(0x34);
LCD_WriteCommand(0x36);
switch(y)
{
case 0: base_x=0x80;break;
case 1: base_x=0x90;break;
case 2: base_x=0x88;break;
default:return;
}
if(y==0||y==2)
{
for(i=0;i<32;i++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(base_x+x);
for(j=0;j<2;j++)
{
if(!g)
LCD_WriteData(*img++);
else LCD_WriteData(~(*img++));
}
}
}
if(y==1)
{
for(i=0;i<16;i++)
{
LCD_WriteCommand(0x90+i);
LCD_WriteCommand(base_x+x);
for(j=0;j<2;j++)
{
if(g)
LCD_WriteData(~(*img++));
else
LCD_WriteData(*img++);
}
}
for(i=0;i<16;i++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(base_x+x+8);
for(j=0;j<2;j++)
{
if(g)
LCD_WriteData(~(*img++));
else
LCD_WriteData(*img++);
}
}
}
LCD_WriteCommand(0x36);
//LCD_WriteCommand(0x30);
}

/*------------------------------------
GDRAM繪制128x64
------------------------------------*/
void LCD_SendImg128x64(UINT8 *img)
{
UINT8 i,j;
//LCD_WriteCommand(0x30);
LCD_WriteCommand(0x36);
for(i=0;i<32;i++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(0x80);
for(j=0;j<16;j++)
{
LCD_WriteData(*img++);
}
}
for(i=0;i<32;i++)
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(0x88);
for(j=0;j<16;j++)
{
LCD_WriteData(*img++);
}
}
LCD_WriteCommand(0x36);
}

/*------------------------------------
清除GDRAM
------------------------------------*/
void LCD_ClearGDRAM()
{
UINT8 i,j;
LCD_WriteCommand(0x30);//一般指令
LCD_WriteCommand(0x0C); //開啟顯示
LCD_WriteCommand(0x06); //AC++
LCD_WriteCommand(0x01);//清DDRAM
LCD_WriteCommand(0x36);//開啟繪圖
//LCD_InitGDRAM();
LCD_WriteCommand(0x36);//顯示繪圖
for(i=0;i<32;i++)//在DGRAM里寫滿0,表示清除GDRAM
{
LCD_WriteCommand(0x80+i);
LCD_WriteCommand(0x80);
for(j=0;j<16;j++)
{
LCD_WriteData(0x00);
LCD_WriteData(0x00);
}
}
LCD_WriteCommand(0x36);//繪圖完畢,開啟顯示
}

/*------------------------------------
清除1,2,3行屏
------------------------------------*/
void LCD_ClearScreen123()
{
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x90);
LCD_SendString(" ");
LCD_WriteCommand(0x88);
LCD_SendString(" ");
LCD_WriteCommand(0x98);
LCD_SendString(" ");
}

/*------------------------------------
菜單選擇更新
------------------------------------*/
void LCD_RefreshMenu()
{
LCD_ClearScreen123();
LCD_WriteCommand(0x90);
if(0+(guide/3)*3LCD_SendString(*(MainMenu+(guide/3)*3));

LCD_WriteCommand(0x88);
if(1+(guide/3)*3LCD_SendString(*(MainMenu+(guide/3)*3+1));

LCD_WriteCommand(0x98);
if(2+(guide/3)*3LCD_SendString(*(MainMenu+(guide/3)*3+2));

switch(guide%3)
{
case 0: LCD_WriteCommand(0x90);break;
case 1: LCD_WriteCommand(0x88);break;
case 2: LCD_WriteCommand(0x98);break;
default:return ;
}
LCD_DisplayCGRAM(1);
}

#endif


上一頁 1 2 下一頁

評(píng)論


技術(shù)專區(qū)

關(guān)閉