DS12887(時(shí)鐘日歷芯片) c語(yǔ)言驅(qū)動(dòng)程序
掃描二維碼
隨時(shí)隨地手機(jī)看文章
****************DS12887 時(shí)鐘日歷芯片調(diào)試******************/ /*************************/ #define AM_SEC XBYTE[0xFF01] #define REG_A XBYTE[0xFF0a] /********************************************************************/ void Stop_calendar(void); /********************************************************************/ code unsigned char calendar_day[7][3]={"MON","TUE","WEN","THU","FRI","SAT","SUN"}; void main(void) void LCD_en_command(unsigned char command)//寫(xiě)命令函數(shù) void LCD_en_dat(unsigned char dat)//寫(xiě)數(shù)據(jù)函數(shù) void LCD_set_xy( unsigned char x, unsigned char y ) //設(shè)置地址函數(shù) void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)//寫(xiě)字符函數(shù) void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)//寫(xiě)字符串函數(shù) void LCD_init(void)//初始化子函數(shù) void Set_calendar(void) //設(shè)置系統(tǒng)時(shí)間 void Read_calendar(void) //讀取系統(tǒng)時(shí)間 void Start_calendar(void) //啟動(dòng)時(shí)鐘 void Stop_calendar(void)
管腳配置:
MOT: 接地
CS: 接地 地址:0xFF00
AS: 接單片機(jī) 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_MIN XBYTE[0xFF03]
#define AM_HOU XBYTE[0xFF05]
#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; //數(shù)據(jù)、命令選擇 1:數(shù)據(jù) 0:指令 4腳
sbit RW=P0^6; //讀、寫(xiě)操作選擇 1:讀 0:寫(xiě) 5腳
sbit E=P0^5; //使能信號(hào) 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 delay_nms(unsigned int n);
/********************************************************************/
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}; /* 年、月、日、時(shí)、分、秒 、星期*/
unsigned char xdata *calendar_address=0xff00;
{
LCD_init();
//Set_calendar();
Start_calendar();
Stop_calendar();
while(1)
{
Read_calendar();
Display_calendar();
}
}
/********************************************************************/
/******************** LCD PART *************************************/
void LCD_delay(void)//延時(shí)子函數(shù)
{
unsigned char i;
for(i=LCD_DELAY_TIME;i>0;i--); //保證lcd復(fù)位的最小延時(shí)
}
{
LCDIO=command;
RS=LOW;
RW=LOW;
E=LOW;
LCD_delay();
E=HIGH;
}
{
LCDIO=dat;
RS=HIGH;
RW=LOW;
E=LOW;
LCD_delay();
E=HIGH;
}
{
unsigned char address;
if (y == 0)
address = 0x80 + x;
else
address = 0xc0 + x;
LCD_en_command(address);
}
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}
{
LCD_set_xy( X, Y ); //寫(xiě)地址
while (*s) // 寫(xiě)顯示字符
{
LCDIO=*s;
LCD_en_dat(*s);
s ++;
}
}
{
CLEARSCREEN;//清屏
LCD_en_command(0x38);//設(shè)置8位串?dāng)?shù)據(jù)格式
LCD_en_command(0x0c);//開(kāi)顯示器
LCD_en_command(0x80);//顯示起始地址
CLEARSCREEN;//清屏
}
/********************************************************************/
{
unsigned char i;
REG_B=0x80;
for(i=0;i<9;i++)
*(calendar_address+at[i])=calendar_time[i];
}
{
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]);
}
{
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);
}
{
REG_A=0x70;
}