寄存器赋值

1、赋值

假如一个寄存器BIT14位要设置为1

struct s3c_ts_regs {

unsigned long adccon;

};

static volatile struct s3c_ts_regs *s3c_ts_regs;

s3c_ts_regs = ioremap(0x58000000, sizeof(struct s3c_ts_regs));

s3c_ts_regs->adccon = (1<<14)|(49<<6);

1<<14 操作

0000 0000 0000 0001 左移14位

那么就是

0100 0000 0000 0000

就是在它的14位上置1了

如果需要在他的6-13置49这个值 怎么做

49 = 0011 0001 左移6位

0000 1100 0100 0000

所以就是49 <<6 就可以表示把这个49赋值给6:13位了

2、取出寄存器某一位的值

假如取出adccon寄存器的14位并判断

if ( s3c_ts_regs->adccon & ( 1 << 14 ) )

{

}

else

{

}

猜你喜欢

转载自blog.csdn.net/ll148305879/article/details/94001266