基于8051+Proteu s 仿真案例 第 01 篇 基础程序设计 01 闪烁的LED /* 名称:闪烁的LED 说明:LED 按设定的时间间隔闪烁 */ #include #define uchar unsigned char #define uint unsigned int sbit LED=P1^0; //延时 void DelayMS(uint x) { uchar i; while(x--) { for(i=0;i<120;i++); } } //主程序 void main() { LED=0; while(1) { LED=~LED; DelayMS(150); } } 02 模拟开关灯 /* 监视开关K1(接在P3.0 端口上),用发光二极管L1(接在单片机P1.0 端口上)显示开关状态,如果开关合上,L1 亮,开关打开,L1 熄灭。 */ #include sbit K1=P3^0; sbit L1=P1^0; void main(void) { while(1) { L1=K1; } } 03 从左到右的流水灯 /* 名称:从左到右的流水灯 说明:接在P0 口的8 个LED 从左到右循环依次点亮,产生走马灯效果 */ #include #include #define uchar unsigned char #define uint unsigned int //延时 void DelayMS(uint x) { uchar i; while(x--) { for(i=0;i<120;i++); } } //主程序 void main() { P0=0xfe; while(1) { P0=_crol_(P0,1); //P0 的值向左循环移动 DelayMS(150); } } 04 8 只LED 左右来回点亮 /* 名称:8 只LED 左右来回点亮 说明:程序利用循环移位函数_crol_和_cror_形成来回滚动的效果,仿真图同上 */ #include #include #define uchar unsigned char #define uint unsigned int //延时 void DelayMS(uint x) { uchar i; while(x--) { for(i=0;i<120;i++); } } //主程序 void main() { uchar i,j; j=0x01; while(1) { for(i=0;i<7;i++) { P0=~j; j=_crol_(j,1); //向左循环移动 DelayMS(500); } for(i=0;i<7;i++) { P0=~j; j=_cror_(j,1); //向右循环移动 DelayMS(500); } } } 0 5 花样流水灯 /* 名称:花样流水灯 说明: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,0x81,0x00,0x81,0xc3,0xe7,0xff, 0x...