Demo entry 6626047

c

   

Submitted by anonymous on Jun 23, 2017 at 06:38
Language: C. Code size: 3.7 kB.

#include<reg51.h>
#include"lcd.h"
#include"ds1302.h"
#include"lcd.h"
#include"key.h"
#include"delay.h"


 #define uchar unsigned char
 #define uint unsigned int
	

	/////自动控制时信号输入////////
		sbit gg=P1^6;		//光敏电阻信号输入g 
		sbit yy=P1^7;		//下雨传感器信号输入y     //要不要?
		sbit qh=P1^4;
		uchar fan[4]={0xf8,0xf4,0xf2,0xf1};//反转 
uchar zheng[4]={0xf1,0xf2,0xf4,0xf8};//正转 
uchar nian,yue,ri,shi,fen,miao;//变量定义 
uchar shi1,fen1,shi2,fen2;//时分1开启和2关闭比较变量 
uchar writetime[7]; 
uchar writeadd[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80}; //写入数据的地址 
uchar readadd[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};//时钟芯片读出数据的地址
bit chuang_flag;


void  lcd_write_com	(uchar);



void lcd_in()
{ 
	lcd_write_com(0x38); 
	lcd_write_com(0x0c); 
	 lcd_write_com(0x06); 
	lcd_write_com(0x01); 
} 

  void display() //显示函数  显示年月日时分秒 
{ 
 lcd_write_com(0x80); 
 lcd_write_date('D'); 
 lcd_write_date('a'); 
 lcd_write_date('t'); 
 lcd_write_date('a'); 
 
lcd_write_date(':'); 
 writetime[0]=ds1302_read(readadd[0]); 
 write_1602(5,writetime[0]); 
 lcd_write_com(0x80+7); 
 lcd_write_date('-'); 
 writetime[2]=ds1302_read(readadd[2]); 
 write_1602(8,writetime[2]); 
 lcd_write_com(0x80+10); 
 lcd_write_date('-'); 
 writetime[3]=ds1302_read(readadd[3]); 
 write_1602(11,writetime[3]); 
 lcd_write_com(0x80+14); 
 if(chuang_flag==0)lcd_write_date('K'); 
 if(chuang_flag==1)lcd_write_date('G'); 
 
 lcd_write_com(0x80+0x40); 
 lcd_write_date('T'); 
 lcd_write_date('i'); 
 lcd_write_date('m'); 
 lcd_write_date('e'); 
 lcd_write_date(':'); 
 writetime[4]=ds1302_read(readadd[4]); 
 write_1602(0x40+5,writetime[4]); 
  lcd_write_com(0x80+0x40+7); 
 lcd_write_date(':'); 
 writetime[5]=ds1302_read(readadd[5]); 
 write_1602(0x40+8,writetime[5]); 
 lcd_write_com(0x80+0x40+10); 
 lcd_write_date(':'); 
 writetime[6]=ds1302_read(readadd[6]); 
 
write_1602(0x40+11,writetime[6]); 
 lcd_write_com(0x80+0x40+11); 
} 

  
  void deal_with() 
{ 
 uchar ss,ff,a,b; 
 uchar i,j; 
 if(qh==1)//不接短路帽为自动定时控制 
 { 
  display(); 
  keyscan(); 
  a=writetime[4]/16; 
  b=writetime[4]%16; 
  ss=a*10+b; 
 
 a=writetime[5]/16; 
  b=writetime[5]%16; 
  ff=a*10+b; 
  if((shi1!=0)&&(fen1!=0)&&(shi2!=0)&&(fen2!=0)) 
  { 
   if((shi1==ss)&&(fen1==ff)&&(chuang_flag==1))//需要打开窗户的时间和窗是

   { 
    //yy晴天1,下雨0//gg白天0,白天开窗 
    for(j=0;j<128;j++)//步进电机转90° 
    { 
     for(i=0;i<4;i++) 
     { 
      P2=zheng[i]; 
      display(); 
     } 
    } 
    chuang_flag=0;//窗户当前状态开启 
   } 
   if((shi2==ss)&&(fen2==ff)&&(chuang_flag==0))//需要关闭窗户的时间和窗是

   { 
    for(j=0;j<128;j++)//步进电机转90° l     
	{ 
     for(i=0;i<4;i++) 
     { 
      P2=fan[i]; 
      display(); 
     } 
    } 
 
   chuang_flag=1;//1为窗户当前状态关 
   } 
  } 
 } 
 if(qh == 0)//街上短路帽为触发信号控制(光敏电阻和雨滴传感器) 
 { 
  display(); 
  if(yy==0 && chuang_flag==0)//yy=0下雨关窗,0为窗户开的情况(白天)关闭窗

  { 
   for(j=0;j<128;j++)//步进电机转90° 
   { 
    for(i=0;i<4;i++) 
    { 
     P2=fan[i]; 
     display(); 
    } 
   } 
   chuang_flag=1;//1为窗户当前状态关 
  } 
  if((yy==1)&&(gg==1)&&(chuang_flag==0))//0为窗户开,到了晚上需要关窗  
  { 
   //yy晴天1,下雨0 //gg晚上1,晚上关窗   for(j=0;j<128;j++)//步进电机转90° 
   { 
    for(i=0;i<4;i++) 
    { 
     P2=fan[i]; 
     display(); 
    } 
 
  } 
   chuang_flag=1;//1为窗户当前状态关 
 
  } 
  if((yy==1)&&(gg==0)&&(chuang_flag==1))//窗户关,到白天需要开窗  
  { 
   //yy晴天1,下雨0//gg白天0,白天开窗 
   for(j=0;j<128;j++)//步进电机转90° 
   { 
    for(i=0;i<4;i++) 
    { 
     P2=zheng[i]; 
     display(); 
    } 
   } 
   chuang_flag=0;//窗户当前状态开启 
  } 
 }  
} 



  
   void main()
   {
 		lcd_in();
		while(1)
		{
			display();	//显示函数
			keyscan();	 //按键扫描
			deal_with();//窗户开关	
		}  
   }

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).