首页 自动售水机

自动售水机

举报
开通vip

自动售水机自动售水机 #include #include #include #define uint unsigned int #define uchar unsigned char unsigned char code tab1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char code tab2[]=...

自动售水机
自动售水机 #include #include #include #define uint unsigned int #define uchar unsigned char unsigned char code tab1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; unsigned char code tab2[]={0x3f+0x80,0x06+0x80,0x5b+0x80,0x4f+0x80,0x66+0x80,0x6d+0x80,0x7d+0x80,0x07+0x80,0x7f+0x80,0x6f+0x80,0x40+0x80}; unsigned char code tab3[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//;{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; unsigned char i,j,k,l; unsigned int a,b,c,d; sbit scl=P2^1; sbit sda=P2^0; uint baiwei,gewei,shiwei; sbit P0_0=P1^0; sbit P0_1=P1^1; sbit P2_0=P1^7; sbit P1_4=P1^4; sbit P1_2=P1^2; /****************************************************************** 初始化函数 ******************************************************************/ void init_pcf8591() { sda=1; scl=1; } /****************************************************************** 短延时函数 ******************************************************************/ void delay_pcf8591(uchar z) { while(z--); } /****************************************************************** 长延时函数 ******************************************************************/ void delay(uchar z) { uchar x,y; for(x=z;x>0;x--) for(y=100;y>0;y--); } /****************************************************************** 开始函数 ******************************************************************/ void start_pcf8591() { sda=1; delay_pcf8591(1); scl=1; delay_pcf8591(1); sda=0; delay_pcf8591(1); } /****************************************************************** 停止函数 ******************************************************************/ void stop_pcf8591() { sda=0; delay_pcf8591(1); scl=1; delay_pcf8591(1); sda=1; delay_pcf8591(1); } /****************************************************************** 等待应答函数 ******************************************************************/ void ack_pcf8591() { uint t; scl=1; delay_pcf8591(1); while((sda==1)&&t<250) t++; scl=0; delay_pcf8591(1); } /****************************************************************** 写字节函数 ******************************************************************/ void write_pcf8591_byte(uchar add) { uchar i; for(i=0;i<8;i++) { add<<=1; scl=0; delay_pcf8591(1); sda=CY; scl=1; delay_pcf8591(1); } scl=0; delay_pcf8591(1); sda=1; delay_pcf8591(1); } /****************************************************************** 读字节函数 ******************************************************************/ uint read_pcf8591_byte() { uchar temp,i; for(i=0;i<8;i++) { scl=1; delay_pcf8591(1); temp<<=1; temp|=sda; scl=0; delay_pcf8591(1); } return temp; } /****************************************************************** 读pcf8591数据函数 ******************************************************************/ uint readpcf8951_adc() { uint dat; start_pcf8591(); write_pcf8591_byte(0x90); ack_pcf8591(); write_pcf8591_byte(0x41); ack_pcf8591(); start_pcf8591(); write_pcf8591_byte(0x91); ack_pcf8591(); dat=read_pcf8591_byte(); stop_pcf8591(); return dat; } /****************************************************************** display函数 ******************************************************************/ void display() { uchar L; uint n;//vin; n=readpcf8951_adc(); //vin=((n*50)/255); baiwei=n/100; shiwei=n/10%10; gewei=n%10; L=baiwei*100+shiwei*10+gewei; if(L>125) P1_2=1; else P1_2=0; } void delay3(void) { unsigned char a; for(a=0;a<250;a++); {for(a=0;a<80;a++);} } void delay1(unsigned char an) { unsigned char i,j; for(i=0;i
本文档为【自动售水机】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_637320
暂无简介~
格式:doc
大小:25KB
软件:Word
页数:0
分类:企业经营
上传时间:2017-09-01
浏览量:25