Use IAR's Extended Language features to write reusable code

Source: Internet
Author: User

The IAR Language extension feature # value # is mainly used for macro implementation. The value in the middle of # Is the value you pass in. Can be used to improveCodeReusability. You can use it when writing timer3 and timer4 of the standard. Because these two 8-bit timers are basically the same. The following figure shows how to implement common timer3 and timer4 header files. You can use a header file to perform timer3 or timer4 operations.

# Ifndef _ timer34_h # DEFINE _ timer34_h # define clear_timer34_counter (timer) \ t # timer # CTL & = ~ 0x04 # define timer34_enable_overflow_int (timer, Val) \ (T ## timer ## CTL = (VAL )? T ## timer # CTL | 0x08: T ## timer # CTL &~ 0x08) # define timer34_start (timer, Val) \ (T ## timer ## CTL = (VAL )? T ## timer # CTL | 0x10: T ## timer # CTL &~ 0x10) # define timer34_set_clock_divide (timer, Val) \ do {\ t ## timer ## CTL & = ~ 0xe0; \ (val = 2 )? (T ## timer ## CTL | = 0x20): \ (val = 4 )? (T ## timer ## CTL | = 0x40): \ (val = 8 )? (T ## timer ## CTL | = 0x60): \ (val = 16 )? (T ## timer ## CTL | = 0x80): \ (val = 32 )? (T # timer # CTL | = 0xa0): \ (val = 64 )? (T ## timer ## CTL | = 0xc0): \ (val = 128 )? (T # timer # CTL | = 0xe0): \ (T # timer # CTL | = 0x00); \} while (0) # define timer34_set_mode (timer, Val) \ do {\ t # timer # CTL & = ~ 0x03; \ (val = 1 )? (T ## timer ## CTL | = 0x01): \ (val = 2 )? (T ## timer ## CTL | = 0x02): \ (val = 3 )? (T # timer # CTL | = 0x03): \ (T # timer # CTL | = 0x00); \} while (0) void timer34_init (void); # endif

Note that to use this feature, you must make the following settings in the Project Settings and select the check boxes.

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.