1705 views|0 replies

3836

Posts

19

Resources
The OP
 

Detailed explanation of MSP430 intrinsics.h [Copy link]

1.1.1 Extended Keywords 1. asm can also be written as _asm. The function is to embed assembly language directly in the C program. asm("string"); where string must be a valid assembly statement. 2. __interrupt is placed in front of the function to mark the interrupt function. The following program is the receiving interrupt function of the asynchronous serial port UART0. UART0RX_VECTOR is the receiving interrupt vector of the asynchronous serial port UART0. Example: #pragma vector=UART0RX_VECTOR __interrupt void UARTO_R(void) { TXBUF0=RXBUF0; } 3. __monitor is placed in front of the function, and its function is to automatically turn off the interrupt when this function is executed. Such functions should be shortened as much as possible, otherwise, the interrupt event cannot be responded to in time. 4. __no_init is placed in front of the global variable, and its function is to make the variable not be assigned an initial value when the program starts. 5. __raw When compiling an interrupt function, the compiler will automatically generate a section of code that first saves the contents of the CPU registers used at the time, and then restores them when exiting the interrupt program. Placing __raw before the interrupt function can prohibit the process of saving the CPU registers, and of course it will not be restored when exiting. Whether to use this keyword for an interrupt function depends on the specific situation. 6. __regvar is placed in front of a variable to declare the variable as a register variable. It can be used for integers, pointers, 32-bit floating-point numbers, and structures and unions with only one element. The address of a register variable can only be R4 or R5, and a pointer cannot be used to point to this register variable, and initialization must be prohibited using __no_init. For example: __regvar __no_init unsigned char q0 @ __R4; Other uncommon keywords include: __data16, __intrinsic, __noreturn, __root, __task, __word16. 1.1.2 Internal functions 1. __bcd_add_short Unsigned short __bcd_add_short(unsigned short,unsigned short); Function: Add two 16-bit BCD format numbers and return the sum. 2. __bcd_add_long Unsigned long __bcd_add_long(unsigned long,unsigned long); Function: Add two 32-bit BCD format numbers and return the sum. 3. __bcd_add_long_long Function: Add two 64-bit BCD format numbers and return the sum. 4. __bic_SR_register Void _bic_SR_register(unsigned short); Function: Clear certain bits in the SR register in the CPU. Its parameter is a mask code, and the bits to be cleared are 1. 5. __bic_SR_register_on_exit Void __bic_SR_register_on_exit(unsigned short); Function: When an interrupt function or a non-interruptible function (flag is __monitor) returns, some bits in the SR register in the CPU are cleared to 0. Its parameter is a mask code, and the bits that need to be cleared are 1. 6. __bis_SR_register Void __bis_SR_register(unsigned short); Function: Set some positions in the SR register in the CPU to 1. Its parameter is a mask code, and the bits that need to be set to 1 are 1. 7. __bis_SR_register_on_exit Void __bis_SR_register_on_exit(unsigned short); Function: When an interrupt function or a non-interruptible function (flag is __monitor) returns, some positions in the SR register in the CPU are set to 1. Its parameter is a mask code, and the bits that need to be set to 1 are 1. 8. __disable_interrupt Void __disable_interrupt(void); Function: Disable global interrupts. Execute the DINT instruction first to disable global interrupts, and then execute the NOP instruction. The NOP instruction is to ensure that the following program is executed after the global interrupt is disabled. 9. __enable_interrupt Void __enable_interrupt(void); Function: Use the _EINT() instruction to enable global interrupts. 10. __even_in_range Unsigned short __even_in_range(unsigned short value,unsigned short upper_limit); Function: Can only be used in conjunction with the switch statement to determine whether value is an even number and less than or equal to upper_limit. Example: Unsigned int MoonRiver,iq0; Iq0=2; Switch(__even_in_range(iq0,4)) { Case 0: MoonRiver=0; Break; Case 2: MoonRiver=2; break; } Result: Assuming the value of iq0 is 2, MoonRiver=2 when the execution is completed. Otherwise, like a normal switch statement, skip the case part and execute the following program directly. The advantage of using __even_in_range is that it can generate more efficient code. This function can be used when judging multiple interrupt sources. 11. __get_interrupt_state Istate_t __get_interrupt_state(void); Function: Returns the current interrupt status. The return value isdate_t is a structure. This function can be used to obtain and save the current interrupt status. In the future, __set_interrupt_state can be used to restore the interrupt status. 12. __get_R4_register Unsigned short __get_R4_register(void); Function: Returns the value of register R4, which is only valid when R4 is locked. 13. __get_R5_register Unsigned short __get_R5_register(void); Function: Returns the value of register R5, which is only valid when R5 is locked. 14. __get_SP_register Unsigned short __get_SP_register(void); Function: Returns the value of the stack pointer register SP. 15. __get_SR_register Unsigned short __get_SR_register(void); Function: Returns the value of the status register SR in the CPU. 16. __get_SR_register_on_exit Unsigned short __get_SR_register_on_exit(void); Function: When an interrupt function or a non-interruptible function (flag is __monitor) returns, it returns the value of the status register SR. Only valid in interrupt functions or non-interruptible functions. 17. __low_power_mode_n Void __low_power_mode_n(void); Function: Enter low power mode 0~4.18. __low_power_mode_off_on_exit Void __low_power_mode_off_on_exit(void); Function: Exit low power mode when returning from an interrupt function or non-interruptible function (flagged by __monitor). Only valid in interrupt or non-interruptible functions. 19. __no_operation Void __no_operation(void); Function: Execute NOP instruction. 20. __op_code __op_code(unsigned short); Function: Insert a constant into the instruction stream. 21. __segment_begin Void *__segment_begin(segment); Function: segment is the name of the segment and must be a string. Returns the address pointing to the segment segment. The segment here is the data segment, code segment, stack segment, etc. defined in the program. Generally, users can use the default settings of the compiler. 22. __segment_end Void *__segment_end(segment); Function: segment is the name of the segment and must be a string. Returns the address of the first byte after the end of segment. 23. __set_interrupt_state Void __set_interrupt_state(istate_t); Function: Restore the interrupt state saved in isate_t. 24. __set_R4_register Void __set_R4_register(unsigned short); Function: Assign unsigned short value to register R4, which is only valid when R4 is locked. 25. __set_R5_register Void __set_R5_register(unsigned short); Function: Assign unsigned short value to register R5, which is only valid when R5 is locked. 26. __set_SP_register Void __set_SP_register(unsigned short); Function: Assign value to stack pointer register SP. 27. __swap_bytes Unsigned short __swap_bytes(unsigned short); Function: A 16-bit unsigned integer, the upper 8 bits are swapped with the lower 8 bits. For example, 0x1234 is swapped to 0x3412. 1.1.3 Extended Definition 1. PxIN, PxOUT, PxDIR, PxSEL X is the port number. IN is the port input register, OUT is the port output register, DIR is the port direction control register, and SEL is the port second function selection register. Example: Moon=P1IN; //Read the value of port P1 P3OUT=5; //P3 port outputs 5 P2DIR=0XF0; //The upper four bits of the P2 port are output, and the lower four bits are input P6SEL=0XF; //The upper four bits of the P6 port are used as I/O ports, and the lower four bits are used for the second function 2. The value range of BITx X is 0~F. Represents a bit of the register. Its definition is: #define BIT0 (0X0001) #define BIT1 (0X0002) … … #define BITE (0X4000) #define BITF (0X8000) BIT0 is the lowest bit, BITF is the highest bit. MSP430 does not support bit operations. If you want to operate on bits, the best way is to implement it through bit masking. Example: P1OUT|=BIT0; //Set the lowest bit output of P1 port to 1 P1OUT&=~BIT7; //Clear the highest bit output of P1 port to 0, P1 port has only 8 bits 3. LMPx X: 0~4. Enter 0~4 low power mode. Its definition is: #define LPM0 _BIS_SR(LPM0_bits) //Enter low power mode 0 … #define LPM0 _BIS_SR(LPM4_BITS) //Enter low power mode 4 From the above code, it can be seen that the extended definition is a secondary packaging of the internal function. For example: LPM0; //Enter low power mode 0 LPM4; //Enter low power mode 4 4. LPMx_EXIT X: 0~4. Exit 0~4 low power mode. Its definition is: #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) //Exit low power mode 0 … #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) //Exit low power mode 4 Example: LPM0_EXIT; LPM4_EXIT; 5. _EINT() Turn on the global interrupt control and make GIE=1. 6. _DINT() Disable global interrupt control, set GIE=0. Execute __disable_interrupt instruction. 7. _NOP() No operation. Execute __no_operation instruction. 8. _OPC(x) Insert a constant into the instruction stream. X is of unsigned char type. Execute __op_code instruction. 9. _SWAP_BYTES(x) X is a 16-bit unsigned integer, the upper 8 bits are swapped with the lower 8 bits. Execute __swap_bytes instruction. 10. __no_init [Data type] Variable name @ address Define a variable without initialization at a fixed address, the address can be in RAM or FLASH. If the variable defined in this way in RAM needs to be assigned a value, it must be defined first, and then assigned a value. Example: /*Allocate variable MoonRiver to RAM address 0x210*/ __no_init unsigned int MoonRiver @ 0x210;//Not initialized MoonRiver=100; //Initialize MoonRiver to 100 /*Allocate variable MoonRiver to FLASH address 0XFFC0*/ __no_init float MoonRiver @0Xffc0; /*Allocate array MoonRiver[3] to RAM address 0X200*/ __no_init char MoonRiver[3] @0x200; /*Allocate structure sMoonRiver to RAM address 0X200*/ typedef struct { Unsigned char q0; Unsigned char iq0; }sMoonRiver; //Define a structure data type named sMoonRiver __no_init sMoonRiver MoonRiver @0x200;//Declare variable MoonRiver, its data type is sMoonRiver MoonRiver.q0=100; MoonRiver.iq0=1000; //Assign the initial value 11 to MoonRiver.Const [Data type] Variable name @ address Defines a read-only variable at a fixed address and can only be assigned an initial value when defined. This way of defining variables is very useful when allocating variables at fixed addresses in FLASH. Example: /* Allocate variable MoonRiver to RAM address 0x210*/ Const unsigned int MoonRiver @0x210 =100;//Initialize MoonRiver to 100 /* Allocate variable MoonRiver to FLASH address 0XFFC0*/ Const float MoonRiver @0XFFC0=32.5;//Initialize MoonRiver to 32.5 /* Allocate array MoonRiver[3] to FLASH address 0XFF00*/ Const char MoonRiver[3] @0Xff00{0,1,2}; /* Allocate structure sMoonRiver to RAM address 0XFFD0*/ Typedef struct { Unsigned char q0; Unsigned char iq0; }sMoonRiver;// Define a structure data type named sMoonRiver Const sMoonRiver MoonRiver @ 0xffd0={2,500}; //Declare the variable MoonRiver, whose data type is sMoonRiver If you do not need to determine the address, point to a variable allocated in FLASH in the form of: Const [data type] variable name; Example: Const unsigned int MoonRiver=100;


This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list