ds18b20的時(shí)序圖如下:
復(fù)位時(shí)序:
讀寫時(shí)序:
#include <linux/module.h>
#include #include #include #include #include #include #include #include #include #include #include #include #include #define GPH3_0CON 0xE0200C60 #define GPH3_0DAT 0xE0200C64 #define GPH3_0PUD 0xE0200C68 unsigned int *gpio_config; unsigned char *gpio_data; unsigned int *gpio_pud; static struct class *fog_class; //′′?¨àà static struct class_device *fog_class_devs; //′′?¨àà??ó|μ?éè±? int major; struct mutex res_mutex; void Ds18b20_Pin_Init(void) { unsigned int pin_val; gpio_request(S5PV210_GPH3(0),'my_ds1802'); gpio_config = ioremap(GPH3_0CON,4); gpio_data = ioremap(GPH3_0DAT,1); gpio_pud = ioremap(GPH3_0PUD,2); pin_val = readl(gpio_pud); pin_val &=~(0x0003); pin_val |= 0x2; writel(pin_val,gpio_pud); pin_val = readl(gpio_data); writel(pin_val|0x1,gpio_data); } void DS18B20_OUT( unsigned char value) { if( value == 1) { gpio_direction_output( S5PV210_GPH3(0), 1); } else { gpio_direction_output( S5PV210_GPH3(0), 0); } } unsigned char DS18B20_IN( void ) { unsigned int pin_val; gpio_direction_input( S5PV210_GPH3(0)); pin_val = readl(gpio_data); return pin_val&0x1; } static void Init_DS18B20(void) { gpio_direction_output( S5PV210_GPH3(0), 1); udelay(200); gpio_direction_output( S5PV210_GPH3(0), 0); udelay(600); gpio_direction_output( S5PV210_GPH3(0), 1); udelay(480); } static void WriteCode(unsigned char dat) { unsigned char temp,i; for(i=0;i<8;i++) { temp = dat&0x01; gpio_direction_output( S5PV210_GPH3(0), 1); udelay(2); gpio_direction_output( S5PV210_GPH3(0), 0); if(temp == 0x01) { udelay(2); gpio_direction_output( S5PV210_GPH3(0), 1); udelay(100); }else{ udelay(100); gpio_direction_output( S5PV210_GPH3(0), 1); udelay(3); } dat = dat>>1; } } static void Reset_DS18B20( void ) { gpio_direction_output( S5PV210_GPH3(0), 0); udelay(500); gpio_direction_output( S5PV210_GPH3(0), 1); udelay(480); } static unsigned int ReadData(void) { unsigned int rec,data,i; data = 0; for(i=0;i<16;i++) { gpio_direction_output( S5PV210_GPH3(0), 0); udelay(5); udelay(3); rec = DS18B20_IN(); udelay(20); if(rec){ data |= 0x8000; }else{ data &= 0x7fff; } if(i<15) data >>=1; udelay(20); gpio_direction_output( S5PV210_GPH3(0), 1); udelay(5); } return (data); } int ds18b20_open(struct inode *node, struct file *filp) { return 0; } static int ds18b20_read(struct file * file, char * buffer, size_t count, loff_t *ppos) { int tem; int ds_value; mutex_lock_interruptible(&res_mutex); Ds18b20_Pin_Init(); Init_DS18B20(); WriteCode(0xcc); WriteCode(0x44); gpio_direction_input( S5PV210_GPH3(0)); udelay(100); tem = DS18B20_IN(); if(tem) { gpio_direction_output( S5PV210_GPH3(0), 1); Reset_DS18B20(); WriteCode(0xcc); WriteCode(0xbe); ds_value = ReadData(); }else{ udelay(50); ds_value = 0xaaaa; } mutex_unlock(&res_mutex); copy_to_user(buffer, &ds_value, 4); return sizeof ds_value; } static struct file_operations ds18b20_fops = { .open = ds18b20_open, .read = ds18b20_read, }; static int Ds18b20_init(void) { major = register_chrdev( 0,'ds18b20_drv', &ds18b20_fops ); fog_class = class_create(THIS_MODULE,'ds18b20_class'); fog_class_devs = device_create(fog_class,NULL,MKDEV(major,0),NULL,'my_ds1802'); mutex_init(&res_mutex); printk('install module successedn'); return 0; } void Ds18b20_exit(void) { unregister_chrdev( major, 'ds18b20_drv' ); device_unregister(fog_class_devs); class_destroy(fog_class); } module_init(Ds18b20_init); module_exit(Ds18b20_exit); MODULE_LICENSE('GPL');
上一篇:【驅(qū)動(dòng) 】frambuffer中顯示屏參數(shù)的修改
下一篇:字符設(shè)備驅(qū)動(dòng)(1)代碼分析---之gpio_to_irq
推薦閱讀最新更新時(shí)間:2025-06-28 18:17


設(shè)計(jì)資源 培訓(xùn) 開發(fā)板 精華推薦
- 神經(jīng)形態(tài)芯片可能是革新機(jī)器人實(shí)時(shí)電機(jī)控制的未來
- 從三個(gè)方面理解ARM嵌入式系統(tǒng)
- 自動(dòng)報(bào)警 基于MCU的家庭防盜報(bào)警系統(tǒng)的設(shè)計(jì)
- 存儲(chǔ)控制器及其訪問外設(shè)的原理
- 基于51系列單片機(jī)的智能照明控制系統(tǒng)設(shè)計(jì)方案
- 基于STM32的四旋翼飛行器控制系統(tǒng)
- 單片機(jī)應(yīng)用編程技巧解析
- 基于89C52的教室智能節(jié)能照明系統(tǒng)設(shè)計(jì)
- 一種新型的雨量光照傳感器的設(shè)計(jì)
- A_21_V10基于IPS2電機(jī)換向傳感器的設(shè)計(jì)
- DC500A-B,使用 LTC3406ES5-1.5 的演示板,2.7V 至 5.5Vin,1.5Vout @ 600mA max 同步降壓穩(wěn)壓器
- 使用 Analog Devices 的LT1934的參考設(shè)計(jì)
- LT6656BCS6-2.5、2.5V 低功率 ADC 電壓基準(zhǔn)的典型應(yīng)用
- 使用 Cypress Semiconductor 的 MAX13082EESA 的參考設(shè)計(jì)
- 使用 Analog Devices 的 LT3091HFE 的參考設(shè)計(jì)
- AD8625ARZ-REEL單極輸出精密放大器典型應(yīng)用電路
- LT1351 的典型應(yīng)用 - 250 uA、3MHz、200V/us 運(yùn)算放大器
- 根據(jù) EN50121-3-2(雙輸出)使用帶有 EMC 濾波的 RP40-4812SFR DC/DC 轉(zhuǎn)換器的典型應(yīng)用
- LTC7149IFE 24V 輸入至 -12V 輸出、1MHz 降壓穩(wěn)壓器的典型應(yīng)用電路
- 2026年LiDAR市場(chǎng)可望達(dá)57億美 ADAS成長(zhǎng)潛力足
- 日本半導(dǎo)體,前途未卜
- Basemark開發(fā)出全球首個(gè)通用操作系統(tǒng)RockSolid Core 可大大縮短新車開發(fā)時(shí)間
- Redmi K50與K50 Pro曝光:頂配版上驍龍8平臺(tái)
- 乘用車DHT專用控制器的陽(yáng)光解決方案
- xMEMS推出集成DynamicVent的微型揚(yáng)聲器Montara Pro
- 示波器的負(fù)載效應(yīng)
- STM32-一個(gè)例子搞懂EXTI外部中斷/事件系統(tǒng)
- 大聯(lián)大品佳集團(tuán)推出基于Nuvoton產(chǎn)品的電池監(jiān)測(cè)方案
- 高性能電動(dòng)滑板車 BLDC 電機(jī)驅(qū)動(dòng)器:技術(shù)解析與應(yīng)用展望
- 5G工業(yè)網(wǎng)關(guān)的“邊緣計(jì)算+AI推理”一體化設(shè)計(jì),PLC協(xié)議解析與缺陷檢測(cè)的實(shí)時(shí)聯(lián)動(dòng)
- AR眼鏡的“工業(yè)指令投射”系統(tǒng),SLAM的空間定位、PLC數(shù)據(jù)實(shí)時(shí)疊加顯示
- 多光譜氣體傳感器的抗交叉干擾設(shè)計(jì)
- 多模態(tài)融合感知的“語義-幾何”聯(lián)合建模
- 工業(yè)觸摸屏的“壓感-手勢(shì)”多模態(tài)交互設(shè)計(jì)
- 工業(yè)機(jī)器人高精度力控的“雙模融合”傳感器設(shè)計(jì)
- 工業(yè)機(jī)器人集群的“數(shù)字孿生-物理實(shí)體”閉環(huán)優(yōu)化
- 工業(yè)以太網(wǎng)交換機(jī)的“時(shí)間敏感網(wǎng)絡(luò)(TSN)”改造
- 工業(yè)現(xiàn)場(chǎng)信號(hào)測(cè)試:耦合方式選擇實(shí)戰(zhàn)案例
- 智慧救援設(shè)備亮相抗洪一線,續(xù)航力成為安全保障
- STM8 復(fù)位寄存器地址映射
- STM8 復(fù)位(RST)寄存器
- STM8 存儲(chǔ)器保護(hù)
- STM8 用戶啟動(dòng)區(qū)域(UBC)
- 出海掃地機(jī)器人品牌「UONI由利」獲5000萬A輪融資
- 「知行機(jī)器人」獲數(shù)千萬人民幣A+輪融資,三合資本投資
- 5G基站覆蓋全國(guó)地級(jí)以上城市 累計(jì)開通96.1萬個(gè)
- 歐美爭(zhēng)取芯片國(guó)產(chǎn)化 臺(tái)積電:不切實(shí)際、浪費(fèi)數(shù)千億美元
- 51單片機(jī)(五)—— GPIO點(diǎn)亮一個(gè)LED
- CONV_INTEGER ,CONV_STD_LOGIC_VECTOR使用詳解
- 介紹一下全國(guó)大學(xué)生電子設(shè)計(jì)大賽
- 免費(fèi)得旅行收納袋以及電子工程辭典!!只要關(guān)注【Vishay威士科技】
- TM4C1294XL時(shí)鐘問題
- 藍(lán)牙IPR是什么東東?????
- 請(qǐng)不要做浮躁的嵌入式系統(tǒng)工程師(謹(jǐn)以此文與大家共勉)
- 有關(guān)C6000中編程優(yōu)化
- 請(qǐng)教關(guān)于sizeof的一個(gè)問題
- PB.50編譯出錯(cuò),尋求高手指點(diǎn)
- 據(jù)說服務(wù)器要停機(jī)升級(jí),大家抓緊時(shí)間灌水啊