新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > DS18B20和ADC0832共同使用

DS18B20和ADC0832共同使用

作者: 時間:2016-12-01 來源:網(wǎng)絡(luò) 收藏
#include
#define  uchar  unsigned charsbit DQ=P1^4;uchar data    temp_data[2]={0x00,0x00};uchar data    display[5]={0x00,0x00,0x00,0x00,0x00};unsigned char code  ditab[16] ={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;//共陰數(shù)碼管uchar code table[11] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};// 0,1,2,3,4,5 ,6,7,8,9,百位或當(dāng)最高位十位為0時不顯示uchar code table1[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};// 0.,1.,2.,3.,4.,5.,6.,7.,8.,9.各位帶有小數(shù)點的顯示//以下為水位顯示區(qū)域#define uchar unsigned char#define uint unsigned int#define ulong unsigned long#define _rrca_()          CY   = ACC & 0x01           //產(chǎn)生RRC A指令#define _rlca_()          CY   = ACC & 0x80           //產(chǎn)生RLC A指令sbit bADcs=P1^7;sbit bADcl=P1^6;sbit bADda=P1^5;sbit flag=P1^3;//sbit str=P2^7;//sbit d=P2^6;//sbit clk=P2^5;bit choose=0;unsigned char data1;unsigned char count;unsigned char cycle;uint ge,xiao1,xiao2;unsigned long data2;unsigned char  code tablewe[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};//自己寫的void delay_18b20(unsigned int i){while(i--);}//函數(shù)區(qū)域水位void Delayus(uchar i){while(--i);}void ad(void){    uchar i;//data1=0;bADcs = 0;//當(dāng)ADC0832未工作時其CS輸入端應(yīng)為高電平,此時芯片禁用.bADcl=0;bADda=1;bADcl=1;bADcl=0;//i downbADda=1;bADcl=1;bADcl=0; //   2 downbADda=0;bADcl=1;bADcl=0; //   3 downbADda=1;bADcl=1;bADcl=0; //   4 downfor(i=8;i>0;i--){data1<<=1;bADcl=0;bADcl=1;if(bADda==1) data1|=0x01;bADda=1;}bADcs=1;}void cal(){data2=((ulong)data1*493)/252.5;ge=data2/100;xiao1=(data2%100)/10;xiao2=data2%10;}display2(){P2=tablewe[4];                     //P2口低四位位選P0=0x00;        //P0口數(shù)碼管段選第五個數(shù)碼管不用delay_18b20(50);P2=tablewe[5];P0=table1[ge];delay_18b20(50);P2=tablewe[6];P0=table[xiao1];delay_18b20(50);P2=tablewe[7];P0=table[xiao2];}//以上為水位函數(shù)//初始化函數(shù)Init_DS18B20(void){unsigned char x=0;DQ=1;     //DQ復(fù)位delay_18b20(8);   //稍做延時DQ=0;     //單片機將DQ拉低delay_18b20(80);  //精確延時 大于 480usDQ=1;     //拉高總線delay_18b20(14);x=DQ;       //稍做延時后 如果x=0則初始化成功 x=1則初始化失敗delay_18b20(20);}ReadOneChar(void){unsigned char i=0;unsigned char dat=0;for(i=8;i>0;i--){DQ=0; // 給脈沖信號dat>>=1;DQ=1; // 給脈沖信號if(DQ)dat|=0x80 ;delay_18b20(4) ;}return (dat) ;}
				
            
                
			
							
上一頁 1 2 下一頁

關(guān)鍵詞: DS18B20ADC0832共同使

評論


技術(shù)專區(qū)

關(guān)閉