目录
一次赋值即可一次性控制并行口P1共8个IO口



P1 |= (1<<5) << 左移五位

| 或运算符
P1 &=~ (1<<5) << 左移五位

~ 取反
& 与

if(LED==1) 输入高电平 if(Px &(~(1<
if(LED==0) 输入低电平
- void Delay_xms(unsigned char ms) //延时xms
- {
- unsigned int i,j;
- for(i=0;i
- for(j=0;j<333;j++); //空指令
- }
- }
控制LED灯闪烁
方法一
- void delay_xms(unsigned char ms) //延时xms
- {
- unsigned int i,j;
- for(i=0;i
- for(j=0;j<333;j++); //空指令
- }
- }
- sbit LED1=P0^0;
-
- sbit LED2=P0^1;
-
- sbit LED3=P0^2;
-
- sbit LED4=P0^3;
-
- sbit LED5=P0^4;
-
- sbit LED6=P0^5;
-
- sbit LED7=P0^6;
-
- sbit LED8=P0^7;
- void main()
- {
- while(1){
- LED1=0;delay(500);LED1=1;
- LED2=0;delay(500);LED2=1;
- LED3=0;delay(500);LED3=1;
- LED4=0;delay(500);LED4=1;
- LED5=0;delay(500);LED5=1;
- LED6=0;delay(500);LED6=1;
- LED7=0;delay(500);LED7=1;
- LED8=0;delay(500);LED8=1;
- }
- }
方法二
- void delay_xms(unsigned char ms) //延时xms
- {
- unsigned int i,j;
- for(i=0;i
- for(j=0;j<333;j++); //空指令
- }
- }
unsigned char LED_DAT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- void main(){
- while(1){
- unsigned char i;
- for(i=0;i<8;i++){
- P0=LED_DAT[i];
- delay_xms(500);
- }
- }
- }
方法三
- void delay_xms(unsigned char ms) //延时xms
- {
- unsigned int i,j;
- for(i=0;i
- for(j=0;j<333;j++); //空指令
- }
- }
- void main(){
- while(1){
- unsigned char temp=0xfe,i;
- temp=0xfe; //1111 1110 -> 1111 1101 -> 1111 1011
- for(i=0;i<8;i++){
- P0=temp;
- temp=(temp<<1)+1;
- delay_xms(500);
- }
- }
- }
-
相关阅读:
Windows 下安装NPM
在CentOS中开启mysql服务
linux清理缓存垃圾命令和方法介绍
体验 ABP 的功能和服务
《最新出炉》系列入门篇-Python+Playwright自动化测试-50-滚动条操作
【python基础】input函数
【版本控制工具一】Git 安装注册及使用
Windows 11 Insider Preview Build 22621.730/22623.730(KB5017385)发布!
YOLOv5:修改backbone为ConvNeXt
【luogu P4887】【模板】莫队二次离线(第十四分块(前体))(莫队)
-
原文地址:https://blog.csdn.net/qq_50942093/article/details/127041294