日韩一区二区三区精品,欧美疯狂xxxxbbbb牲交,热99re久久免费视精品频,人妻互换 综合,欧美激情肉欲高潮视频

Linux嵌入式學(xué)習(xí)-ds18b20驅(qū)動(dòng)

發(fā)布者:Asawen最新更新時(shí)間:2025-01-07 來源: cnblogs關(guān)鍵字:Linux  嵌入式學(xué)習(xí)  ds18b20驅(qū)動(dòng) 手機(jī)看文章 掃描二維碼
隨時(shí)隨地手機(jī)看文章

ds18b20的時(shí)序圖如下:

復(fù)位時(shí)序:

讀寫時(shí)序:

以下是程序代碼


#include <linux/module.h>


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include


#include gpio.h>


#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');


關(guān)鍵字:Linux  嵌入式學(xué)習(xí)  ds18b20驅(qū)動(dòng) 引用地址:Linux嵌入式學(xué)習(xí)-ds18b20驅(qū)動(dòng)

上一篇:【驅(qū)動(dòng) 】frambuffer中顯示屏參數(shù)的修改
下一篇:字符設(shè)備驅(qū)動(dòng)(1)代碼分析---之gpio_to_irq

推薦閱讀最新更新時(shí)間:2025-06-28 18:17

Linux內(nèi)核分析:uboot與Linux內(nèi)核機(jī)器碼分析
1. uboot機(jī)器碼 在uboot啟動(dòng)的start_armboot階段,調(diào)用board_init函數(shù)初始化機(jī)器碼。 int board_init(void) { .............................. gd- bd- bi_arch_number = MACH_TYPE_SMDKV210; gd- bd- bi_boot_params = PHYS_SDRAM_1 + 0x100;   return 0; } 在uboot啟動(dòng)內(nèi)核時(shí),將機(jī)器碼傳參至內(nèi)核。 uboot源碼中,也有一個(gè)/uboot/arch/arm/include/mach-types.h文件,該文件維護(hù)至該版本的u
[單片機(jī)]
Linux 藍(lán)牙系列 -- ARM-Linux藍(lán)牙工具的移植
一 內(nèi)核修改 ------------------------------------------------------------ 將內(nèi)核的藍(lán)牙做成模塊形式。 并配置如下, Bluetooth subsystem support --- L2CAP protocol support SCO links support RFCOMM protocol support RFCOMM TTY support BNEP protocol support HIDP protocol support (NEW) Bluetooth d
[單片機(jī)]
Linux 下PL2302 USB轉(zhuǎn)串口的使用
現(xiàn)在市面上的USB轉(zhuǎn)串口線非常便宜,而且現(xiàn)在大部分機(jī)器都沒有串口.因此在嵌入式LINUX下開發(fā)使用USB轉(zhuǎn)串口的線相當(dāng)普遍.而我測(cè)試最穩(wěn)定是 PL2303芯片,即一般是黑色不透明那種.在WINDOWS XP下使用比較穩(wěn)定.學(xué)生一般問我,我都推薦這種,反而是市面上那種綠色透明的轉(zhuǎn)換線,相當(dāng)不穩(wěn)定. 以下是推薦的串口轉(zhuǎn)USB線,采用PL2303芯片 Y-105 Usb轉(zhuǎn)串口線 Usb轉(zhuǎn)Com USB 轉(zhuǎn) Rs232 9.5元 以下是不推薦的HL340芯片,在LINUX下盡量不要使用. a 五鉆 USB轉(zhuǎn)RS232(COM) USB轉(zhuǎn)串口數(shù)據(jù)線 HL-340芯片 串口線 6.5元 關(guān)于PL230
[單片機(jī)]
<font color='red'>Linux</font> 下PL2302 USB轉(zhuǎn)串口的使用
記錄tiny6410 jlink 命令行調(diào)試linux-2.6.38內(nèi)核
1\首先啟動(dòng)nandflash uboot- linux內(nèi)核- 文件系統(tǒng),進(jìn)入文件系統(tǒng)命令行 2\啟動(dòng)JLinkGDBServer -device ARM11 3啟動(dòng)arm-none-eabi-gdb vmlinux 在這個(gè)命令行中輸入 target remote localhost:2331 monitor halt monitor reset b start_kernel list continue 注意 需要燒寫與所調(diào)試的內(nèi)核一致的內(nèi)核
[單片機(jī)]
S3C6410移植u-boot-2010.3(5)Dnw for linux
  現(xiàn)在開始記錄在linux上安裝dnw功能   想要源代碼,可以到這里fork https://github.com/Qunero/dnw4linux   詳細(xì)的使用,README里面講得很清楚了,不加贅述了。   這里只講一下怎么使用。   1、加載模塊.ko文件 $ cd secbulk_driver/ $ insmod secbulk.ko   然后確認(rèn)一下已經(jīng)加載 $ lsmod | grep secbulk //若正確加載了,應(yīng)該有回顯 secbulk 12728 0   2、插入U(xiǎn)SB to miniUSB線   然后查看一下系統(tǒng)信息 $ dmesg //正常情況下應(yīng)
[單片機(jī)]
友善之臂Micro2440下的Embedded Linux的硬件時(shí)間設(shè)置
最近一直在做Embedded Linux下的項(xiàng)目,平臺(tái)是友善之臂Micro2440。不過有時(shí)會(huì)發(fā)現(xiàn),因?yàn)殚_發(fā)板用的時(shí)間比較長(zhǎng)了,實(shí)時(shí)時(shí)鐘的電池會(huì)沒電,于是造成系統(tǒng)時(shí)間設(shè)置發(fā)生錯(cuò)誤。解決方法當(dāng)然是要更換新的電池,可也要設(shè)置一下時(shí)間問題,主要的命令如下: #date 2012.8.27-16:05:59 #hwclock -w 第一句的意思是設(shè)置系統(tǒng)時(shí)間為2012.8.27-16:05:59 第二句的意思是將系統(tǒng)時(shí)間寫入到硬件實(shí)時(shí)時(shí)鐘中 經(jīng)過上面兩句,重啟后會(huì)發(fā)現(xiàn),時(shí)間初始化將成功,時(shí)鐘恢復(fù)正常。
[單片機(jī)]
基于Linux的S3C2410串行通信設(shè)計(jì)
ARM ADS全稱為ARM Developer suite(ARM開發(fā)套件)。ADS的C++odeWarrior集成開發(fā)環(huán)境(IDE)是基于Metrowerks CodeWarrior IDE4.2版本的,經(jīng)過適當(dāng)?shù)牟眉粢灾С諥DS工具鏈,為管理和開發(fā)項(xiàng)目提供了簡(jiǎn)單多樣化的圖形用戶界面,用戶可以使用ADS的CodeWarrior IDE為ARM和Thumb處理器開發(fā)用C、C++或ARM匯編語言的程序代碼,縮短了用戶開發(fā)項(xiàng)目代碼的周期。ADS中包括3個(gè)調(diào)試器:AXD(ARM ExtendedDebugger)、ARMSD(ARM Symbo l i c Debugger)、ADW/ADU(Appl icat ion Debugger
[單片機(jī)]
基于<font color='red'>Linux</font>的S3C2410串行通信設(shè)計(jì)
JZ2440--linux下給u-boot打補(bǔ)丁并編譯
解壓縮 book@book-desktop:~/zhangbing$ tar xjf u-boot-1.1.6.tar.bz2 2.打補(bǔ)丁 進(jìn)入u-boot-1.1.6并且打補(bǔ)丁 book@book-desktop:~/zhangbing$ cd u-boot-1.1.6/ book@book-desktop:~/zhangbing/u-boot-1.1.6$ patch -p1 ../u-boot-1.1.6_jz2440.patch 3.配置 book@book-desktop:~/zhangbing/u-boot-1.1.6$ make 100ask24x0_config 4.編譯 book@boo
[單片機(jī)]
小廣播
設(shè)計(jì)資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機(jī)文章

 
EEWorld訂閱號(hào)

 
EEWorld服務(wù)號(hào)

 
汽車開發(fā)圈

 
機(jī)器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號(hào) 京ICP備10001474號(hào)-1 電信業(yè)務(wù)審批[2006]字第258號(hào)函 京公網(wǎng)安備 11010802033920號(hào) Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved