基於arm的乙個簡單的led驅動

2021-06-20 05:44:26 字數 1694 閱讀 9793

在學寫驅動的時候一定不要盲目的跟從,要有自己的方法。要記住一點,學習驅動要學習驅動的模板,每個驅動程式其結構基本上都是一樣的。只要大家掌握了驅動的結構以後在寫驅動的時候就相對來說要簡單一些。只要大家學會寫驅動過後後頭來看其實驅動都是大同小異的。在這裡我給大家介紹乙個簡單的led驅動的寫法,

#define device_name "drvtest"//巨集定義 定義出這個驅動程式的名字為drvtest 這是為我們以後寫應用程式的時候做準備,我們所寫的應用程式就是通過這個名字來呼叫這個驅動程式的。

/*這兩句是定義了兩個指標只要大家學習了一些裸機程式設計的話都知道,如果想要操作arm上的硬體其實要處理的資料至少有兩個暫存器 乙個是控制控制暫存器 乙個是資料暫存器*/

volatile unsigned int *gpedat=null;//用來指向資料暫存器

//static struct class *drv_test_class;

struct device *dev;

int major,err;

static int drvtest_open(struct inode *inode, struct file *file)

ssize_t drvtest_write(struct file *file, const char __user *data,size_t len, loff_t *ppos)

ssize_t drvtest_read(struct file *file, char __user * buf,size_t len, loff_t * ppos)

static const struct file_operations drvtest_fops = ;

static int __init drv_test_init(void)

major=register_chrdev (0, "drvtest", &drvtest_fops);

printk("2222222222222222222222222222222 \n");

dev=device_create(drv_test_class, null, mkdev(major, 0), null, "drvtest");

printk("33333333333333333333333333333333 \n");

/*struct device *device_create(struct class *class, struct device *parent,

dev_t devt, void *drvdata, const char *fmt, ...)

device_create(my_class,null, devno, null,"hello");*/

printk("drvtest installed ok\n");

//硬體控制 通過指標去指向硬體位址

gpecon=(volatile unsigned int *)ioremap(0x56000010,16);

gpedat=gpecon+1;

*gpecon=1<<22;

*gpedat=0;

//0x56000040

return 0;

}static void __exit drv_test_exit(void)

module_init(drv_test_init);

module_exit(drv_test_exit);

module_license("gpl");

乙個簡單的LED驅動 不基於驅動框架

驅動 include include include include include include include static int led major 1 static struct class led mark class null static struct device led mar...

驅動篇 乙個簡單的led驅動

1.構造裝置結構體 struct light dev cdev結構體 struct cdev 2.設定裝置資訊 struct light dev light devp 設定裝置結構體變數 int light major light major 設定主裝置號3.設定並填充file operations...

基於Proteus的乙個LED燈閃爍實驗

根據原理圖對微控制器進行程式設計,使led燈每隔一小段時間就改變一下量變狀態,若上乙個時間段為點亮狀態,則隔段時間熄滅,間隔時間可相同可不同,這裡我們假定led燈量變間隔時間相同。定義標頭檔案 sbit led p0 0 定義引腳 int i,j void main main代表主函式,程式執行的部...