⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wds12887lcd.#1

📁 C8051F.rar
💻 #1
字号:
//参考程序C  :WDS12887LCD.c	此程序读取时钟值,并年,月,日,时,分,秒.
//分别显示在LCD屏上。可实现时钟初始化(授时)
#include <c8051f020.h>          // SFR declarations
#include <intrins.h>
#define CS12887		0x8300		/*DS12887时间寄存器首地址*/
#define	CS12887A	0x830A		/*DS12887内部寄存器A地址*/
#define	CS12887B	0x830B		/*DS12887内部寄存器B地址*/
#define	CS12887C	0x830C		/*DS12887内部寄存器C地址*/
unsigned long x;
unsigned char *lcdpoint;         /*指向 lcddata数组的指针*/
unsigned char lcd_data_count;    /*要显示的数据个数 */
void PORT_Init (void);
void sleep_ms(unsigned int count)
{
  unsigned int ii,jj;
  for(ii=0;ii<count;ii++)
    {
      for(jj=0;jj<250;jj++)
	  _nop_();			
    }	
}
void SYSCLK_Init (void)
{
 OSCICN = 0x05;       /*系统时钟初始化为片内的4MHz*/
                                      
 }
 void DS12887INIT(void)
{
	unsigned char i;
	unsigned char xdata *idata Point1;	
	Point1=CS12887B;
	*Point1=0x80;		/*设置SET=1,禁止时间更新*/
	Point1=CS12887;
	*Point1=0x00;		/*写入当前秒值:"30"秒*/
	Point1++;
	*Point1=0xff;		/*秒不报警(不闹秒)*/
	Point1++;
	*Point1=0x0;		/*写入当前分值:"58"分*/
	Point1++;
	*Point1=0xff;		/*分不报警(不闹分)*/
	Point1++;
	*Point1=0x21;		/*写入当前时值:"16" 时*/
	Point1++;
	*Point1=0xff;		/*时不报警(不闹时)*/
	Point1++;
	*Point1=0x05;		/*写入当前周日:"5"*/
	Point1++;
	*Point1=0x6;		/*写入当前日期:"05"日*/
	Point1++;
	*Point1=0x10;		/*写入当前月份:"08"月*/
	Point1++;
	*Point1=0x05;		/*写入当前年份:"05"年*/
	Point1=CS12887C;
	i=*Point1;			/*CLEAR C*/
	Point1++;
	i=*Point1;			/*CLEAR D*/
	Point1=CS12887B;	/*更新周期正常运行,禁止中断,采用BCD码格式,24[小]时制*/
	*Point1=0x02;		/*不用复时制*/
}
void PORT_Init (void)
{
   //XBR2    = 0x40;      /*时能交叉开关,弱上拉*/
   P74OUT  = 0xff;		/*推挽输出*/
   EMI0CF |= 0x2c;		/*EMIF工作在地址/数据复用方式,只用外部存储器,ALE高/低脉宽占1个SYSCLK周期*/
   EMI0TC |= 0x6c;		/*地址建立/保持时间占0个SYSCLK周期,/WR和/RD占12个SYSCLK周期*/
}
void LCD_Init(void)
{
   P6 = 0x01;
   for(x=0;x<50000;x++);
   //P7 = 0x30;				/*一行显示*/
   P7 = 0x38;				/*两行显示*/
   P6 = 0x0;
   P6 = 0x1; 
   for(x=0;x<1000;x++);
   P7 = 0x0e;				/*显示开,光标显示,光标不闪烁*/
   P6 = 0x0;
   P6 = 0x1;
   for(x=0;x<1000;x++);
   P7= 0x06;				/*显示增加,不平移*/
   P6 = 0x0;
   P6 = 0x1;
   for(x=0;x<5000;x++);
   P7 = 0x01;				/*清屏*/
   P6 = 0x0;
   P6 = 0x1; 
   for(x=0;x<5000;x++);
}
void main (void) {
	unsigned char temp,data1;
	unsigned char TimeVal[10];
	unsigned char xdata  *idata Pointm;
	unsigned char HMS[10]={0x70,0x70},YMD[10]={0x02,0x00};	
  	WDTCN = 0xde;  /*无效看门狗*/
   	WDTCN = 0xad;
   	SYSCLK_Init ();			/*初始化系统时钟*/
	PORT_Init ();			    /*初始化端口*/
                 //DS12887INIT();			/*时钟芯片授时*/
                  LCD_Init();               /*LCD初始化*/
   	//sleep_ms(4000);
do{
temp=temp&0x7f;	/*UIP=0*/
Pointm=CS12887A;/*判断更新周期结束否?查询UIP位*/
temp=*Pointm;
temp=temp&0x80;	/*UIP=0,时钟更新已经完成,可以读取时钟值*/
}while(temp==0x80);/*UIP=1,时钟更新周期正在进行,不能读取时钟值,需继续等待*/
	while(1)
	{
   		P7 = 0x02;			/*回到起始位置*/
   		P6 = 0x0;
   		P6 = 0x01; 
   		Pointm=CS12887;
		for(temp=0;temp<10;temp++)	/*读时间寄存器*/
		{
			TimeVal[temp]=*Pointm;
			Pointm++;
			switch(temp){	/*准备待显示的时间数据*/
				case 0x00:
					HMS[7]=0x0a;
					HMS[8]=(TimeVal[temp]>>4);
					HMS[9]=TimeVal[temp]&0x0f;
					break;
				case 0x02:
					HMS[4]=0x0a;
					HMS[5]=(TimeVal[temp]>>4);
					HMS[6]=TimeVal[temp]&0x0f;
					break;
				case 0x04:
					HMS[2]=(TimeVal[temp]>>4);
					HMS[3]=TimeVal[temp]&0x0f;
					break;
				case 0x07:
					YMD[7]=0x0a;
					YMD[8]=(TimeVal[temp]>>4);
					YMD[9]=TimeVal[temp]&0x0f;
					break;
				case 0x08:
					YMD[4]=0x0a;
					YMD[5]=(TimeVal[temp]>>4);
					YMD[6]=TimeVal[temp]&0x0f;
					break;
				case 0x09:
					YMD[2]=(TimeVal[temp]>>4);
					YMD[3]=TimeVal[temp]&0x0f;
					break;
				default:
					_nop_();
			}
		}
Pointm=CS12887C;
temp=*Pointm;			/*CLEAR C*/
Pointm++;
temp=*Pointm;			/*CLEAR D*/
Pointm=CS12887B;	/*更新周期正常运行,禁止中断,采用BCD码格式,24[小]时制*/
*Pointm=0x02;		/*不用复时制*/
_nop_();
 P6  = 0x05;                             //准备送数据
  for(x=0;x<5000;x++);
lcdpoint=&YMD;
for(lcd_data_count=10;lcd_data_count>0;lcd_data_count--)     //显示第一行字符
{ 
data1=*lcdpoint;
data1 += 0x30;		/*转化成字符码*/
P7 = data1; 		/*送字符数据*/
P6 = 0x04;
P6 = 0x05;
lcdpoint++;
for(x=0;x<100;x++);
}
		P6 = 0x01;
	  P7 = 0xc0;		/*切换到第二行*/
   		P6 = 0x00;	
   		P6 = 0x01; 	
   		for(x=0;x<1000;x++);
	    lcdpoint=&HMS;
	    for(lcd_data_count=10;lcd_data_count>0;lcd_data_count--)     //显示第二行字符
	    { 
		    data1=*lcdpoint;
			data1 += 0x30;		/*转化成字符码*/
		    P7 = data1; 		/*送字符数据*/
			P6 = 0x04;
	        P6 = 0x05;
	        lcdpoint++;
			for(x=0;x<100;x++);
		}
	}
}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -