单片机源程序如下:
- #include <reg52.h>
- #include "pcf8591.h"
- #include "i2c.h"
- #include "shumaguan.h"
- #include "Delay.h"
- #include "juzhengjianpan.h"
- #include "zhongduan.h"
- #define pcf8591 0x90 //PCF8591 地址
- char wei=0;
- char a[4],i;
- int zijie,shuru;
- void main()
- {
- T0dingshiqizhongduan();//启动定时中断
- if(wei!=0)
- {
- for(i=0;i<=wei-1;i++)
- {
- printdange(a[i],i);
- }//print已采集到的数字
- }
- while(1)
- {
- if(wei>=4)
- {printshuru(shuru);}
- ADCsend(pcf8591,0x40);//(地址,控制字符)//ox40 为in0采样 inout输出
- printceliang(19.53125*ADCread(pcf8591));
- }
- }
- void jianpanxianshi()interrupt 1
- {
- juzhengjianpan(a);
- TH0=(int)(-20000) >>8;
- TL0=(int)(-20000) ;
- wei++;
- if(wei==4)
- {
- shuru=1000*a[0]+100*a[1]+10*a[2]+a[3];
- zijie=shuru/19.53125;
- DACsend(pcf8591,0x40,zijie);//(地址,控制字符,输入的数据)
- ET0=0;//关闭定时器T0中断
- }
- }
复制代码
所有资料51hei提供下载:
尽力完善第五次实验.rar
(65.31 KB, 下载次数: 12)
|