www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]#include#defineucharunsignedchar#defineuintunsignedint#definers_h(PORTC|=0x01)#definers_l(PORTC&=0xfe)#definers_o(TRISC&=0xfe)#definerw_h(PORTC|=0x02)#definerw_l(PORTC&=0xfd)#definerw_o(TRISC&=0xfd)#d

#include#defineucharunsignedchar#defineuintunsignedint#definers_h(PORTC|=0x01)#definers_l(PORTC&=0xfe)#definers_o(TRISC&=0xfe)#definerw_h(PORTC|=0x02)#definerw_l(PORTC&=0xfd)#definerw_o(TRISC&=0xfd)#defineen_h(PORTC|=0x04)#defineen_l(PORTC&=0xfb)#defineen_o(TRISC&=0xfb)#definetemp_h(PORTC|=0x08)#definetemp_l(PORTC&=0xf7)#definetemp_o(TRISC&=0xf7)#definetemp_i(TRISC|=0x08)#defineled_o(TRISC&=0xef)#defineled_l(PORTC&=0xef)#defineled_h(PORTC|=0x10)#defineLCDPORTBuchardat1,dat2;//保存讀出的溫度zunsignedlongintdat;voiddelayms(uintx)//4M晶振下,延時(shí)1ms{uinty,z;for(y=x;y>0;y--)for(z=110;z>0;z--);}voidDs18b20_reset(void)//DS18B20初始化{uintcount;uchari,flag=1;temp_o;temp_l;for(count=60;count>0;count--);//延時(shí)480ustemp_i;while(flag){if(RC3)flag=1;elseflag=0;}led_o;led_l;//開指示燈for(count=60;count>0;count--);//延時(shí)480us}voidDs18b20_write(uchardatt)//向DS18B20寫一個(gè)字節(jié){ucharcount;uchari;temp_o;for(i=8;i>0;i--){temp_o;temp_l;for(count=1;count>0;count--);if(datt&0x01==0x01)temp_i;else{temp_o;temp_l;}for(count=23;count>0;count--);//延時(shí)60ustemp_i;for(count=1;count>0;count--);datt>>=1;}}ucharDs18b20_read(void)//從DS18B20讀一個(gè)字節(jié){uchari,datt;ucharcount;for(i=8;i>0;i--){datt>>=1;temp_o;temp_l;for(count=1;count>0;count--);temp_i;//改為輸入方向時(shí),上拉電阻把數(shù)據(jù)線拉高,釋放總線,此語句必須有,參考datasheet的P15for(count=1;count>0;count--);if(RC3)datt|=0x80;for(count=23;count>0;count--);//延時(shí)60us}returndatt;}voidlcd_com(ucharcom)//向LCD1602寫命令{rs_o;rw_o;en_o;TRISB=0x00;//配置RB為輸出方向rs_l;rw_l;LCD=com;delayms(1);en_h;delayms(1);en_l;delayms(1);}voidlcd_dat(uchardat)//向LCD1602寫數(shù)據(jù){rs_o;rw_o;TRISB=0x00;//配置RB為輸出方向en_o;rs_h;rw_l;LCD=dat;delayms(1);en_h;delayms(1);en_l;delayms(1);}voidlcd_write(ucharc,ucharr,uchardat)//向LCD1602指定行、指定列、寫數(shù)據(jù){lcd_com(0x80+0x40*c+r);lcd_dat(dat);delayms(1);}voidlcd_init(void)//LCD1602初始化,初始化后第一行顯示temperature:,第二行顯示.C{lcd_com(0x38);lcd_com(0x0c);lcd_com(0x06);lcd_write(0,2,0x54);lcd_write(0,3,0x65);lcd_write(0,4,0x6d);lcd_write(0,5,0x70);lcd_write(0,6,0x65);lcd_write(0,7,0x72);lcd_write(0,8,0x61);lcd_write(0,9,0x74);lcd_write(0,10,0x75);lcd_write(0,11,0x72);lcd_write(0,12,0x65);lcd_write(0,13,0x3a);lcd_write(1,11,0xdf);lcd_write(1,12,0x43);}voidshow(void)//把溫度值送LCD1602顯示{ucharflag;uchart[4];uinttemp;if(dat2>=240){dat=(~(dat2*256+dat1)+1)*(0.0625*10);//取反加一,保留一位小數(shù)flag=1;}else{dat=(dat2*256+dat1)*(0.0625*10);flag=0;};temp=dat%10;t[0]=(0x30+temp);temp=dat%100;temp=temp/10;t[1]=(0x30+temp);temp=dat%1000;temp=temp/100;t[2]=(0x30+temp);temp=dat/1000;t[3]=(0x30+temp);if(flag==1)//負(fù)溫度顯示{lcd_write(1,10,t[0]);lcd_write(1,9,0xa5);lcd_write(1,8,t[1]);lcd_write(1,7,t[2]);lcd_write(1,6,t[3]);lcd_write(1,5,0x2d);}if(flag==0)//正溫度顯示{lcd_write(1,10,t[0]);lcd_write(1,9,0xa5);lcd_write(1,8,t[1]);lcd_write(1,7,t[2]);lcd_write(1,6,t[3]);lcd_write(1,5,0x20);//顯示空格,刷掉負(fù)號(hào)}}voidmain(void){lcd_init();while(1){Ds18b20_reset();Ds18b20_write(0xcc);Ds18b20_write(0x44);//發(fā)送溫度轉(zhuǎn)換命令delayms(1000);//延時(shí)1s,等待溫度轉(zhuǎn)換完成Ds18b20_reset();Ds18b20_write(0xcc);Ds18b20_write(0xbe);//發(fā)送讀溫度寄存器命令dat1=Ds18b20_read();dat2=Ds18b20_read();show();led_h;//關(guān)指示燈delayms(2000);}}//調(diào)試總結(jié)://某IO口8位未全使用時(shí),對(duì)整個(gè)IO口讀取進(jìn)行位運(yùn)算無效

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

//軟件思路:選擇RAO做為模擬輸入通道; // 連續(xù)轉(zhuǎn)換4次再求平均值做為轉(zhuǎn)換結(jié)果 // 最后結(jié)構(gòu)只取低8位 // 結(jié)果送數(shù)碼管的低3位顯示 #include //包含內(nèi)部資源預(yù)定義...

關(guān)鍵字: ad轉(zhuǎn)換 pic16f877a picc

unsigned char eeprom_read(unsigned char addr);void eeprom_write(unsigned char addr, unsigned char value);這兩個(gè)函數(shù)...

關(guān)鍵字: pic16f877a eeprom使用

//*****************電子園PIC16F877A開發(fā)板 SPI總線驅(qū)動(dòng)74595實(shí)驗(yàn)***************////CKP=0; 空閑為低電平//CKP=1; 空閑為高電平//STAT_CKE=0;...

關(guān)鍵字: pic16f877a spi總線 驅(qū)動(dòng)74595

用c語言寫的一個(gè)時(shí)鬧鐘程序單片機(jī)用16F877,主時(shí)鐘用20MHz,用32768作定時(shí)時(shí)間??梢詫?shí)現(xiàn)2路定鬧,每一路都可分別設(shè)置和開關(guān),采用4x4鍵盤,16x2的字符型LCD顯示。連線在程序開頭有...

關(guān)鍵字: pic16f877a 時(shí)鐘 程序 語言

/****************************************************標(biāo)題:萬年歷**說明:包含文件,*****************************...

關(guān)鍵字: pic16f877a 萬年歷 程序

//數(shù)碼管顯示//★★★★★★★★★數(shù)碼管顯示★★★★★★★★★★★\\\\ //單征機(jī)型號(hào):PIC16F877A //功能描述:采用動(dòng)態(tài)掃描方式,初始時(shí)顯示123,當(dāng)按下RB0時(shí),數(shù)值加一,當(dāng)按下RB1時(shí),數(shù)值減一...

關(guān)鍵字: pic16f877a 數(shù)碼管顯示

/************************************************PIC16F877A 內(nèi)部EEPROM讀寫實(shí)驗(yàn)*******Author:hnrainDate:2010-12-26Ver...

關(guān)鍵字: pic16f877a 內(nèi)部eeprom 內(nèi)部函數(shù) 讀寫實(shí)驗(yàn)

/*Capture mode時(shí),外部CCP1事件觸發(fā)后,CCPR1H和CCPR1L將獲取Timer1的TMR1H和TMR1L中的數(shù)值對(duì)于CCP1的觸發(fā)事件,設(shè)置鍵CCP1Con中的相應(yīng)位CCP1M3--CCP1M0CCP...

關(guān)鍵字: capture mode pic16f877a

PIR1 Register The PIR1 register contains the individual flag bits for the peripheralinterrupts.PIR1 REGISTERPS...

關(guān)鍵字: pic16f877a 單片機(jī) spi學(xué)習(xí)
關(guān)閉