C51算術(shù)運(yùn)算符練習(xí)
*位定義實(shí)現(xiàn)3個LED的點(diǎn)亮
*李欽焰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);
}
/*
*復(fù)合賦值運(yùn)算符的使用
*李欽焰
* 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);
}
評論