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

📄 时钟.c

📁 简单的时钟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		   OutputInformation(6,1,0x20);
		   OutputInformation(7,1,0x20);
		  }
		else
		  {OutputInformation(6,1,R1302(0xc5)/16+0x30); //显示闹铃时
		   OutputInformation(7,1,R1302(0xc5)%16+0x30); //显示闹铃时
		  }

/**************************闹铃分闪烁显示*******************/
		if((id==14)&&(a==1))               //闹铃分闪烁
		 {OutputInformation(9,1,0x20);     //不显示
		  OutputInformation(10,1,0x20);    //不显示
		  
		 }
		else
		  {OutputInformation(9,1,R1302(0xc7)/16+0x30);  //显示闹铃分
		   OutputInformation(10,1,R1302(0xc7)%16+0x30); //显示闹铃分
		  }

/************************exit闪烁显示***********************/
		if((id==15)&&(a==1))			   //exie闪烁
		  {OutputInformation(12,1,0x20);   //不显示
	       OutputInformation(13,1,0x20);   //不显示
		   OutputInformation(14,1,0x20);   //不显示
		   OutputInformation(15,1,0x20);   //不显示
		  }
		else
		  DisplayListChar(12,1,exit);	   //显示exit								   
	   }
	 }
}
							
/*********************************背光灯设置*****************************************/
void model4()
{
	  if(id==0)								//id为零未进入背光灯设置
	   {OutputInformation(10,1,0x20);       //不显示
	    OutputInformation(11,1,0x20);       //不显示
	    OutputInformation(4,1,0x20);        //不显示
		DisplayListChar(5,1,reset);         //显示reset		
		DisplayListChar(12,1,exit);         //显示exit
		if(a==1)
		  {OutputInformation(0,1,0x20);     //不显示
	       OutputInformation(1,1,0x20);     //不显示
		   OutputInformation(2,1,0x20);     //不显示
		   OutputInformation(3,1,0x20);     //不显示
		   }
		else
          DisplayListChar(0,1,lamp);        //显示lamp
	    }
	 else 						            //id不为零(10)进入背光灯时间设置
	   {DisplayListChar(0,1,lamp);          //显示lamp
		DisplayListChar(4,1,set);           //显示set
		DisplayListChar(9,1,sec);           //显示sec
		DisplayListChar(12,1,exit);         //显示exit
		if((id==10)&&(a==1))
		   {
			OutputInformation(7,1,0x20);      //不显示		 
            OutputInformation(8,1,0x20);}
		else
		  {
		   OutputInformation(7,1,R1302(0xc1)/16+0x30); //读出背光灯延时时间
		   OutputInformation(8,1,R1302(0xc1)%16+0x30);
		  }
		if((id==11)&&(a==1))
		  {OutputInformation(12,1,0x20);     //不显示
	       OutputInformation(13,1,0x20);     //不显示
		   OutputInformation(14,1,0x20);     //不显示
		   OutputInformation(15,1,0x20);     //不显示
		  }
	 }

}
/*********************************时间归零设置*****************************************/
void model5()
{       
        OutputInformation(4,1,0x20);        //不显示
	    OutputInformation(10,1,0x20);       //不显示
		OutputInformation(11,1,0x20);       //不显示
	    DisplayListChar(0,1,lamp);          //显示lamp
	    DisplayListChar(12,1,exit);         //显示exit
		if(a==1)
		 { OutputInformation(5,1,0x20);     //不显示
	       OutputInformation(6,1,0x20);     //不显示
		   OutputInformation(7,1,0x20);     //不显示
		   OutputInformation(8,1,0x20);     //不显示
		   OutputInformation(9,1,0x20);
		 }
		else
          DisplayListChar(5,1,reset);       //显示reset	  
}
/**********************************退出***********************************************/
void model6()
{
  OutputInformation(10,1,0x20);       //不显示
  OutputInformation(11,1,0x20);       //不显示
  DisplayListChar(0,1,lamp);          //显示lamp
  DisplayListChar(5,1,reset);         //显示reset
  if(a==1)
	 {OutputInformation(12,1,0x20);   //不显示
	  OutputInformation(13,1,0x20);   //不显示
	  OutputInformation(14,1,0x20);   //不显示
	  OutputInformation(15,1,0x20);   //不显示
	 }
  else
     DisplayListChar(12,1,exit);      //显示exit
}

	
  
//********* LCM1602驱动程序 ***************
//写数据
void WriteDataLCM(uchar WDLCM)
{
ReadStatusLCM(); //检测忙
LCM_Data = WDLCM;
LCM_RS = 1;
LCM_RW = 0;
LCM_E = 0; //若晶振速度太高可以在这后加小的延时
LCM_E = 0; //延时
LCM_E = 1;
}
//写指令
void WriteCommandLCM(uchar WCLCM,BuysC)     //BuysC为0时忽略忙检测
 {
  if (BuysC) ReadStatusLCM(); //根据需要检测忙
  LCM_Data = WCLCM;
  LCM_RS = 0;
  LCM_RW = 0; 
  LCM_E = 0;
  LCM_E = 0;
  LCM_E = 1; 
 }
//读状态
uchar ReadStatusLCM(void)
 {
  LCM_RS = 0;
  LCM_RW = 1;
  LCM_E = 0;
  LCM_E = 0;
  LCM_E = 1;
  while (LCM_Data & Busy); //检测忙信号
  return(LCM_Data);
 }
//LCM初始化
void LCMInit(void) 
 {
  LCM_Data = 0;
  WriteCommandLCM(0x38,0); //三次显示模式设置,不检测忙信号
  Delay5Ms(); 
  WriteCommandLCM(0x38,0);
  Delay5Ms(); 
  WriteCommandLCM(0x38,0);
  Delay5Ms(); 
  WriteCommandLCM(0x38,1); //显示模式设置,开始要求每次检测忙信号
  WriteCommandLCM(0x08,1); //关闭显示
  WriteCommandLCM(0x01,1); //显示清屏
  WriteCommandLCM(0x06,1); // 显示光标移动设置
  WriteCommandLCM(0x0C,1); // 显示开及光标设置
 }
//按指定位置显示一个字符
void OutputInformation(uchar X, uchar Y, uchar DData)
 {
  Y &= 0x1;
  X &= 0xF; //限制X不能大于15,Y不能大于1
  if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
  X |= 0x80; //算出指令码
  WriteCommandLCM(X, 0); //这里不检测忙信号,发送地址码
  WriteDataLCM(DData);
 }
//按指定位置显示一串字符  ***原来的遇到空格0x20就不显示***
void DisplayListChar(uchar X, uchar Y, uchar code *DData)
{
  uchar ListLength,j;
  ListLength = strlen(DData);
  Y &= 0x1;
  X &= 0xF; //限制X不能大于15,Y不能大于1
      if (X <= 0xF) //X坐标应小于0xF
        { 
         for(j=0;j<ListLength;j++)
            {
             OutputInformation(X, Y, DData[j]); //显示单个字符
             X++;
            }
        }
}
//5ms延时
void Delay5Ms(void)
 {
  unsigned int TempCyc = 5552;
  while(TempCyc--);
 }
//400ms延时
void Delay400Ms(void)
 {
  uchar TempCycA = 5;
  unsigned int TempCycB;
  while(TempCycA--)
  {
   TempCycB=7269;
   while(TempCycB--);
  }
 }

//********DS1302读写程序***************//
/******************************************************************** 
函 数 名:RTInputByte()
功    能:实时时钟写入一字节
说    明:往DS1302写入1Byte数据 (内部函数)
入口参数:d 写入的数据 
返 回 值:无  
***********************************************************************/
void RTInputByte(uchar d) 
{ 
    uchar i;
    ACC = d;
    for(i=8; i>0; i--)
    {
        T_IO = ACC0;           /*相当于汇编中的 RRC */
        T_CLK = 1;
        T_CLK = 0;
        ACC = ACC >> 1; 
    } 
}
/******************************************************************** 
函 数 名:RTOutputByte()
功    能:实时时钟读取一字节
说    明:从DS1302读取1Byte数据 (内部函数)
入口参数:无  
返 回 值:ACC
设    计:zhaojunjie           日    期:2002-03-19
修    改:                     日    期: 
***********************************************************************/
uchar RTOutputByte(void) 
{ 
    uchar i;
    for(i=8; i>0; i--)
    {
        ACC = ACC >>1;         /*相当于汇编中的 RRC */
        ACC7 = T_IO;
        T_CLK = 1;
        T_CLK = 0;
    } 
    return(ACC); 
}
/******************************************************************** 
函 数 名:W1302()
功    能:往DS1302写入数据
说    明:先写地址,后写命令/数据 (内部函数)
调    用:RTInputByte() , RTOutputByte()
入口参数:ucAddr: DS1302地址, ucData: 要写的数据
返 回 值:无
***********************************************************************/
void W1302(uchar ucAddr, uchar ucDa)
{
    T_RST = 0;
    T_CLK = 0;
    T_RST = 1;
    RTInputByte(ucAddr);       /* 地址,命令 */
    RTInputByte(ucDa);       /* 写1Byte数据*/
    T_CLK = 1;
    T_RST = 0;
}
/******************************************************************** 
函 数 名:R1302()
功    能:读取DS1302某地址的数据
说    明:先写地址,后读命令/数据 (内部函数)
调    用:RTInputByte() , RTOutputByte()
入口参数:ucAddr: DS1302地址
返 回 值:ucData :读取的数据
***********************************************************************/
uchar R1302(uchar ucAddr)
{
    uchar ucData;
    T_RST = 0;
    T_CLK = 0;
    T_RST = 1;
    RTInputByte(ucAddr);             /* 地址,命令 */
    ucData = RTOutputByte();         /* 读1Byte数据 */
    T_CLK = 1;
    T_RST = 0;
    return(ucData);
}

/******************************************************************** 
函 数 名:Set1302()
功    能:设置初始时间
说    明:先写地址,后读命令/数据(寄存器多字节方式)
调    用:W1302()
入口参数:pClock: 设置时钟数据地址 格式为: 秒 分 时 日 月 星期 年
                               7Byte (BCD码)1B 1B 1B 1B 1B  1B  1B
返 回 值:无
***********************************************************************/
void Set1302(uchar *pClock) 
{
    uchar i;
    uchar ucAddr = 0x80; 
    W1302(0x8e,0x00);           /* 控制命令,WP=0,写操作*/
    for(i =7; i>0; i--)
    { 
        W1302(ucAddr,*pClock);  /* 秒 分 时 日 月 星期 年 */ 
        pClock++;
        ucAddr +=2;
    }
    W1302(0x8e,0x80);           /* 控制命令,WP=1,写保护*/
}

⌨️ 快捷键说明

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