The operation method of register in embedded development

Source: Internet
Author: User

In the development of embedded software, the more common operation is register operation.

For the more lack of hardware knowledge of computer software professionals born, sometimes become a headache, so I summed up a little about register operation of some common usage

Assignment operation Method of register

For illustration convenience, define the following 3 8-bit registers:

#define REG 0XFFFFFF10

1, assigning values to a single bit

(1) Place the Register Reg's 5th position "1"

REG |= (1 << 5);

(2) clearing the Register Reg's 5th digit

REG &= ~ (1 << 5);

(3) The Register reg 3rd, 5 position "1"

REG |= (1 << 5) | (1 << 3);

(4) Clearing the Register Reg's 3rd and 5 digits

REG &= ~ ((1 << 5) | (1 << 3));

2, Direct assignment

(1) Register Reg 0, 1, 2, 3, 5, 7 position "1"

REG = 0x5f;

(That is, give the register REG1 to 1010 1111, this method is more in the initialization of the use)

(2) Register Reg 1, 3, 5, 7 location "1", 0, 2 position "0"

UInt32 temp;

TMEP = REG;

temp &= ~0x01;

Temp |= (1 << 1);

Temp &= ~ (1 << 2);

temp |= (1 << 3);

temp |= (1 << 5);

temp |= (1 << 7);

REG = temp;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.