嵌入式C语言学习
置位:
bits = bits | (1<<7); //sets bit 7
bits |= (1<<7); //set sbit 7
#define SET_BIT (n,bits) do{bits |= (1<<n)}while(0)
清除:
bits &= ~(1<<7); //clears bit 7
#define CLR_BIT (n,bit) do{bits &=~ (1<<n)}while(0)
反转位:
bits ^= (1<<6); //flips bit 6
#define FLIP_BIT (n,bits) do{bits ^=(1<<n)}while(0)
时间的提取和插入
提取位:
插入位:
相关代码
实现时钟
#define DATA_Addr 0xFFFC0000;
#define tme *(int *) DATA_Addr;
int getHour()
{
int Hour;
Hours=time>>11)&0x1F;
return Hours;
}
void SetHours(int Hours)()
{
oldtime=TIME;
newtime=oldtime&~(0x1F<<11);
TIME=newtime;
}
实现分钟
#define DATA_Addr 0xFFFC0000;
#define tme *(int *) DATA_Addr;
int getMinutes()
{
int Minutes;
Minutes=time>>5)&0x3F;
return Minutes;
}
void SetMinutes(int Minutes)()
{
oldtime=TIME;
newtime=oldtime&~(0x3F<<5);
TIME=newtime;
}