万年历源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
LCD_Write(LCD_COMMAND, 0x04|InputMode); }
//初始化 LCD************************************************************
void LCD_Initial()
{
LcdEn=0; LCD_Write(LCD_COMMAND,0x38);
#define LCD_SHOW
0x04 //显示开
#define LCD_HIDE
0x00 //显示关
#define LCD_CURSOR #define LCD_NO_CURSOR
#define LCD_FLASH #define LCD_NO_FLASH
0x02 0x00
//显示光标 //无光标
{
Time->DateString[0] = '2';
Time->DateString[1] = '0';
Time->DateString[2] = Time->Year/10 + '0';
#include <REG52.H> #include <intrins.h> //#include "LCD1602.h" //#include "DS1302.h"
#define uint unsigned int #define uchar unsigned char sbit DS1302_CLK = P1^7; sbit DS1302_IO = P1^6; sbit DS1302_RST = P1^5;
0x01 0x00
//光标闪动 //光标不闪动
void LCD_SetDisplay(unsigned char DisplayMode) {
LCD_Write(LCD_COMMAND, 0x08|DisplayMode); }
//设置输入模式************************************************************
unsigned char Second; unsigned char Minute; unsigned char Hour; unsigned char Week; unsigned char Day; unsigned char Month; unsigned char Year;
unsigned char DateString[11]; unsigned char TimeString[9]; }SYSTEMTIME; //定义的时间类型 SYSTEMTIME CurrentTime;
}
// 地址,命令 // 写 1Byte 数据
unsigned char Read1302(unsigned char ucAddr) //读取 DS1302 某地址的数据
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
sbit Set = P2^0;
//模式切换键
sbit Up = P2^1; sbit Down = P2^2;
//加法按钮 //减法按钮
sbit out = P2^3; sbit DQ = P1^0;
//立刻跳出调整模式按钮 //温度传送数据 IO 口
char done,count,temp,flag,up_flag,down_flag;
uchar temp_value;
//温度值
uchar TempBuffer[5],week_value[2];
//秒,分,时到日,
void show_time(); //液晶显示程序 /***********1602 液晶显示部分子程序****************/
//Port Definitions**********************************************************
#define LCD_AC_UP
0x02
#define LCD_AC_DOWN
0xБайду номын сангаас0
// default
#define LCD_MOVE #define LCD_NO_MOVE
0x01
// 画面可平移
0x00
//default
void LCD_SetInput(unsigned char InputMode) {
{
LcdEn=0;
LcdRs=style;
LcdRw=0;
_nop_();
DBPort=input; _nop_();//注意顺序
LcdEn=1;
_nop_();//注意顺序
LcdEn=0;
_nop_();
LCD_Wait();
}
//设置显示模式************************************************************
//实时时钟读取一字节(内部函数) //相当于汇编中的 RRC
void Write1302(unsigned char ucAddr, unsigned char ucDa) 要写的数据
//ucAddr: DS1302 地址, ucData:
{ DS1302_RST = 0; DS1302_CLK = 0; DS1302_RST = 1; DS1302InputByte(ucAddr); DS1302InputByte(ucDa); DS1302_CLK = 1; DS1302_RST = 0;
#define LCD_COMMAND
0
// Command
#define LCD_DATA
1
#define LCD_CLEAR_SCREEN 0x01
#define LCD_HOMING
0x02
// Data // 清屏 // 光标返回原点
void LCD_Write(bit style, unsigned char input)
#define AM(X) X #define PM(X) (X+12) #define DS1302_SECOND #define DS1302_MINUTE #define DS1302_HOUR #define DS1302_WEEK #define DS1302_DAY #define DS1302_MONTH #define DS1302_YEAR
DS1302InputByte(ucAddr|0x01); ucData = DS1302OutputByte();
// 地址,命令 // 读 1Byte 数据
DS1302_CLK = 1;
DS1302_RST = 0;
return(ucData);
}
void DS1302_GetTime(SYSTEMTIME *Time) //获取时钟芯片的时钟数据到自定义的结构 型数组 {
}
//将字符输出到液晶显示 void Print(unsigned char *str) {
while(*str!='\0') {
LCD_Write(LCD_DATA,*str); str++; } }
/***********DS1302 时钟部分子程序******************/ typedef struct __SYSTEMTIME__ {
void DateToStr(SYSTEMTIME *Time) //将时间年,月,日,星期数据转换成液晶显示字符串,
放到数组里 DateString[]
{ if(hide_year<2)
//这里的 if,else 语句都是判断位闪烁,<2 显示数据,>2
就不显示,输出字符串为 2007/07/22
//实时时钟时钟线引脚 //实时时钟数据线引脚 //实时时钟复位线引脚
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;
char hide_sec,hide_min,hide_hour,hide_day,hide_week,hide_month,hide_year;
月,年位闪的计数
//AC 递增, 画面不动
}
//液晶字符输入的位置************************ void GotoXY(unsigned char x, unsigned char y) {
if(y==0) LCD_Write(LCD_COMMAND,0x80|x);
if(y==1) LCD_Write(LCD_COMMAND,0x80|(x-0x40));
//8 位数据端口,2 行显示,5*7 点阵
LCD_Write(LCD_COMMAND,0x38);
LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR); //开启显示, 无光标 LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE);
unsigned char ReadValue; ReadValue = Read1302(DS1302_SECOND); Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_MINUTE); Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_HOUR); Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_DAY); Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_WEEK); Time->Week = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_MONTH); Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_YEAR); Time->Year = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); }
0x80 0x82 0x84 0x8A 0x86 0x88 0x8C
// 转成 24 小时制 //时钟芯片的寄存器位置,存放时间
void DS1302InputByte(unsigned char d) {
unsigned char i; ACC = d; for(i=8; i>0; i--) {
DS1302_IO = ACC0; DS1302_CLK = 1; DS1302_CLK = 0; ACC = ACC >> 1; } }
unsigned char LCD_Wait(void)
{
LcdRs=0;
LcdRw=1; _nop_();
LcdEn=1; _nop_();
LcdEn=0; return DBPort;
}
//

LCD







************************************************************
sbit LcdRs
= P3^4;
sbit LcdRw
= P3^6;
sbit LcdEn = P3^7; sfr DBPort = 0x80;
//P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.数据端口
//






**************************************************************************
//实时时钟写入一字节(内部函数) //相当于汇编中的 RRC
unsigned char DS1302OutputByte(void) {
unsigned char i; for(i=8; i>0; i--) {
ACC = ACC >>1; ACC7 = DS1302_IO; DS1302_CLK = 1; DS1302_CLK = 0; } return(ACC); }
相关文档
最新文档