当前位置:首页 > 单片机 > 单片机
[导读]****************DS12887 时钟日历芯片调试******************/ 管脚配置: MOT: 接地 CS: 接地 地址:0xFF00 AS: 接单片机 ALE R/W: 接 RW DS: 接 RD RESET: 接高 IRQ: 空 SQW: 空 */ #i nclude #

****************DS12887 时钟日历芯片调试******************/

管脚配置:
MOT: 接地
CS: 接地 地址:0xFF00
AS: 接单片机 ALE
R/W: 接 RW
DS: 接 RD
RESET: 接高
IRQ: 空
SQW: 空
*/
#i nclude
#i nclude

/*************************/
#define TM_SEC XBYTE[0xFF00]
#define TM_MIN XBYTE[0xFF02]
#define TM_HOU XBYTE[0xFF04]
#define DAY XBYTE[0xFF06]
#define DATE XBYTE[0xFF07]
#define MONTH XBYTE[0xFF08]
#define YEAR XBYTE[0xFF09]

#define AM_SEC XBYTE[0xFF01]
#define AM_MIN XBYTE[0xFF03]
#define AM_HOU XBYTE[0xFF05]

#define REG_A XBYTE[0xFF0a]
#define REG_B XBYTE[0xFF0b]
#define REG_C XBYTE[0xFF0c]
#define REG_D XBYTE[0xFF0d]

/********************************************************************/
#define LCDIO P2
#define LINE1 0
#define LINE2 1
#define HIGH 1
#define LOW 0
#define CLEARSCREEN LCD_en_command(0x01)
#define LCD_DELAY_TIME 40
/*******************************************************************/
sbit RS=P0^7; //数据、命令选择 1:数据 0:指令 4脚
sbit RW=P0^6; //读、写操作选择 1:读 0:写 5脚
sbit E=P0^5; //使能信号 6脚
/********************************************************************/
void LCD_delay(void);
void LCD_en_command(unsigned char command);
void LCD_en_dat(unsigned char temp);
void LCD_set_xy( unsigned char x, unsigned char y );
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);
void LCD_init(void);
/********************************************************************/
void Set_calendar(void);
void Read_calendar(void);
void Start_calendar(void);
void Display_calendar(void);

void Stop_calendar(void);

/********************************************************************/
void delay_nms(unsigned int n);
/********************************************************************/

code unsigned char calendar_day[7][3]={"MON","TUE","WEN","THU","FRI","SAT","SUN"};
unsigned char calendar_time[7]={05,8,16,18,58,55,2}; /* 05/8/16 18:58:00 星期二*/
code unsigned char at[7]={9,8,7,4,2,0,6}; /* 年、月、日、时、分、秒 、星期*/
unsigned char xdata *calendar_address=0xff00;

void main(void)
{
LCD_init();
//Set_calendar();
Start_calendar();
Stop_calendar();
while(1)
{
Read_calendar();
Display_calendar();
}
}
/********************************************************************/
/******************** LCD PART *************************************/
void LCD_delay(void)//延时子函数
{
unsigned char i;
for(i=LCD_DELAY_TIME;i>0;i--); //保证lcd复位的最小延时
}

void LCD_en_command(unsigned char command)//写命令函数
{
LCDIO=command;
RS=LOW;
RW=LOW;
E=LOW;
LCD_delay();
E=HIGH;
}

void LCD_en_dat(unsigned char dat)//写数据函数
{
LCDIO=dat;
RS=HIGH;
RW=LOW;
E=LOW;
LCD_delay();
E=HIGH;
}

void LCD_set_xy( unsigned char x, unsigned char y ) //设置地址函数
{
unsigned char address;
if (y == 0)
address = 0x80 + x;
else
address = 0xc0 + x;
LCD_en_command(address);
}

void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)//写字符函数
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}

void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)//写字符串函数
{
LCD_set_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCDIO=*s;
LCD_en_dat(*s);
s ++;
}
}

void LCD_init(void)//初始化子函数
{
CLEARSCREEN;//清屏
LCD_en_command(0x38);//设置8位串数据格式
LCD_en_command(0x0c);//开显示器
LCD_en_command(0x80);//显示起始地址
CLEARSCREEN;//清屏
}
/********************************************************************/

void Set_calendar(void) //设置系统时间
{
unsigned char i;
REG_B=0x80;
for(i=0;i<9;i++)
*(calendar_address+at[i])=calendar_time[i];

}

void Read_calendar(void) //读取系统时间
{
unsigned char temp,i;
REG_B=0x06;
do{ temp=REG_A;}
while(temp&0x80);
for(i=0;i<7;i++)
calendar_time[i]=*(calendar_address+at[i]);

}

void Start_calendar(void) //启动时钟
{
REG_A=0x20;
REG_B=0x06;
}
/********************************************************************/
void Display_calendar(void)
{
LCD_write_string(0,LINE1," ");

LCD_write_string(0,LINE1,"20 - - ");
LCD_write_char(0x02,LINE1,(calendar_time[0]/10)|0X30);
LCD_write_char(0x03,LINE1,(calendar_time[0]%10)|0X30);
LCD_write_char(0x05,LINE1,(calendar_time[1]/10)|0X30);
LCD_write_char(0x06,LINE1,(calendar_time[1]%10)|0X30);
LCD_write_char(0x08,LINE1,(calendar_time[2]/10)|0X30);
LCD_write_char(0x09,LINE1,(calendar_time[2]%10)|0X30);
if(calendar_time[6]==1)
LCD_write_string(0x0d,LINE1,"Mon");
if(calendar_time[6]==2)
LCD_write_string(0x0d,LINE1,"Tue");
if(calendar_time[6]==3)
LCD_write_string(0x0d,LINE1,"Wen");
if(calendar_time[6]==4)
LCD_write_string(0x0d,LINE1,"Thu");
if(calendar_time[6]==5)
LCD_write_string(0x0d,LINE1,"Fri");
if(calendar_time[6]==6)
LCD_write_string(0x0d,LINE1,"Sat");
if(calendar_time[6]==7)
LCD_write_string(0x0d,LINE1,"Sun");

LCD_write_string(0,LINE2," : :");
LCD_write_char(0x08,LINE2,(calendar_time[3]/10)|0X30);
LCD_write_char(0x09,LINE2,(calendar_time[3]%10)|0X30);
LCD_write_char(0x0b,LINE2,(calendar_time[4]/10)|0X30);
LCD_write_char(0x0c,LINE2,(calendar_time[4]%10)|0X30);
LCD_write_char(0x0e,LINE2,(calendar_time[5]/10)|0X30);
LCD_write_char(0x0f,LINE2,(calendar_time[5]%10)|0X30);
}

void Stop_calendar(void)
{
REG_A=0x70;
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

USB摄像头是一种采用USB接口的视频采集设备,其优点在于即插即用、操作简便,无需额外驱动程序,支持笔记本电脑,并且成本较低,可以支持远程网络观看。

关键字: usb摄像头 驱动程序

与两相双极步进电机的驱动电路相比,两相单极步进电机的驱动电路在输入段配置、内部逻辑及控制电路和驱动电路使用双通道方面基本相同,但是输出段的配置不同。

关键字: 四相步进电机 驱动程序 程序电路

本文介绍了如何实现嵌入式MICREL网卡的驱动程序开发和设计。首先,我们介绍了MICREL网卡的概述和工作原理。然后,详细探讨了驱动程序的开发流程,包括硬件和软件的配置以及驱动程序的编写和测试。最后,总结了几点注意事项和...

关键字: 嵌入式 MICREL网卡 驱动程序

在这篇文章中,小编将对OLED的相关内容和情况加以介绍以帮助大家增进对它的了解程度,和小编一起来阅读以下内容吧。

关键字: OLED 驱动程序 无源驱动

近日,英特尔发布了锐炫显卡的新版驱动更新。本次驱动更新涵盖了锐炫A770、A750、A380以及移动端的锐炫GPU,这使得英特尔锐炫整个家族的DX9性能都实现了显著提升。

关键字: 英特尔 显卡 驱动程序

摘 要:从硬件与软件方面介绍了基于PXI技术的1553B总线通讯模块的设计,并对PXI总线接口设计、驱动程序的开发、 SDRAM存储器的控制和1553B总线通信协议实现等关键技术进行了详细的阐述,为航空领域测控系统开发P...

关键字: PXI技术 驱动程序 SDRAM存储器 1553B总线

PnP全称Plug-and-Play,译文为即插即用。PnP的作用是自动配置低层计算机中的板卡和其他设备,然后告诉对应设备都做了什么。PnP的任务是把物理设备和软件设备驱动程序相配合,并操作设备,在每个设备和它的驱动程序...

关键字: PnP 驱动程序 操作设备

作 者:道哥,10年嵌入式开发老兵,专注于:C/C、嵌入式、Linux。关注下方公众号,回复【书籍】,获取Linux、嵌入式领域经典书籍;回复【PDF】,获取所有原创文章(PDF格式)。目录kill命令和信号使用kill...

关键字: 信号 应用程序 驱动程序

驱动程序本质上是软件代码,主要作用是计算机系统与硬件设备之间完成数据传送的功能,只有借助驱动程序,两者才能通信并完成特定的功能。

关键字: 驱动程序 硬件设备 UNIX

驱动程序(Device Driver)全称为“设备驱动程序”,是一种可以使计算机和设备通信的特殊程序,可以说相当于硬件的接口,操作系统只能通过这个接口,才能控制硬件设备的工作,假如某设备的驱动程序未能正确安装,便不能正常...

关键字: 驱动程序 声卡 设备
关闭
关闭