2012年(1008)
分类:
2012-08-01 11:04:03
原文地址:C51算术运算符练习 作者:luozhiyong131
/*
* 位定义实现3个LED的点亮
* 李钦焰 2011.12.01
*/
#include
#define ON 0
#define OFF 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 unchar unsigned char
main()
{
unchar led;
led=0x55;
P1 = led;
while(1);
}
/*
* *的使用
* 李钦焰
* 2011.12.01
*/
#include
#define unchar unsigned char
main()
{
unchar led;
led = 0x00 + 1*8;
P1 = led;
while(1);
}
/*
* 复合赋值运算符的使用
* 李钦焰
* 2011.12.01
*/
#include
#define unchar unsigned 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 unchar unsigned char
main()
{
unchar led;
led=0x00+0xE0;
P1 = led;
while(1);
}
/*
* %的使用
* 李钦焰
* 2011.12.01
*/
#include
#define unchar unsigned char
main()
{
unchar led;
led = 66%5;
P1 = led;
while(1);
}
/*
* <<的使用
* 李钦焰
* 2011.12.01
*/
#include
#define unchar unsigned char
main()
{
unchar led;
led = 0xFF >>3;
P1 = led;
while(1);
}
/*
* &的使用
* 李钦焰
* 2011.12.01
*/
#include
#define unchar unsigned char
main()
{
unchar led;
led = 0x55 & 0xAA;
P1 = led;
while(1);
}