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.