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

📄 ds1302.c

📁 SPI FLASH,SL811HST驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
		          {
				   mdelay(8);
				     switch(lcd_count)
				          {case 1:
                                  i = Read1302(DS1302_SECOND);  //读取秒数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                      //秒数减1
                                  down_flag=1;                  //数据调整后更新标志
								  if( 0xff == j  )                    //小于零,转到59秒
                                  j=0x3b;
                                  k=j/10;
                                  temp = (k<<4)|(j%10);
								  break;
				           case 2:
                                  i = Read1302(DS1302_MINUTE);  //读取分数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                      //分数减1
                                  down_flag=1;                  //数据调整后更新标志
								  if( 0xff == j )                    //小于零,转到59分
                                  j=0x3b;
                                  k=j/10;
                                  temp = (k<<4)|(j%10);
								  break;
				           case 3:
                                  i = Read1302(DS1302_HOUR);    //读取小时数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                      //小时数减1
                                  down_flag=1;                  //数据调整后更新标志
								  if(0xff == j)                    //超过23时,清零小于零,转到23时
                                  j=0x17;
                                  k=j/10;
                                  temp = (k<<4)|(j%10);	
								  break;
				          /* case 4:
                                  temp=Read1302(DS1302_WEEK);  //读取星期数
								  temp=temp-1;                 //星期数减1
                                  down_flag=1;
								  if(temp==0)
								  temp=0x7;
								  break; */
				           case 4:
                                  i = Read1302(DS1302_DAY);   //读取日数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                    //日数减1
                                  down_flag=1;                //数据调整后更新标志
								  if(j == 0x0)                  //小于零,转到31
                                  j=0x1f;
                                  k=j/10;
                                  temp = (k<<4)|(j%10);
								  break;
				           case 5:
                                  i = Read1302(DS1302_MONTH);  //读取月数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                     //月秒数减1
                                  down_flag=1;                 //数据调整后更新标志
								  if(j == 0x0)                   //小于零,转到12
                                  j=0xc;
                                  k=j/10;
                                  temp = (k<<4)|(j%10);
								  break;
				           case 6:
                                  i = Read1302(DS1302_YEAR);  //读取年数
                                  j = ((i&0x70)>>4)*10 + (i&0x0F);
								  j = j-1;                    //年数减1
                                  down_flag=1;                //数据调整后更新标志
								  if( j == 0xff )j=0x4f;                //超过59秒,清零小于零,转到最大值
                                  k=j/10;
                                  temp = (k<<4)|(j%10);
								  break;
                           
					       case 7:
                                  step = step-10;
                                  down_flag = 1;
                                  if(step==0)
                                  step = 60;
                                  break; 
					      default:break;
				         } 
				   while(Down==0);
				  }
}

//模式选择按键
void Setkey()
{
		Set = 1;
		if( Set == 0 )
	    {
           mdelay(8);
           lcd_count=lcd_count+1;	 //Setkey按一次,lcd_count就加1
		   if(lcd_count == 10)lcd_count = 1;
           key_finish = 0;
           while(Set==0);
           
           //while(wireless_4==1);
		 }
}

//按键功能执行
void keydone()
{        unsigned char Second;
         if( (lcd_count==0)|| (lcd_count>9) )show_time;
         
		// if(lcd_count==0)    
       //  { Write1302(0x8e,0x00);
        //  temp = Read1302(0x80);
         //  Write1302(0x80,temp|0x80);
	    //  Write1302(0x8e,0x80); //禁止写入
       //    flag=1;
       //  }
         Setkey();				            //扫描模式切换按键
  
      //   if(lcd_count>0)ClearLcd;

		 switch(lcd_count)
		 {case 1:do					        
		          {
                    ClearLcd(); Delay10Us(1);
                     DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                    GotoXY(1,0);
	                Print("Set Time Second"); //显示时间
                    GotoXY(2,0);
	                Print(CurrentTime.TimeString); //显示时间

                   outkey();		   	//扫描跳出按钮
				   Upkey();                //扫描加按钮
				   Downkey();              //扫描减按钮
				   if(up_flag==1||down_flag==1)  
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x80,temp|0x80); //写入新的秒数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }

				   hide_sec++;          //位闪计数
				   if(hide_sec>3)
				   hide_sec=0;
                 //  show_time();
                   
                    DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                    GotoXY(1,0);
	                Print("Set Time Second"); //显示时间
                    GotoXY(2,0);
	                Print(CurrentTime.TimeString); //显示时间
				  }while(lcd_count==2);
				  break;  
		  case 2:do					        
		          {
                               hide_sec=0; 
                               ClearLcd(); Delay10Us(1);
                               DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                               GotoXY(1,0);
	                           Print("Set Time Minute"); //显示时间
                               GotoXY(2,0);
	                           Print(CurrentTime.TimeString); //显示时间
				   
				   outkey();
				   Upkey();
				   Downkey();
				   if(temp>0x60)
				     temp=0;
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x82,temp); //写入新的分数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_min++;
				   if(hide_min>3)
				     hide_min=0;
                   
                               DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                               GotoXY(1,0);
	                           Print("Set Time Minute"); //显示时间
                               GotoXY(2,0);
	                           Print(CurrentTime.TimeString); //显示时间
               //                    show_time();
				  }while(lcd_count==3);break;
		  case 3:do					        
		          {
                                   
                                   hide_min=0; 
				    ClearLcd(); Delay10Us(1);
                   
                                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Time Hour"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.TimeString); //显示时间
                   outkey();
				   Upkey();
				   Downkey();
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x84,temp); //写入新的小时数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_hour++;
				   if(hide_hour>3)
				     hide_hour=0;
                  
                                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           TimeToStr(&CurrentTime);       //时间数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Time Hour"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.TimeString); //显示时间
             //      show_time();
				  }while(lcd_count==4);break;
		/*  case 4:do					        
		          {
                   hide_hour=0; 
				   outkey();
				   Upkey();
				   Downkey();
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x8a,temp); //写入新的星期数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_week++;
				   if(hide_week>3)
				     hide_week=0;
                   show_time();
				  }while(lcd_count==5);break;*/
		  case 4:do					       
		          {        
                                   hide_hour=0; 
                    ClearLcd(); Delay10Us(1);
                        DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Date"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间     
				   outkey();
				   Upkey();
                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Date"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
				   Downkey();
                   
                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	               DateToStr(&CurrentTime);       //日期数据转换液晶字符
                   GotoXY(1,0);
	               Print("Set Date"); //显示时间
                   GotoXY(2,0);
	               Print(CurrentTime.DateString); //显示时间
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x86,temp); //写入新的日数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_day++;
				   if(hide_day>3)
				   hide_day=0;
				  
                                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Date"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
                         //        show_time();
				  }while(lcd_count==5);break;
		  case 5:do					        
		          {
                   hide_day = 0;           
                   ClearLcd();   Delay10Us(1);
                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Month"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
                                   hide_day=0; 
				   outkey();
				   Upkey();
				   Downkey();
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x88,temp); //写入新的月数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_month++;
				   if(hide_month>3)
				     hide_month=0;
                   
                                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Month"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
                                   hide_day=0; 
                         //        show_time();
				  }while(lcd_count==6);break;
		  case 6:do					        
		          {
                                   
                    hide_month=0; 
                    ClearLcd(); Delay10Us(1);
                    DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Year"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
				   outkey();
				   Upkey();
				   Downkey();
				   if(up_flag==1||down_flag==1)
				   {
				   Write1302(0x8e,0x00); //写入允许
				   Write1302(0x8c,temp); //写入新的年数
				   Write1302(0x8e,0x80); //禁止写入
				   up_flag=0;
				   down_flag=0;
				   }
				   hide_year++;
				   if(hide_year>3)
				   hide_year=0;
                  
                                   DS1302_GetTime(&CurrentTime);  //获取时钟芯片的时间数据
	                           DateToStr(&CurrentTime);       //日期数据转换液晶字符
                                   GotoXY(1,0);
	                           Print("Set Year"); //显示时间
                                   GotoXY(2,0);
	                           Print(CurrentTime.DateString); //显示时间
                      //           show_time();
				  }while(lcd_count==7);break;
          case 7: do
                   {                   

                                    
                                     hide_year=0;
                     ClearLcd(); Delay10Us(1); 
                       step_to_str();   
                                     GotoXY(1,0);    
                                     Print("Set step");   
                                     GotoXY(2,0);
                                     Print(&stepBuffer);
                                        outkey();
				     Upkey();
				     Downkey();
                     step_to_str();   
                     GotoXY(1,0);    
                     Print("Set step");   
                     GotoXY(2,0);
                     Print(&stepBuffer);
				     up_flag=0;
				     down_flag=0;
				 

				     hide_step++;          //位闪计数
				     if(hide_step>3)
				     hide_step=0;
                      
                                     step_to_str();   
                                     GotoXY(1,0);    
                                     Print("Set step");   
                                     GotoXY(2,0);
                                     Print(&stepBuffer);
                    //               show_time();
                   //                done=0;         //液晶显示数据
				     }while(lcd_count==8);break;
		  case 8: do
                  {
                    
                    hide_step=0;
                    ClearLcd(); Delay10Us(1);
                     c_to_str();	  
                    GotoXY(1,0);
                    Print("Usb_suevice");
                    GotoXY(2,0);
                    Print(&c_copy);
                    outkey();
                    up_flag=0;
		            down_flag=0;
                     c_to_str();	  
                    GotoXY(1,0);
                    Print("Usb_suevice");
                    GotoXY(2,0);
                    Print(&c_copy);
                    hide_c++;
                    if(hide_c>3)
                    hide_c = 0;
                    
                    c_to_str();	  
                    GotoXY(1,0);
                    Print("Usb_suevice");
                    GotoXY(2,0);
                    Print(&c_copy);
                   }while(lcd_count==9);break;
          case 9: lcd_count=0; hide_c=0;  //count8, 跳出调整模式,返回默认显示状态
	               ClearLcd();show_time();
                   show_time();
                   Second=Read1302(DS1302_SECOND);
                   ClearLcd();show_time();
                   Write1302(0x8e,0x00); //写入允许
	               Write1302(0x80,Second&0x7f);
	               Write1302(0x8E,0x80);          //禁止写入
                   ClearLcd();show_time();
                   show_time();
                   key_finish = 1;
                  break;
		  default:break;
		 }

}

void Delay1ms(unsigned int lcd_count)
{
	unsigned int i,j;
	for(i=0;i<lcd_count;i++)
	for(j=0;j<120;j++);
}



/*void temp_to_str()  
{
	TempBuffer[0]=temp_value/10+'0';  
	TempBuffer[1]=temp_value%10+'0';  
	TempBuffer[2]=0xdf;   
	TempBuffer[3]='C';
	TempBuffer[4]='\0';
}*/


#endif

⌨️ 快捷键说明

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