ImageVerifierCode 换一换
格式:DOCX , 页数:143 ,大小:458.49KB ,
资源ID:12992648      下载积分:6 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-12992648.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(51单片机仿真100实例.docx)为本站会员(b****6)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

51单片机仿真100实例.docx

1、51单片机仿真100实例 单片机C语言程序设计实训100例基于8051+Proteus仿真案例 第 01 篇 基础程序设计 01 闪烁的LED 名称:闪烁的LED/* LED按设定的时间间隔闪烁 说明: */ #include #define uchar unsigned char #define uint unsigned int sbit LED=P10; 延时/ void DelayMS(uint x) uchar i; while(x-) for(i=0;i120;i+); /主程序 void main() while(1) LED=LED; DelayMS(150); 从左到右的流水

2、灯02 /* 名称:从左到右的流水灯LED个P0口的8接在 说明:产生走从左到右循环依次点亮, 马灯效果 */ #include #include #define uchar unsigned char #define uint unsigned int /延时 void DelayMS(uint x) uchar i; while(x-) for(i=0;i120;i+); /主程序 void main() P0=0xfe; while(1) P0=_crol_(P0,1); /P0的值向左循环移动 DelayMS(150); 03 8只LED左右来回点亮 /* 名称:8只LED左右来回点亮

3、 说明:程序利用循环移位函数_crol_和_cror_形成来回滚动的效果 */ #include #include #define uchar unsigned char #define uint unsigned int /延时 void DelayMS(uint x) uchar i; while(x-) for(i=0;i120;i+); /主程序 void main() uchar i; P2=0x01; while(1) for(i=0;i7;i+) P2=_crol_(P2,1); /P2的值向左循环移动 DelayMS(150); for(i=0;i7;i+) P2=_cror_

4、(P2,1); /P2的值向右循环移动 DelayMS(150); 04 花样流水灯 /* 名称:花样流水灯 说明:16只LED分两组按预设的多种花样变换显示 */ #include #define uchar unsigned char #define uint unsigned int uchar code Pattern_P0= 0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,

5、0x81,0x00,0x81,0xc3,0xe7,0xff, 0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f, 0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,0xff, 0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0

6、xff,0xff,0xff,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe, 0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe, 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff ; uchar code Pattern_P2= 0xff,0xff,0xff,0xf

7、f,0xff,0xff,0xff,0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0xff, 0xe7,0xdb,0xbd,0x7e,0xbd,0xdb,0xe7,0xff,0xe7,0xc3,0x81,0x00,0x81,0xc3,0xe7,0xff, 0xaa,0x55,0x18,0xff,0xf0,0x0f,0x00,0xff,0xf8,0xf1,0xe3,0xc7,0x8f,0x1f,0x3f,0x7f, 0x7f,0x3f,0x1f,0x8f,0xc7,0xe3,0xf1,0xf8,0xff,0x00,0x00,0xff,0xff,0x0f,0xf0,

8、0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00, 0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff,0

9、xff,0xff,0xff,0xff,0xff,0xff, 0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff ; /延时 void DelayMS(uint x) uchar i; while(x-) for(i=0;i120;i+); /主程序 void main() uchar i; while(1) /从数组中读取数据送至P0和P2口显示 for(i=0;i136;i+) P0=Pattern_P0i; P2=Pattern_P2i; DelayMS(100); 05 LED模拟交通灯 /* 名称:LED模拟交通灯 说明:东西向绿灯亮若干秒,黄灯闪烁5次后红

10、灯亮, 红灯亮后,南北向由红灯变为绿灯,若干秒后南北向黄灯闪烁5此后变红灯,东西向变绿灯,如此重复。 */ #include #define uchar unsigned char #define uint unsigned int sbit RED_A=P00; /东西向灯 sbit YELLOW_A=P01; sbit GREEN_A=P02; sbit RED_B=P03; /南北向灯 sbit YELLOW_B=P04; sbit GREEN_B=P05; uchar Flash_Count=0,Operation_Type=1; /闪烁次数,操作类型变量 /延时 void Delay

11、MS(uint x) uchar i; while(x-) for(i=0;i120;i+); /交通灯切换 void Traffic_Light() switch(Operation_Type) case 1: /东西向绿灯与南北向红灯亮 RED_A=1;YELLOW_A=1;GREEN_A=0; RED_B=0;YELLOW_B=1;GREEN_B=1; DelayMS(2000); Operation_Type=2; break; case 2: /东西向黄灯闪烁,绿灯关闭 DelayMS(300); YELLOW_A=YELLOW_A;GREEN_A=1; if(+Flash_Coun

12、t!=10) return; /闪烁5次 Flash_Count=0; Operation_Type=3; break; case 3: /东西向红灯,南北向绿灯亮 RED_A=0;YELLOW_A=1;GREEN_A=1; RED_B=1;YELLOW_B=1;GREEN_B=0; DelayMS(2000); Operation_Type=4; break; case 4: /南北向黄灯闪烁5次 DelayMS(300); YELLOW_B=YELLOW_B;GREEN_B=1; if(+Flash_Count!=10) return; Flash_Count=0; Operation_T

13、ype=1; /主程序 void main() while(1) Traffic_Light(); 06 单只数码管循环显示09 /* 名称:单只数码管循环显示09 说明:主程序中的循环语句反复将09的段码送至P0口,使数字09循环显示 */ #include #include #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff; /延时 void DelayMS(uint x) uchar

14、 t; while(x-) for(t=0;t120;t+); /主程序 void main() uchar i=0; P0=0x00; while(1) /* for(;i11;i+) P0=DSY_CODEi; DelayMS(300); /注:另一方案 */ P0=DSY_CODEi; i=(i+1)_x0010_; DelayMS(300); 07 8只数码管滚动显示单个数字 /* 名称:8只数码管滚动显示单个数字 说明:数码管从左到右依次滚动显示07,程序通过每次仅循环选通一只数码管 */ #include #include #define uchar unsigned char #

15、define uint unsigned int uchar code DSY_CODE=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90; /延时 void DelayMS(uint x) uchar t; while(x-) for(t=0;t120;t+); /主程序 void main() uchar i,wei=0x80; while(1) for(i=0;i8;i+) P2=0xff; /关闭显示 wei=_crol_(wei,1); P0=DSY_CODEi; /发送数字段码 P2=wei; /发送位码 DelayMS(300);

16、 08 8只数码管动态显示多个不同字符 电路如上图 /* 名称:8只数码管动态显示多个不同字符 说明:数码管动态扫描显示07。 */ #include #include #define uchar unsigned char #define uint unsigned int uchar code DSY_CODE=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90; /延时 void DelayMS(uint x) uchar t; while(x-) for(t=0;t120;t+); /主程序 void main() uchar i,wei

17、=0x80; while(1) for(i=0;i8;i+) P2=0xff; P0=DSY_CODEi; /发送段码 wei=_crol_(wei,1); P2=wei; /发送位码 DelayMS(2); 09 8只数码管闪烁显示数字串 电路如上图 /* 名称:8只数码管闪烁显示数字串 说明:数码管闪烁显示由07构成的一串数字 本例用动态刷新法显示一串数字,在停止刷新时所有数字显示消失。 */ #include #define uchar unsigned char #define uint unsigned int /段码表 uchar code DSY_CODE=0xc0,0xf9,0

18、xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90; /位码表 uchar code DSY_IDX=0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80; /延时 void DelayMS(uint x) uchar t; while(x-) for(t=0;t120;t+); /主程序 void main() uchar i,j; while(1) for(i=0;i30;i+) for(j=0;j8;j+) P0=0xff; P0=DSY_CODEj; /发送段码 P2=DSY_IDXj; /发送位码 DelayMS(2); P2=0x

19、00; /关闭所有数码管并延时 DelayMS(1000); 10 8只数码管滚动显示数字串 电路如上图 /* 名称:8只数码管滚动显示数字串 说明:数码管向左滚动显示3个字符构成的数字串 */ #include #include #define uchar unsigned char #define uint unsigned int /段码表 uchar code DSY_CODE=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff; /下面数组看作环形队列,显示从某个数开始的8个数(10表示黑屏) uchar Num=10,10,

20、10,10,10,10,10,10,2,9,8; /延时 void DelayMS(uint x) uchar t; while(x-) for(t=0;t120;t+); /主程序 void main() uchar i,j,k=0,m=0x80; while(1) /刷新若干次,保持一段时间的稳定显示 for(i=0;i15;i+) for(j=0;j8;j+) /发送段码,采用环形取法,从第k个开始取第j个 P0=0xff; P0=DSY_CODENum(k+j); m=_crol_(m,1); P2=m; /发送位码 DelayMS(2); k=(k+1); /环形队列首支针k递增,N

21、um下标范围010,故对11取余 11 K1-K4 控制LED移位 /* 名称:K1-K4 控制LED移位 说明:按下K1时,P0口LED上移一位; 按下K2时,P0口LED下移一位; 按下K3时,P2口LED上移一位; 按下K4时,P2口LED下移一位; */ #include #include #define uchar unsigned char #define uint unsigned int /延时 void DelayMS(uint x) uchar i; while(x-) for(i=0;i120;i+); /根据P1口的按键移动LED void Move_LED() if

22、(P1&0x10)=0) P0=_cror_(P0,1); /K1 else if(P1&0x20)=0) P0=_crol_(P0,1); /K2 else if(P1&0x40)=0) P2=_cror_(P2,1); /K3 else if(P1&0x80)=0) P2=_crol_(P2,1); /K4 /主程序 void main() uchar Recent_Key; /最近按键 P0=0xfe; P2=0xfe; P1=0xff; Recent_Key=0xff; while(1) if(Recent_Key!=P1) Recent_Key=P1; /保存最近按键 Move_LE

23、D(); DelayMS(10); 12 K1-K4 按键状态显示 /* 名称:K1-K4 按键状态显示 说明:K1、K2按下时LED点亮,松开时熄灭, K3、K4按下并释放时LED点亮,再次按下并释放时熄灭; */ #include #define uchar unsigned char #define uint unsigned int sbit LED1=P00; sbit LED2=P01; sbit LED3=P02; sbit LED4=P03; sbit K1=P10; sbit K2=P11; sbit K3=P12; sbit K4=P13; /延时 void DelayMS

24、(uint x) uchar i; while(x-) for(i=0;i120;i+); /主程序 void main() P0=0xff; P1=0xff; while(1) LED1=K1; LED2=K2; if(K3=0) while(K3=0); LED3=LED3; if(K4=0) while(K4=0); LED4=LED4; DelayMS(10); 13 K1-K4 分组控制LED /* 名称:K1-K4 分组控制LED 说明:每次按下K1时递增点亮一只LED,全亮时再次按下则再次循环开始, K2按下后点亮上面4只LED,K3按下后点亮下面4只LED,K4按下后关闭所有L

25、ED */ #include #define uchar unsigned char #define uint unsigned int /延时 void DelayMS(uint x) uchar i; while(x-) for(i=0;i4; k=0; /检查1所在位置,累加获取按键号k while(Key_State!=0) k+; Key_State=1; /根据按键号k进行4种处理 switch(k) case 1: if(P0=0x00) P0=0xff; P0=1; DelayMS(200); break; case 2: P0=0xf0;break; case 3: P0=0x0f;break; case 4: P0=0xff; 14 K1-K4 控制数码管移位显示 /* 名称:K1-K4 控制数码管移位显示 说明:按下K1时加1计数并增加显示位, 按下K2时减1计数并减少显示位, 按下K3时清零。 */ #include #define uchar unsigned ch

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2