单片机的模拟智能灌溉系统
.h>//else IOunsigned char AD_CHANNEL;unsigned long xdata LedOut[8];unsigned int D[32];sbit LS138A=P2^2; sbit LS138B=P2^3;sbit LS138C=P2^4;sbit L1=P2^5;sbit L2=P2^6;sbit beed=P1^0;sbit RELAY=P1^1;sbit k4=P1^2;sbit k5=P1^3;sbit k6=P1^4;sbit k7=P1^5; //此表为 LED 的字模, 共阴数码管 0-9 - unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; unsigned char delay1[8]={10,10,0,0,0,0,0,0};unsigned char HUO,flag;unsigned char key,mode,th;/**延迟函数**/ void delay(){unsigned char a=100;while(a--); }/************at24c02功能模块***/void At24c02Write(unsigned char addr,unsigned char dat){I2C_Start();I2C_SendByte(0xa0, 1);//发送写器件地址I2C_SendByte(addr, 1);//发送要写入内存地址I2C_SendByte(dat, 0); //发送数据I2C_Stop();}unsigned char At24c02Read(unsigned char addr){unsigned char num;I2C_Start();I2C_SendByte(0xa0, 1); //发送写器件地址I2C_SendByte(addr, 1); //发送要读取的地址I2C_Start();I2C_SendByte(0xa1, 1); //发送读器件地址num=I2C_ReadByte(); //读取数据I2C_Stop();return num; }/*******************************************************************ADC发送字节[命令]数据函数 *******************************************************************/bit ISendByte(unsigned char sla,unsigned char c){Start_I2c(); //启动总线SendByte(sla); //发送器件地址if(ack==0)return(0);SendByte(c); //发送数据if(ack==0)return(0);Stop_I2c(); //结束总线return(1);}/*******************************************************************ADC读字节数据函数 *******************************************************************/unsigned char IRcvByte(unsigned char sla){ unsigned char c;Start_I2c(); //启动总线SendByte(sla+1); //发送器件地址if(ack==0)return(0);c=RcvByte(); //读取数据0Ack_I2c(1); //发送非就答位Stop_I2c(); //结束总线return(c);}unsigned char keysan(void){ if(!k7){while(!k7);return 7;}if(!k6){while(!k6);return 6;}if(!k5){while(!k5);return 5;} if(!k4){while(!k4);return 4;}return 0;}/**初始设置函数**/void seting(){ unsigned char isFirstRun=0;beed=1;L1=0;L2=1;RELAY=1;mode=1;isFirstRun=!At24c02Read(2);//通过EEPROM的2地址出是否有值来判断是否为第一次运行if(isFirstRun)//若第一次运行{At24c02Write(2,1);//往2地址写入信息供以后开机时判断At24c02Write(1,50);//写入默认阈值50}else{HUO=At24c02Read(1);//从EEPROM的1地址处读出阈值}delay1[6]=HUO/10;delay1[7]=HUO%10;InitTIMER0(); //初始化定时器0Set_RTC(); }/****判断函数***/void chouse(unsigned char key){ switch(key) { case 4:if(mode==1){ if(j==1){ HUO--;delay1[6]=HUO/10;delay1[7]=HUO%10;delay();} }else { RELAY=1;}break; case 5:if(mode==1){if(j==1){ HUO++; if(HUO>99)HUO=99;delay1[6]=HUO/10;delay1[7]=HUO%10;delay();}}else {RELAY=0;}break;case 6:if(mode==1){ if(flag==1)//在设置模式,保存阈值并退出设置模式{At24c02Write(1,HUO);//在EEPROM的1地址处写入阈值flag=0;}else//不在设置模式,将进入设置模式{flag=1;}}else {beed=(beed==1)?0:1;} break;case 7:if(mode==1){mode=0;L1=0;L2=1;}else {mode=1;L1=1;L2=0;} break;default:break;}if(th
单片机模拟智能灌溉系 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)