1.png (140.4 KB, 下载次数: 16)
#include<reg52.h> //头文件 |
#include<intrins.h> |
#define uchar unsigned char//宏定义 |
#define uint unsigned int//宏定义 |
sbit Key = P1^0; |
bit Press,Forward; |
void delayms(uchar ms) //延时子函数 |
{ |
uchar i; |
while(ms--) |
{ |
if(Key == 0) Press = 1; //检查Key |
for(i=0;i<123;i++); //酌情减小 |
} |
} |
void main()//主函数 |
{ |
P0=0xFE; |
while(1) |
{ |
delayms(500);//延时100ms |
if(Press) |
{ |
Press = 0; |
Forward = !Forward; |
} |
if(Forward) P0=(P0<<7) | (P0>>1);//循环移位 |
else P0=(P0<<1) | (P0>>7);//循环移位 |
} |
} |
188610329 发表于 2022-10-11 23:07
在你的代码基础上改的。
188610329 发表于 2022-10-11 23:07
在你的代码基础上改的。
zhxiufan 发表于 2022-10-12 08:41
#include //头文件
#include
#define uchar unsigned char//宏定义
zephry 发表于 2022-10-12 10:23
这个优化了上面的,把key从延时函数里移到了主函数里,感谢大佬
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |