How To Set Direction Register For Red, Green Blue Led On Msp430
TheMSP-EXP430G2 is a Evolution Tool a.m.a LaunchPad provided by theTexas Instruments to learn and exercise on how to use their Microcontrollers. This board falls under the MSP430 Value Line category where we can program all the MSP430 serial Microcontrollers. Learninghow to employ TI Microcontrollers would definitely be a mighty tool up in our sleeve because TI is really huge and has a wide verity of MCU'southward to choose from for a very less competitive toll.
We already covered detailed article on using Energia IDE with MSP430. In this tutorial we volition learn well-nigh Code Composer Studio and how it is used to programme MSP430. This tutorial is written for very beginners and no hardware is required except the MSP430 board and a calculator. At the finish of this tutorial we volition be able toBlink the onboard LED of MSP430.
MSP-EXP430G2 Development Lath:
The gorgeous red color lath is the MSP-EXP430G2 Development Board. This board can plan TI Microcontrollers that autumn nether the MSP430 series. The main purpose of this board it to upload lawmaking from the computer to the MCU and read serial data from the MCU for debugging purpose. It also provides the pin-out for each pin of the MCU and also ii LEDs and a push push to make development like shooting fish in a barrel. The lath has evolved a lot since its launch and the one shown below is theMSP_EXP430G2 Rev1.v.
TheMSP430G2553 has amend specifications than the other series, it too has a UART module which would be very handy while debugging usingCode Composer Studio. Hence in this series of tutorials, nosotros will be using the MSP430G2553 to explore all the functionalities of this Development kit.
Powering and Testing the development board :
Earlier we start anything TI would have alreadyuploaded a sample Program on your MSP430G2553 Microcontroller, then allow the states ability the board and cheque if information technology is working. You tin can power lath through the mini USB jack and once y'all exercise information technology, you lot should notice the LEDs (carmine and green) at the lesser left corner of your lath glowing alternatively. You tin can so printing the push push connected to P1.3 to check if the internal temperature sensor is working. Yes, theMSP2553 has an internal temperature sensor, after pressing the button only rub your fingers to warm information technology up and place it on the IC y'all can notice the Cerise LED turns on to bespeak the rise in temperature. Cool!! Correct?? Okay now, let us movement on to the Software Surround.
Programming Software (IDE) for MSP430 LaunchPad:
Texas Instruments allows us to program their Microcontrollers through a variety of Environments. The Official one is the Code Composer Studio commonly known equally the CCS. This software is available gratuitous of cost. As well, it requires some minimal level of experience with Microcontrollers. Don't worry we volition cover every step to get familiar with CCS.
At that place is one more IDE available to write our program i.due east. Energia IDE. So, what is the divergence between CCS and Energia IDE. We already covered Energia IDE in our previous Tutorial.
Energia IDE vs. Code Composer Studio:
Energia is an Open source and costless Surround that enables us to program the TI Microcontrollers easily. The principal aim of Energia is to make programming TI MCU'southward as easy as programming in Arduino. Then Energia is an Equivalent for Arduino that supports Texas Instruments Microcontrollers. People who have used Arduino will hold more than on this once they download and launch the Energia IDE.
Code Composer Studio (CCS) is a more versatile professional IDE which has more than functionalities and capabilities in terms of accessing the inside architecture of microcontroller. It has inbuilt debugging function which can check errors in your code and you tin can run your code line by line that helps in finding error without any headache. It volition take sometime to get comfortable with CCS. Once you gear up with this awesome software, trust me you will get to know anything about a particular microcontroller. You take to accept assist of Datasheet of the microcontroller to write your program.
If you are washed with Arduino iDE or Energia IDE, change your coding environment to CCS, it is most demanding software in Industries.
Downloading and Launching the Code Composer Studio:
This software is available at Texas Instrument'southward website without any cost. And so, you tin can download it from the given link Download link .Nosotros volition use Code Composer Studio V7 but you can download latest version also, procedure remains same.
Either you can download whole software using web installer or download setup/off-line installer. This software is quite heavy around 1GB so, y'all need to wait until it finished downloading.
After downloading the software, open it and install.
When you click on setup, just similar any other software you will be asked to agree terms and weather and to select the installation binder. Afterwards that you have to cull boards for which you desire to download files. In our case we are using MSP430 MCU, click on first option. You can download more than one board files.
Side by side window is to select debug probe. By default i option is available and then, click on it and stop. Now, your installation will start and then just expect until information technology finished.
After installation, it asks about workspace folder and then choose the folder where you lot want to salve your files and click Ok.
And then, let's have a look at the outset window that we will see.
This is a simple interface where you can meet Getting started carte du jour in which you can commencement to make your project ,next to getting started there is a Resource Explorer . This is a crawly feature of this software in which you tin find every detail of a TI product like datasheets, documentations, etc. At that place is no need to discover datasheets on internet, just click on resource explorer and click on the device which you want to explore after that you tin can see every detail well-nigh the production.
Creating first Project in Code Composer Studio: Blink an LED:
Creating Project in CCS:
Step ane:- Click on File -> New -> CCS projection. As shown below
Step 2:- Adjacent, you accept to choose MSP lath that you lot are using. I am using MSP430G2553 so, I volition choose this every bit shown.
Requite name to your projection and click on finish.
Every bit soon as y'all click on cease, a new window will open up with some lines code already written into it.
Writing Lawmaking in CCS:
Permit's see the structure of the code that is already given. Start line is our header file which depends on the variant that we cull while creating the project. As I told I am using MSP430G2553, so I'll rename the header file to
#include<msp430g2553.h>
Side by side line is the chief part. In the main function you will see initialization of Watchdog timer. MSP430 and other TI based microcontroller has special type of timer which is known as Watchdog timer . Work of this timer is to rset the microcontroller when it starts to hanging or finish giving response. In our code, we volition not use Watchdog timer because it is above the beginner's perspective. When we ON the Microcontroller, watchdog timer is ON by default so nosotros accept to OFF this timer by writing this line
WDTCTL = WDTPW | WDTHOLD;
Now, we have to write code to blink onboard LED which is connected to P1.0. There is another LED continued to P1.6. We will use simply first LED. Y'all are able to write code for toggling these two LED's as well afterwards you understand the blink program.
Starting time, we have to declare these PINS equally we are using these equally INPUT or OUTPUT.
In that location are many blazon of Registers i.e. retentivity blocks used to control PORTS. So, for defining PORT as INPUT or OUTPUT, PXDIR (10 is port no.) (Information Direction Annals) register is used. If PXDIR is 1 it acts equally OUTPUT and 0 for INPUT. Our LED is at port no. 1 so we will write equally P1DIR .
Nosotros need to configure Pin 0, as our LED is connected to this Pin and it is OUTPUT. Each port has viii bits and we want Bit0 equally Loftier to make information technology OUTPUT. So, we assign P1DIR every bit
P1DIR = 0b00000001; information technology is in binary , we can also write information technology in Hexadecimal i.e. P1DIR = 0x01;
Next, we accept to prepare the particular pin of detail port as high or depression. For this purpose we have to useP1OUT annals, ane for high while 0 for low. Initially, I brand the LED ON by setting BIT0 equally 1 other remains cypher.
P1OUT=0b00000001; P1OUT = 0x01; //in hexadecimal
As at that place is no inbuilt function of delay in MSP430 and so, we accept to use for loop to provide filibuster.
So, in next step, we have to declare a variable'i'for filibuster purpose which tin be written as
Unsigned int i;
Offset, we volition make PIN0 Loftier and requite some delay using FOR loop later on that make the PIN Low. In this way, we get blinking effect. We write program similar this:
P1OUT=0X01; //make bit0 Loftier for(i=0;i<20000;i++){ // delay till you make LED HIGH } P1OUT=0X00; //make bit0 Low for(i=0;i<20000;i++){ // delay till you brand LED LOW } You can write this code in another way likewise. You can utilize BITWISE operator to reduce lines of code. There are OR, AND and XOR bitwise operators available. You tin can utilise XOR operator (^) . XOR functioning gives ane when both bits are equal like 1 and one, 0 and 0 .We write it similar this
P1OUT ^= 0x01;
which means P1OUT = P1OUT xor 0b00000001;
Then, initially we initialize P1OUT every bit 0b00000001, if we take xor operation with 0b00000001, output will be 0b00000000 ways our LED will exist OFF. Later this we put for loop for filibuster purpose.
while(ane) { P1OUT ^=0X01; //toggle the bits for(i=0;i<20000;i++){ // delay till you make LED Depression High } } Upload the code into MSP430:
Complete program for CCS is given at the end of the folio. Then our lawmaking is set up to burn in MSP430. Then, connect MSP with your laptop using USB cable.
Now, we take to compile/build our code, for this click on Project -> Build All. Check the study of compilation in the console box at the bottom of the window. It will show "Build Finished".
It's fourth dimension to upload the plan. Click on Run -> Debug . Afterward clicking on debug, y'all volition get a window related to power saving, just click on proceed. In debug option go to Run->Resume. If your options are blanked out, no need to worry, go to View->Debug and then again get to Run->Resume .
As soon as you debugged the code, your program is uploaded in the MSP. A shortcut mode is to merely click the play/pause like push button on the screen. The debug screen will await like, as given below
If LED is not blinking and so Reset the board or connect the USB again.
And so this is how you lot can write a simple plan in Code Composer Studio to blink a LED using MSP430.
Lawmaking
#include <msp430g2553.h> // header file that depends upon your board
/*
* master.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
P1DIR = 0X01; //Declare PIN0 OF PORT one AS OUTPUT
P1OUT = 0X01; //MAKE PIN0 HIGH INITIALLY
unsigned int i; //Delay variable
while(1)
{
P1OUT ^=0X01; ////toggle the bits
for(i=0;i<20000;i++){ // delay till yous make LED LOW HIGH
}
}
return 0;
}
How To Set Direction Register For Red, Green Blue Led On Msp430,
Source: https://circuitdigest.com/microcontroller-projects/getting-started-with-msp430-using-code-composer-studio/
Posted by: lawsoncaph1956.blogspot.com

0 Response to "How To Set Direction Register For Red, Green Blue Led On Msp430"
Post a Comment