Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
while writing values to the registers in microcontrollers we write directly a value to the register such as initializing the gpio pins and again the other way is providing bit values to the registers such as stoping the watchdog timer, kindly explain why these two methods are available and which is the effective one.

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1OUT = 0x01; // Red LED on
P1SEL = 0x10; // P1.4 SMCLK output
P1DIR = 0x51; // P1.0,4,6 output

What I have tried:

I am new to programming and i don't have the idea of providing bit values to the registers whereas I can assign directly assign a required value to the register out of curiosity I want to know the difference between them
Posted
Updated 29-Nov-19 20:53pm

WDT+ can be configured to act as either a Watch Dog Timer or an Interval timer, see explanation here: Configuring the registers of Watch Dog Timer (WDT+) in MSP430G2xxxx | xanthium enterprises[^]
Quote:
... one of the mode is called as interval timer mode ...
The mode selection is done by setting the WDTTMSEL bit in WDTCTL register (WDTTMSEL = 1)

Bit 7 is called "HOLD", and this bit stops the operation of the watchdog counter.

And also: Why do programs stop watchdog timer on MSP430? - Electrical Engineering Stack Exchange[^]
 
Share this answer
 
v4
Comments
Member 14608858 30-Nov-19 5:06am    
WDTCTL = WDTPW + WDTHOLD; format 1
P1OUT = 0x01; format 2

is there a difference between two formats of declaring registers if yes which one is effective?
Generally speaking, you can directly initialize registers because they are memory mapped. Hence you assign a value to a variable and the corresponding bit pattern is set into the target register (and viceversa in a read operation).

Quote:
and again the other way is providing bit values to the registers
I don't get you on this: What is the 'other way', exactly?
 
Share this answer
 
Comments
Member 14608858 30-Nov-19 5:06am    
WDTCTL = WDTPW + WDTHOLD; format 1
P1OUT = 0x01; format 2

is there a difference between two formats of declaring registers if yes which one is effective?
CPallini 30-Nov-19 8:40am    
There is no difference, because both WDTPW and WDTHOLD are just defines (and it looks that WDTPW + WDTHOLD = 0x5680).
Using meaningful names possibly makes the code more readable.
Member 14608858 13-Dec-19 1:01am    
thank you
CPallini 13-Dec-19 2:37am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900