满意答案
jpovx
2018.04.23
采纳率:40%等级:13
已帮助:10028人
#include #define LED P1 //宏定义,使用LED代替P1口(相当于LED=P1) #define uchar unsigned char //用uchar代替unsigned char方便操作 #define uint unsigned int /*------------------time ms延时函数-----------------*/ void delay_ms(uint time) { uchar tres; for(;time>0;time--) { tres=150; while(tres--); } } void main() { uchar t; LED=0X01;//P1=00000001B while(1)//死循环,不断点亮和熄灭LED { for(t=0;t<8;t ) { LED=~LED;///按位取反,点亮一个LED delay_ms(100);//延时0.1s LED=~LED;//按位取反 LED<<=1;//左移一位,点亮不同的LED } LED=0X80;//P1=10000000B for(t=0;t<8;t ) { LED=~LED;///按位取反,点亮一个LED delay_ms(100).1s LED=~LED;//按位取反 LED>>=1;//右移一位,点亮不同的LED } LED=0X01;//P1=00000001B } }
00分享举报