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

📄 ds1302._c

📁 DS1302
💻 _C
📖 第 1 页 / 共 2 页
字号:
			{WriteTime[i]=0x6a;
				} 
			if(WriteTime[i]==0x80)
			{WriteTime[i]=0x7a;
				} 
				if(WriteTime[i]==0x90)
		    {WriteTime[i]=0x89;
			} 
			else
			WriteTime[i]=WriteTime[i]-1;
}
/*ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
     按键检测主程序
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/
 void keypress(void)//按键检测程序
 {
  	  if(!(PINC&0X08))
 	  {int NoGong=0,move=0;
	   while(!(PINC&0X08));//检测按键释放
	    NoGong=1;
	    while(NoGong==1)//功能键按下
		{
	             black(13,0);//闪烁时的背景线
				 LCD_write_char(13,0,secondtl+48);//初始状态second闪烁
				               DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
                            if(!(PINC&0x20))  //检测加一按键
                              {delay_nus(30);
							    while(!(PINC&0X20));
							    PlusForSET(5);//设置秒
							   DS1302_WriteTime();  	
		                       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          } 
						    if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							   SubForSET(5);//设置秒
							   DS1302_WriteTime();  	
		                       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          }
//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc			 
	             
                  if(!(PINC&0x10))//检测移位按键
                   {while(!(PINC&0X10));
    				move=1;
	                 while(NoGong==1)
				      {
					  
					           DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc					   
					   while(move==1) //设置分钟位置
					    {  black(10,0);
						   LCD_write_char(10,0,minutetl+48);
						       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
							//cccccccccccccccccccccccccccccccccccc   
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));						  
						       PlusForSET(4);//设置分钟
							   DS1302_WriteTime();  	
		                       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          } 
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
								SubForSET(4);				   
							   DS1302_WriteTime();
							   DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          }
							   if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
						   
					     if(!(PINC&0x10))//检测移位按键
                         {while(!(PINC&0X10));
					      move=2;
					     }						 
					   }//move=1
//cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc					   
					   while(move==2)//设置小时位置
					    {  black(7,0);
						   LCD_write_char(7,0,hourtl+48);
						       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
						   //cccccccccccccccccccccccccccccccccccccccccc
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));
							      PlusHour(3);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间
							      SendDataForDisplay();//显示设置
					          } 
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							      SubHour(3);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间							      
							   SendDataForDisplay();//显示设置
					          }
							  if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
						   
					     if(!(PINC&0x10))//检测移位按键
                         {while(!(PINC&0X10));
					      move=3;
					     }						 
					   }//move=2
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc					   
					   while(move==3) //设置日位置
					    {  black(13,1);
						   LCD_write_char(13,1,datetl+48);
						       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
						   //ccccccccccccccccccccccccccccccccccccc
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));
							      PlusDay(2);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          } 
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							      SubDay(2);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          }
						   
						     if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
							 
					     if(!(PINC&0x10))//检测移位按键
                         {while(!(PINC&0X10));
					      move=4;
					     }						 
					   }//move=3
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc				   
					   while(move==4)//设置月位置
					    {  black(10,1);
						   LCD_write_char(10,1,monthtl+48);
						   DS1302_ReadTime(); //读取当前时间
						   SendDataForDisplay();//显示设置
							//ccccccccccccccccccccccccccccccccccccccccc   
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));
							      PlusMonth(1);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          } 
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							      SubMonth(1);
							      DS1302_WriteTime();
							      DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          }
						   
						      if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
						   
					     if(!(PINC&0x10))//检测移位按键
                         {while(!(PINC&0X10));
					      move=5;
					     }						 
					   }//move=4
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc					   
					   while(move==5)//设置年位置
					    {  black(7,1);
						   LCD_write_char(7,1,yeartl+48);
						   DS1302_ReadTime(); //读取当前时间
						   SendDataForDisplay();//显示设置
						   //ccccccccccccccccccccccccccccccccccccccccc
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));
							      PlusYear(0);
							      DS1302_WriteTime();
							      DS1302_ReadTime();
							   SendDataForDisplay();//显示设置
					          } 
							  
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							    SubYear(0);
							    DS1302_WriteTime();
							    DS1302_ReadTime();
							    SendDataForDisplay();//显示设置
					          }
						   
						      if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
						   
					      if(!(PINC&0x10))//检测移位按键
                          {while(!(PINC&0X10));
					      move=0;					 
					      }						 
					   }//move=5
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
                     while(move==0)//设置秒位置
					    {  black(13,0);
						   LCD_write_char(13,0,minutetl+48);
						   DS1302_ReadTime(); //读取当前时间
						   SendDataForDisplay();//显示设置
						   //cccccccccccccccccccccccccccccccccccccccccccccccc
						      if(!(PINC&0x20))  //检测加一按键
                              {while(!(PINC&0X20));
							   PlusForSET(5);//设置秒
							   DS1302_WriteTime();  	
		                       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          } 
							  if(!(PINB&0x01))//检测减一按键
                              {while(!(PINB&0X01));
							   SubForSET(5);//设置秒
							   DS1302_WriteTime();  	
		                       DS1302_ReadTime(); //读取当前时间
							   SendDataForDisplay();//显示设置
					          }
							   if(!(PINC&0x08))   //检测功能键
                                {while(!(PINC&0X08));
                                 NoGong=2;
								 move=6;//使此值与所有的判断值都不相等
                                }
						   
					     if(!(PINC&0x10))//检测移位按键
                         {while(!(PINC&0X10));
					      move=1;
					     }
           			   }//move=1
				   
				     }//while(NoGong==1)end
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
//ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc	   
                } //检测第一次移位按键的结尾
			   
	       if(!(PINC&0x08)) //检测功能键为第二次按下时退出
           {while(!(PINC&0X08));
           NoGong=2;
            }
	   }//功能键按下第一次的循环
	}//功能按键按下的结尾
  }//KEYPRESS()结尾
  
void LCDFirst(void)
{
  LCD_write_string(0,0,"2007 Graduate!!!");
  LCD_write_string(0,1,"Name:CenWenJiao");// 姓名
  delay_nus(100000); 
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
   LCD_write_command(0x01);//清屏程序
  LCD_write_string(0,0,"  IFID SYSTEM !");
  LCD_write_string(0,1,"  TIME module !"); //题目
  delay_nus(100000); 
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
  delay_nus(100000);
  LCD_write_command(0x01);//清屏程序
    
}
/*CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
  系统主函数
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC*/
void main()
{char CO=0;
//port_init();
init_devices(); //初始化1302
//delay_nus(1000);

init_devicesl();  //初始化LCD1602
DS1302_WriteTime();//时间校准
//LCDFirst();  //显示开机词 
while(1)
 { 
  DS1302_ReadTime(); //读取时间
  /*second1=second;
  minute1=minute;
  hour1=hour;
  date1=date;
  month1=month;
  year1=year;*/
  SendDataForDisplay();//显示时间
  keypress();         //按键检测
 }
}
/////////////////////////////////////////////////////////////////////////
////////////////vc++ icc/avr 20070502 programEnd Time:13:50/////////////
///////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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