微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 51单片机驱动ds1302程序(12864液晶显示)

51单片机驱动ds1302程序(12864液晶显示)

时间:11-30 来源:互联网 点击:

LCD_SendImg16x32(0,1,*(User_16x32+Bell_Hour/10),Set_Bell==0);
LCD_SendImg16x32(1,1,*(User_16x32+Bell_Hour%10),Set_Bell==0);

LCD_SendImg16x32(2,1,*(User_16x32+10),0);

LCD_SendImg16x32(3,1,*(User_16x32+Bell_Minute/10),Set_Bell==1);
LCD_SendImg16x32(4,1,*(User_16x32+Bell_Minute%10),Set_Bell==1);

LCD_SendImg16x32(5,1,*(User_16x32+10),0);

LCD_SendImg16x32(6,1,*User_16x32,0);
LCD_SendImg16x32(7,1,*User_16x32,0);
}

/*------------------------------------
读取日期
------------------------------------*/
void DS1302_ReadDate()
{
Year=DS1302_ReadByte(YEAR_ADDRESS);
Month=DS1302_ReadByte(MONTH_ADDRESS);
Date=DS1302_ReadByte(DATE_ADDRESS);
}

/*------------------------------------
写入日期
------------------------------------*/
void DS1302_WriteDate()
{
DS1302_WriteByte(CONTROL_ADDRESS,0X00);//关闭写保护
DS1302_WriteByte(DATE_ADDRESS,Date);
DS1302_WriteByte(MONTH_ADDRESS,Month);
DS1302_WriteByte(YEAR_ADDRESS,Year);//清零秒
DS1302_WriteByte(CONTROL_ADDRESS,0x80);//打开写保护
}

/*------------------------------------
设置时填充大数字日期
------------------------------------*/
void Display_SetDate()
{
LCD_WriteCommand(0x34);
LCD_WriteCommand(0x36);

LCD_SendImg16x32(0,1,*(User_16x32+Year/16),Set_Date==0);
LCD_SendImg16x32(1,1,*(User_16x32+Year%16),Set_Date==0);

LCD_SendImg16x32(2,1,*(User_16x32+11),0);

LCD_SendImg16x32(3,1,*(User_16x32+Month/16),Set_Date==1);
LCD_SendImg16x32(4,1,*(User_16x32+Month%16),Set_Date==1);

LCD_SendImg16x32(5,1,*(User_16x32+11),0);

LCD_SendImg16x32(6,1,*(User_16x32+Date/16),Set_Date==2);
LCD_SendImg16x32(7,1,*(User_16x32+Date%16),Set_Date==2);
//LCD_WriteCommand(0x30);
}
/*------------------------------------
星期转换
------------------------------------*/
UINT8 Conver_Week(bit c,UINT8 year,UINT8 month,UINT8 date)
{
UINT8 temp1,temp2,week;
temp1=year/16;
temp2=year%16;
year=temp1*10+temp2;
temp1=month/16;
temp2=month%16;
month=temp1*10+temp2;
temp1=date/16;
temp2=date%16;
date=temp1*10+temp2;

if (c==0){year+=0x64;}
temp1=year/0x4;
temp2=year+temp1;
temp2=temp2%0x7;
temp2=temp2+date+WEEK_TAB[month-1];
if (year%0x4==0&&month<3)temp2-=1;
week=temp2%0x7;
return week;
}
/*------------------------------------
显示日期
------------------------------------*/
void Display_Date()
{
//if(Set_Year&&!Set_Month)
//Year=~Year;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x06);
//显示日期格式20XX-XX-XX
LCD_WriteCommand(0x80);
//从1302读出年信息
LCD_SendString("20");
LCD_WriteData(Year/16|0x30);//填充年信息
LCD_WriteData(Year%16|0x30);

LCD_WriteData(-);//分隔符

//从1302读出月信息
LCD_WriteData(Month/16|0x30);//LCD填充月信息
LCD_WriteData(Month%16|0x30);

LCD_WriteData(-);//分隔符

//从1302读出日信息
LCD_WriteData(Date/16|0x30);//LCD填充日信息
LCD_WriteData(Date%16|0x30);
}

/*------------------------------------
换算并显示星期
------------------------------------*/
void Display_Week()
{
LCD_WriteCommand(0x86);
//Week=DS1302_ReadByte(WEEK_ADDRESS);
Week=Conver_Week(0,Year,Month,Date);
LCD_SendString("周");
switch(Week)
{
case 0: LCD_SendString("日");
break;
case 1:LCD_SendString("一");
break;
case 2: LCD_SendString("二");
break;
case 3:LCD_WriteData(0xc8);//字库区位码表得出"三"的显示码.
LCD_WriteData(0xfd);
break;
case 4: LCD_SendString("四");
break;
case 5: LCD_SendString("五");
break;
case 6: LCD_SendString("六");
break;
default:return ;
}
}

/*------------------------------------
初始化
------------------------------------*/
void DS1302_Init()//初始化DS1302
{
DS_SCL_CLR;
DS_RST_CLR;
//DS1302_WriteByte(CONTROL_ADDRESS,0X00);
//DS1302_WriteByte(HOUR_ADDRESS,0x16);
//DS1302_WriteByte(CONTROL_ADDRESS,0x80);

}
#endif

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top