forked from flyher/shumeipai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRaspberry Pi的GPIO端口控制入门_1.html
45 lines (45 loc) · 42.3 KB
/
Raspberry Pi的GPIO端口控制入门_1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta name="exporter-version" content=mNote Mac 2.4.10"/><meta name="created" content="2013-07-29T14:21:32Z"/><meta name="updated" content="2013-07-29T14:21:32Z"/><title>Raspberry Pi的GPIO端口控制入门</title></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><td style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: table-cell; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 1689px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; vertical-align: middle; width: 757px; word-wrap: break-word;">
<i style="border: 0px none rgb(153, 153, 153); color: rgb(153, 153, 153); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 32px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 32px; margin: 0px 0px -30px; outline: rgb(153, 153, 153) none 0px; padding: 0px; text-align: center; text-decoration: initial; width: 757px; word-wrap: break-word;"> 本帖最后由 奇迹的龙 于 2013-1-16 01:29 编辑 </i><br>
<br>
考完研闲了一段时间,这两天开始正式学习单片机开发,以便完成毕业设计。本来想跟大家分享Raspberry Pi与STM32F4DISCOVERY开发板之间,使用nRF24L01无线模块进行通讯的方法,无奈水平有限,暂时还没能调试好,为了赶上爱板网的这次分享活动,就先将Raspberry Pi的GPIO端口控制方法跟大家分享一下,其他的以后再发。<br>
<br>
<strong style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;"><font color="#ff0000" style="border: 0px none rgb(255, 0, 0); color: rgb(255, 0, 0); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(255, 0, 0) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">第一步</font></strong>,安装系统.建议Raspberry Pi官方的Debian系统,在这里下载好镜像之后,dd至SD卡上即可,系统的初始化设置可能需要用到显示器。<br>
<br>
<strong style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;"><font color="#ff0000" style="border: 0px none rgb(255, 0, 0); color: rgb(255, 0, 0); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(255, 0, 0) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">第二步</font></strong>,使用SSH登录Raspberry Pi。默认用户名:pi,密码:raspberry,主机名:raspberrypi,将Raspberry Pi通过网线连上路由器之后,使用ssh命令登录:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 39px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">ssh pi@raspberrypi</li></ol></div><em onclick="copycode($('code_AU6'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div><strong style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;"><font color="#ff0000" style="border: 0px none rgb(255, 0, 0); color: rgb(255, 0, 0); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(255, 0, 0) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">第三步</font></strong>,下载并安装GPIO库。首先下载源代码:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 39px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">wget http://www.open.com.au/mikem/bcm2835/bcm2835-1.16.tar.gz</li></ol></div><em onclick="copycode($('code_hhO'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div>然后编译安装:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 123px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 105px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 105px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">tar xzvf bcm2835-1.16.tar.gz<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">cd bcm2835-1.16<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">./configure<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">make<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">sudo make install</li></ol></div><em onclick="copycode($('code_5Nc'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div><strong style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;"><font color="#ff0000" style="border: 0px none rgb(255, 0, 0); color: rgb(255, 0, 0); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(255, 0, 0) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">第四步</font></strong>,示例。这个C库暂时还没有文档,所以只能先看代码注释了解用法,好在代码不多。下面用这个交替闪烁两个LED灯的示例来验证下吧。<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 669px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 651px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 651px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">#include <bcm2835.h><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">#define LEDA_PIN RPI_GPIO_P1_16 /* LED灯A使用P1上的16引脚 */<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">#define LEDB_PIN RPI_GPIO_P1_18 /* LED灯A使用P1上的18引脚 */<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">int main(int argc, char **argv)<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">{<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> if (!bcm2835_init())<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> return 1;<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> /* 初始化GPIO端口 */<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_fsel(LEDA_PIN, BCM2835_GPIO_FSEL_OUTP);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDA_PIN, LOW);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_fsel(LEDB_PIN, BCM2835_GPIO_FSEL_OUTP);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDB_PIN, LOW);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> while (1) {<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDA_PIN, HIGH);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDB_PIN, LOW);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_delay(250);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDA_PIN, LOW);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_gpio_write(LEDB_PIN, HIGH);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> bcm2835_delay(250);<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> }<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"><br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"> return 0;<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">}<br>
</li><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;"></li></ol></div><em onclick="copycode($('code_8kj'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div><strong style="border: 0px none rgb(68, 68, 68); color: rgb(68, 68, 68); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(68, 68, 68) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;"><font color="#ff0000" style="border: 0px none rgb(255, 0, 0); color: rgb(255, 0, 0); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px; outline: rgb(255, 0, 0) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">第五步</font></strong>,编译运行。将上面的代码保存为文件,比如rpi_led.c,然后上传到Raspberry上:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 39px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">scp rpi_led.c pi@raspberrypi:~</li></ol></div><em onclick="copycode($('code_GD0'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div>编译:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 39px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">gcc rpi_led.c -l rt -l bcm2835 -o rpi_led</li></ol></div><em onclick="copycode($('code_jHj'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div>将两只LED灯分别连接到GPIO23、GPIO24和Ground,运行:<div style="background-image: url(http://www.eeboard.com/bbs/static/image/common/codebg.gif); background-attachment: scroll; background-origin: padding-box; background-clip: border-box; background-color: rgb(247, 247, 247); background-size: auto; border: 1px solid rgb(204, 204, 204); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 39px; margin: 10px 0px; outline: rgb(102, 102, 102) none 0px; overflow: hidden; padding: 10px 0px 5px 10px; text-decoration: initial; width: 745px; word-wrap: break-word; background-position: 0px 0px; background-repeat: no-repeat repeat;"><div style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 745px; word-wrap: break-word;"><ol style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: block; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: 21px; font-family: Tahoma, 'Microsoft Yahei', Simsun; height: 21px; margin: 0px 0px 0px 10px; outline: rgb(102, 102, 102) none 0px; padding: 0px; text-decoration: initial; width: 735px; word-wrap: break-word; list-style: decimal outside none;"><li style="border: 0px none rgb(102, 102, 102); color: rgb(102, 102, 102); display: list-item; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 21.59375px; font-family: Monaco, Consolas, 'Lucida Console', 'Courier New', serif; height: 21px; margin: 0px 0px 0px 24px; outline: rgb(102, 102, 102) none 0px; padding: 0px 0px 0px 10px; text-align: left; text-decoration: initial; width: 701px; word-wrap: break-word; list-style: decimal-leading-zero outside none;">sudo ./rpi_led</li></ol></div><em onclick="copycode($('code_Mz6'));" style="border: 0px none rgb(51, 102, 153); color: rgb(51, 102, 153); cursor: pointer; display: inline; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: 18px; font-family: Tahoma, 'Microsoft Yahei', Simsun; margin: 0px 0px 0px 43px; outline: rgb(51, 102, 153) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">复制代码</em></div>怎么样,两只LED灯是不是已经开始交替闪烁了?<br>
<br>
<br>
</td></div><div><a href="thread-6791-1-1.html" style="border: 0px none rgb(51, 51, 51); color: rgb(51, 51, 51); display: inline; font-style: normal; font-variant: normal; font-weight: bold; font-size: 16px; line-height: normal; font-family: 'Microsoft Yahei', Hei, Tahoma, SimHei, sans-serif; outline: rgb(51, 51, 51) none 0px; padding: 0px; text-decoration: initial; word-wrap: break-word;">【分享】Raspberry Pi</a></div></body></html>