【嵌入式linux】(第六步):使用eclipse整合式開發環境開發第一個嵌入式Linux程式,並測試LED驅動

來源:互聯網
上載者:User

 

前言:使用eclipse開發嵌入式linux程式和pc linux程式幾乎沒有區別,並且使用eclipse圖形介面的整合式開發環境上手簡單,方便學習,這裡就教大家開發第一個嵌入式linux程式,程式功能就是測試上次寫好的LED驅動程式。

1.建立工程

輸入工程名稱,選擇可執行程式,選擇cross GCC,下一步,選擇填寫arm-linux-gcc的路徑,這一步按照自己的實際情況進行填寫

點擊完成即可

2.輸入代碼並編譯

代碼很簡單的,只是一個執行個體

/*****************************************************************************************************************檔案名稱:main.c*主要功能:LED測試*作者       :異靈元(cp1300@139.com)*建立時間:2012下午11:52:59*最後修改時間:2012下午11:52:59*說明:使用OK6410開發板,測試自己寫的LED驅動****************************************************************************************************************/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>int main(void){int fd;int retval;unsigned char led;//LED測試printf("LED test...\n");fd = open("/dev/OK6410_LED",O_RDWR);//open led,注意:是驅動模組名,不是驅動檔案名稱if(fd == -1){printf("open led error!\n");exit(-1);}else{printf("open led ok!\n");}while(1){for(retval = 0;retval < 4;retval ++){led = 1 << retval;led = ~led;write(fd,&led,sizeof((unsigned char)1));//read(fd,&led,sizeof((unsigned char)1));//printf("LED = 0x%X\n",led);usleep(1000 * 100);//100MS}for(retval = 2;retval > 0;retval --){led = 1 << retval;led = ~led;write(fd,&led,sizeof((unsigned char)1));//read(fd,&led,sizeof((unsigned char)1));//printf("LED = 0x%X\n",led);usleep(1000 * 100);//100MS}}close(fd);exit(0);}

編寫完代碼後編譯,一般先儲存,設定了編譯前自動儲存只要按下 Ctrl + B 即可,編譯完成後會產生相關的可執行程式,但是這個程式只能在ARM LINUX上執行,不能在PC上面執行。

3.執行程式

將程式複製到開發板執行,如果掛載了NFS就可以直接運行了,運行結果如下,當然還可以看到開發板的燈在來回跑動。。。

有的時候程式無法運行,需要添加可執行屬性

 執行:chmod +x xxxx      xxxx即為編譯好的可執行程式名稱。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.