ds18b20程序 lm386 超声波测距
//pcf8591 AD/DA 转换 #include <reg52.h> #include <display.h> #include <IIC.h> uchar i;
void write_DA(uchar date) { start(); writebyte(0x90);//第一字节写地址 最后一位写是0 respons(); writebyte(0x40);//是芯片工作在数模转换状态 respons(); writebyte(date);// 写数 进行数模转换 respons(); stop(); }
uchar read_AD(uchar kz) // 返回值 { uchar j; start(); writebyte(0x90); respons(); writebyte(kz);//选择通道 respons(); start(); writebyte(0x91); // 读回通道中 由模拟量转换回来的数字量 j=readbyte(); stop(); return j; }
void main() { init(); TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)/256; ET0=1; EA=1; TR0=1; while(1) { display(i);
} }
void t0() interrupt 1 { uchar k; TH0=(65536-50000)/256; TL0=(65536-50000)%256; k++; if(k==20) { k=0; i=read_AD(0x01); //一秒钟刷新一回 0x00 通道1 0x01通道2 0x02 通道3 0x03 通道4 } }