单片机C语言程序设计实训100例基于8051 Proteus仿真Word下载.docx
- 文档编号:15340334
- 上传时间:2022-10-29
- 格式:DOCX
- 页数:128
- 大小:1.53MB
单片机C语言程序设计实训100例基于8051 Proteus仿真Word下载.docx
《单片机C语言程序设计实训100例基于8051 Proteus仿真Word下载.docx》由会员分享,可在线阅读,更多相关《单片机C语言程序设计实训100例基于8051 Proteus仿真Word下载.docx(128页珍藏版)》请在冰豆网上搜索。
//延时
voidDelayMS(uintx)
{
uchari;
while(x--)
{
for(i=0;
i<
120;
i++);
}
}
//主程序
voidmain()
while
(1)
LED=~LED;
DelayMS(150);
02从左到右的流水灯
从左到右的流水灯
接在P0口的8个LED从左到右循环依次点亮,产生走马灯效果
intrins.h>
P0=0xfe;
P0=_crol_(P0,1);
//P0的值向左循环移动
038只LED左右来回点亮
8只LED左右来回点亮
程序利用循环移位函数_crol_和_cror_形成来回滚动的效果
P2=0x01;
7;
i++)
{
P2=_crol_(P2,1);
//P2的值向左循环移动
DelayMS(150);
}
P2=_cror_(P2,1);
//P2的值向右循环移动
04花样流水灯
花样流水灯
16只LED分两组按预设的多种花样变换显示
ucharcodePattern_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,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,0xff,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
};
ucharcodePattern_P2[]=
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,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,0xff,0xff,0xff,0xff,0xff,0xff,
{//从数组中读取数据送至P0和P2口显示
136;
P0=Pattern_P0[i];
P2=Pattern_P2[i];
DelayMS(100);
05LED模拟交通灯
/*名称:
LED模拟交通灯
东西向绿灯亮若干秒,黄灯闪烁5次后红灯亮,红灯亮后,南北向由红灯变为绿灯,若干秒后南北向黄灯闪烁5此后变红灯,东西向变绿灯,如此重复。
sbitRED_A=P0^0;
//东西向灯
sbitYELLOW_A=P0^1;
sbitGREEN_A=P0^2;
sbitRED_B=P0^3;
//南北向灯
sbitYELLOW_B=P0^4;
sbitGREEN_B=P0^5;
ucharFlash_Count=0,Operation_Type=1;
//闪烁次数,操作类型变量
while(x--)for(i=0;
//交通灯切换
voidTraffic_Light()
switch(Operation_Type)
case1:
//东西向绿灯与南北向红灯亮
RED_A=1;
YELLOW_A=1;
GREEN_A=0;
RED_B=0;
YELLOW_B=1;
GREEN_B=1;
DelayMS(2000);
Operation_Type=2;
break;
case2:
//东西向黄灯闪烁,绿灯关闭
DelayMS(300);
YELLOW_A=~YELLOW_A;
GREEN_A=1;
if(++Flash_Count!
=10)return;
//闪烁5次
Flash_Count=0;
Operation_Type=3;
case3:
//东西向红灯,南北向绿灯亮
RED_A=0;
RED_B=1;
GREEN_B=0;
Operation_Type=4;
case4:
//南北向黄灯闪烁5次
YELLOW_B=~YELLOW_B;
Operation_Type=1;
while
(1)Traffic_Light();
06单只数码管循环显示0~9
单只数码管循环显示0~9
主程序中的循环语句反复将0~9的段码送至P0口,使数字0~9循环显示
ucharcodeDSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
uchart;
while(x--)for(t=0;
t<
t++);
uchari=0;
P0=0x00;
{/*for(;
11;
i++){P0=~DSY_CODE[i];
DelayMS(300);
}//注:
另一方案*/
P0=~DSY_CODE[i];
i=(i+1)%10;
DelayMS(300);
078只数码管滚动显示单个数字
8只数码管滚动显示单个数字
数码管从左到右依次滚动显示0~7,程序通过每次仅循环选通一只数码管
uc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机C语言程序设计实训100例基于8051 Proteus仿真 单片机 语言程序设计 100 基于 8051 Proteus 仿真
![提示](https://static.bdocx.com/images/bang_tan.gif)