流水灯实验
2016-03-31 19:06
323 查看
单片机基本实验,流水灯。
首先需添加
延迟函数delay(); 定义一个中转变量temp,对其赋值为0xfe,0xfe代表第一个灯亮(二进制是11111110),每次移位后赋值给P1; (P1控制LED灯亮)
首先需添加
#include<intrins.h>,后面需要用到移位crol或者cror函数;
延迟函数delay(); 定义一个中转变量temp,对其赋值为0xfe,0xfe代表第一个灯亮(二进制是11111110),每次移位后赋值给P1; (P1控制LED灯亮)
#include<reg51.h> #include<intrins.h> #define uchar unsigned char #define uint unsigned int void delay(uint n); uchar temp; void main() { temp=0xfe; P1=temp; while(1) { delay(1000); temp=_crol_(temp,1); P1=temp; } } void delay(uint n) { uint j,i; for(i=0; i<n; i++) for(j=0; j<110; j++) ; }
相关文章推荐
- 51单片机的中断整理
- 时钟+温度+遥控设置,综合时钟例子
- 温度传感器+I2C+串口+PC上位机(pyserial)例子
- 51单片机中data,idata,xdata,pdata的区别
- 什么叫51单片机最小系统
- 用串口连接GSM手机发送和接收短消息,在应用程序中如何编程实现?
- MCU之心路分享
- 按键led
- 单片机学会释放CPU
- 单片机无线串行接口电路设计
- 单片机无线串行接口电路设计
- 单片机系统中的红外通信接口
- 单片机系统中的红外通信接口
- 单片机实现接收从电脑发送过来的字符串的方法
- 单片机IO口模拟串口程序(发送+接收
- DSP、ARM和单片机的区别
- 转:接地:数字地、模拟地、信号地、交流地、直流地、屏蔽地、浮地
- 单片机存储器之flash,eeprom,sram,dram简介
- 程序状态字(PSW)的动画说明,
- 51单片机