微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > C51算术运算符练习

C51算术运算符练习

时间:11-11 来源:互联网 点击:
/*
*位定义实现3个LED的点亮
*李钦焰2011.12.01
*/
#include

#defineON 0
#defineOFF 1

sbit led1=P1^0;
sbit led2=P1^2;
sbit led3=P1^5;

main()
{
bit a;
a=ON;

led1=led2=led3=a;
while(1);
}

/*
* char变量的用法
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=0x55;

P1=led;
while(1);
}

/*
* *的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=0x00+1*8;

P1=led;
while(1);
}

/*
*复合赋值运算符的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char
#define led6(1<6)

main()
{
/*unchar led = 0;
led |= led6 ;//置位
*/
unchar led=0xff;
led&=~led6;

P1=led;
while(1);
}

/*
* +的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=0x00+0xE0;

P1=led;
while(1);
}

/*
* %的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=66%5;

P1=led;
while(1);
}

/*
* <的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=0xFF>>3;

P1=led;
while(1);
}

/*
* &的使用
*李钦焰
* 2011.12.01
*/
#include

#define uncharunsigned char

main()
{
unchar led;
led=0x55&0xAA;

P1=led;
while(1);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top