范文无忧网范文学习范文大全

单片机C语言编程

12月18日 编辑 fanwen51.com

[51单片机C语言编程]代码如下: typedef union { unsigned int myvalue; struct{ unsigned myvalueL:8; unsigned myvalueH:8; }child; }_mytype; _mytype mytype; void main() { mytype.myvalue...+阅读

/*该程序流水灯有两种模式,顺序左移和顺序右移,独立开关控制*/

#include

#include

#define uchar unsigned char

#define uint unsigned int

uchar tmp,flag;

sbit key1=P3^4;

sbit key2=P3^5;

void delay(uint z);

void led();

void keyscan();

void main()

{

tmp=0xfe;

P1=tmp;

while(1)

{

keyscan();

led();

}

}

void keyscan()

{

if(key1==0)

{

delay(10);

if(key1==0)

{

flag=1;

while(key1==0);

}

}

if(key2==0)

{

delay(10);

if(key2==0)

{

flag=0;

while(key2==0);

}

}

}

void led()

{

switch(flag)

{

case 1: {tmp=_crol_(tmp,1);P1=tmp;delay(200);break;}

case 0: {tmp=_cror_(tmp,1);P1=tmp;delay(200);break;}

default: break;

}

}

void delay(uint z)

{

uint x,y;

for(x=z;x>0;x--)

for(y=110;y>0;y--);

}

延伸阅读:

单片机 C语言程序P1=1<<j++;这句错了,<&lt;这个是左移,而不是循环左移 改为这样就可以了 #include <reg52.h> #include<intrins.h> typedef unsigned int uint16; typedef unsigned char uint8;...

推荐阅读
图文推荐
栏目列表