-
Home
- Intro to computational engineering
- Intro to computational engineering
- Lab 3-2 digital input and output
This module goes over the basics of digital I/O and the digital interface between a microcontroller and the outside world.
Basic digital i/o in the real world
In this lab you'll go over the basics of how to setup and use the GPIO on the MSP430. This will allow you to get data from the outside world, run some processing on it, and then output it again as useful information. You only have one task this week:
- Coding in MSP430 assembly,
write a simple I/O echo program . Setup the GPIO pins and poll the input switches for any changes. On a change, take the input and display it to the output. Step through this program to observe how it behaves.
Assignment Details
Digital i/o basics
Gpio
Philosophy
- The MSP430 uses a limited number of GPIO hardware pins that are assignable to several functions depending on your specific model and your program's needs. Our version, the MSP430G2231, can have the Port_1 pins act as digital output, digital input, or ADC input.
- The pins are organized into ports, with each port usually one byte (8 bits/pins) wide. On larger versions of the processor (different format chips with physically many more pins...) you can encounter several ports, but in this lab you will only be using Port_1 and Port_2
- You can set each pin's function independently (input or output) by modifying some memory mapped I/O registers. Since we want to do both, we will divide P1 into half inputs and half outputs as needed.
Usage
- The I/O ports are memory mapped into the top of the MSP430 address space.
- There are several registers associated with each port. For now, you only need to worry about four (P1IN, P1OUT, P1DIR, and P1REN).
P1in
- The P1IN register is located at address
0x0020
in memory, which you can also refer to using the C symbol
&P1IN
- The register holds the values the MSP430 sees at each pin, regardless of the pin direction setting.
- To read the register, it is good practice to use a
mov.b
instruction to avoid accidentally reading adjacent registers
-
If you are looking to test or read just the pins set to input, you will have to mask the P1IN register to zero out the other unwanted/output pins. Reading P1IN reads the entire port, regardless of pin direction.
P1out
- The P1OUT register is located at address
0x0021
in memory, which you can also refer to using the C symbol
&P1OUT
- If their direction bits in P1DIR are set to output/ "1", the corresponding pins will output the values set in P1OUT.
- If a pin's direction bits are set to input in P1DIR and its resistors are enabled in P1REN, P1OUT controls the pin's connection to the pull-up resistor. Setting P1OUT to "1" enables the pull-up, while setting it to "0" leaves the input to float in a high impedance state.
- To set P1OUT, use a
mov.b
instruction to set several pins at once. To set individual bits to "1", you can use an
or.b
instruction with a "1" in the positions you want to set. To clear individual bits/ set them to zero, use an
and.b
instruction with mostly "1"s except for a "0" for the bits you want to clear.
P1dir
- The P1DIR register is located at address
0x0022
in memory, which you can also refer to using the C symbol
&P1DIR
- The value of the bits in P1DIR determines whether the MSP430 hardware leaves the pin in a high impedance state where it responds to external voltage changes (which you can read at P1IN), or in a low impedance state where the MSP430 drives the output voltage to a certain value determined by P1OUT.
- To set the bit directions all at once, use a
mov.b
instruction, but to change individual bits regardless of the others, use an
and.b
or a
or.b
-
Set the corresponding bits to "0" to set pins to input mode, or to "1" to set them to output mode.
P1ren
- The P1REN register is located at address
0x0027
in memory, which you can also refer to using the C symbol
&P1REN
- P1REN controls whether the MSP430 Launchpad enables the integrated pull-up resistor for a given pin.
- The pull-up resistors allow the use of single pole switches. They prevent the input signals from floating randomly while the switches are open by loosely tying the inputs to Vcc. When the switch is closed though, the much stronger connection to ground wins out, pulling the inputs down to GND.
-
Set the corresponding bits to "1" to enable a pin's pull-up resistor, or to "0" to disable it (disabled by default).
Questions & Answers
differentiate between demand and supply
giving examples
differentiated between demand and supply using examples
Lambiv
how is the graph works?I don't fully understand
hi guys good evening to all
Lambiv
In economics, a perfect market refers to a theoretical construct where all participants have perfect information, goods are homogenous, there are no barriers to entry or exit, and prices are determined solely by supply and demand. It's an idealized model used for analysis,
Ezea
other things being equal
AI-Robot
When MP₁ becomes negative, TP start to decline.
Extuples Suppose that the short-run production function of certain cut-flower firm is given by: Q=4KL-0.6K2 - 0.112 •
Where is quantity of cut flower produced, I is labour input and K is fixed capital input (K-5). Determine the average product of lab
Kelo
Extuples Suppose that the short-run production function of certain cut-flower firm is given by: Q=4KL-0.6K2 - 0.112 •
Where is quantity of cut flower produced, I is labour input and K is fixed capital input (K-5). Determine the average product of labour (APL) and marginal product of labour (MPL)
Kelo
Can I ask you other question?
Shukri
What is different between quantity demand and demand?
Quantity demanded refers to the specific amount of a good or service that consumers are willing and able to purchase at a give price and within a specific time period. Demand, on the other hand, is a broader concept that encompasses the entire relationship between price and quantity demanded
Ezea
how do you save a country economic situation when it's falling apart
what is the difference between economic growth and development
Economic growth as an increase in the production and consumption of goods and services within an economy.but
Economic development as a broader concept that encompasses not only economic growth but also social & human well being.
Shukri
production function means
Jabir
What do you think is more important to focus on when considering inequality ?
any question about economics?
sir...I just want to ask one question... Define the term contract curve? if you are free please help me to find this answer 🙏
Asui
it is a curve that we get after connecting the pareto optimal combinations of two consumers after their mutually beneficial trade offs
Awais
thank you so much 👍 sir
Asui
In economics, the contract curve refers to the set of points in an Edgeworth box diagram where both parties involved in a trade cannot be made better off without making one of them worse off. It represents the Pareto efficient allocations of goods between two individuals or entities, where neither p
Cornelius
In economics, the contract curve refers to the set of points in an Edgeworth box diagram where both parties involved in a trade cannot be made better off without making one of them worse off. It represents the Pareto efficient allocations of goods between two individuals or entities,
Cornelius
Suppose a consumer consuming two commodities X and Y has
The following utility function u=X0.4 Y0.6. If the price of the X and Y are 2 and 3 respectively and income Constraint is birr 50.
A,Calculate quantities of x and y which maximize utility.
B,Calculate value of Lagrange multiplier.
C,Calculate quantities of X and Y consumed with a given price.
D,alculate optimum level of output .
the market for lemon has 10 potential consumers, each having an individual demand curve p=101-10Qi, where p is price in dollar's per cup and Qi is the number of cups demanded per week by the i th consumer.Find the market demand curve using algebra. Draw an individual demand curve and the market dema
suppose the production function is given by ( L, K)=L¼K¾.assuming capital is fixed find APL and MPL. consider the following short run production function:Q=6L²-0.4L³ a) find the value of L that maximizes output b)find the value of L that maximizes marginal product
Abdureman
What is the difference between perfect competition and monopolistic competition?
Mohammed
Got questions? Join the online conversation and get instant answers!
Source:
OpenStax, Intro to computational engineering: elec 220 labs. OpenStax CNX. Mar 11, 2013 Download for free at http://cnx.org/content/col11405/1.2
Google Play and the Google Play logo are trademarks of Google Inc.