Question

In: Electrical Engineering

write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...

write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language.

write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.

Solutions

Expert Solution

float maxTemp = 30.0; // switch on led when temp > maxTemp
int maxTempSensor = (int) ((maxTemp / 100 + .5) * 204.8);
float temperature = 0.0;

int maxSeconds = 10; // send status message every maxSeconds

const int ledPin = 13; // temperature led

const int tempPin = A0; // T36 temperature sensor analog input pin

const int led1Pin = 3; // Yellow
const int led2Pin = 4; // Green
const int led3Pin = 5; // Red

volatile int tempVal;
volatile int seconds = 0;
volatile boolean tempHigh = false;
volatile boolean statusReport = false;

String inputString = "";
String command = "";

String value = "";
boolean stringComplete = false;

The setup() function

void setup(){
//start serial connection
Serial.begin(9600);
Serial.print("Max T: ");
Serial.print(maxTemp);
Serial.print(" Sensor: ");
Serial.println(maxTempSensor);

inputString.reserve(50);
command.reserve(50);
value.reserve(50);

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);

pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);

cli(); // disable global interrupts

// initialize Timer1 for interrupt @ 1000 msec
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B

// set compare match register to desired timer count:
OCR1A = 15624; // turn on CTC mode:
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR1B |= (1 << CS10);
TCCR1B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);

sei(); // enable global interrupts

}

ISR(TIMER1_COMPA_vect)
{
tempVal = analogRead(tempPin);

if (tempVal > maxTempSensor) {
digitalWrite(ledPin, HIGH);
tempHigh = true;
}
else {
digitalWrite(ledPin, LOW);
tempHigh = false;
}

if (seconds++ >= maxSeconds) {
statusReport = true;
seconds = 0;
}
}

void loop(){
int intValue = 0;

if (stringComplete) {
Serial.println(inputString);
boolean stringOK = false;
if (inputString.startsWith("CMD ")) {
inputString = inputString.substring(4);

int pos = inputString.indexOf('=');
if (pos > -1) {
command = inputString.substring(0, pos);
value = inputString.substring(pos+1, inputString.length()-1); // extract command up to \n exluded


if (command.equals("RED")) { // RED=ON|OFF
value.equals("ON") ? digitalWrite(led3Pin, HIGH) : digitalWrite(led3Pin, LOW);
stringOK = true;
}
else if (command.equals("GREEN")) { // GREEN=ON|OFF
value.equals("ON") ? digitalWrite(led2Pin, HIGH) : digitalWrite(led2Pin, LOW);
stringOK = true;
}
else if (command.equals("YELLOW")) { // YELLOW=ON|OFF
value.equals("ON") ? digitalWrite(led1Pin, HIGH) : digitalWrite(led1Pin, LOW);
stringOK = true;
}


else if (command.equals("TMAX")) { // TMAX=value
intValue = value.toInt();
if (intValue > 0) {
maxTemp = (float) intValue;
maxTempSensor = (int) ((maxTemp / 100 + .5) * 204.8);
stringOK = true;
}
}
else if (command.equals("SECONDS")) { // SECONDS=value
intValue = value.toInt();
if (intValue > 0) {
maxSeconds = intValue;
stringOK = true;
}
}

} // pos > -1
else if (inputString.startsWith("STATUS")) {
Serial.print("STATUS RED=");
Serial.println(digitalRead(led3Pin));
Serial.print("STATUS GREEN=");
Serial.println(digitalRead(led2Pin));
Serial.print("STATUS YELLOW=");
Serial.println(digitalRead(led1Pin));
Serial.print("STATUS TMAX=");
Serial.println(maxTemp);
Serial.print("STATUS SECONDS=");
Serial.println(maxSeconds);
Serial.print("STATUS TEMP=");
Serial.println(temperature);
Serial.print("STATUS THIGH=");
Serial.println(tempHigh);
stringOK = true;
} // inputString.startsWith("STATUS")

} // inputString.startsWith("CMD ")
stringOK ? Serial.println("Command Executed") : Serial.println("Invalid Command");// clear the string for next iteration
inputString = "";
stringComplete = false;
} // stringComplete

if (statusReport) {
temperature = (tempVal * 0.0048828125 - .5) * 100;
Serial.print("STATUS TEMP=");
Serial.println(temperature);
Serial.print("STATUS THIGH=");
Serial.println(tempHigh);
statusReport = false;
}

}

void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline or a carriage return, set a flag
// so the main loop can do something about it:
if (inChar == '\n' || inChar == '\r') {
stringComplete = true;
}
}
}


Related Solutions

using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever...
using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
Write an assembly language program code to clear and set bit 7th and 19th in a...
Write an assembly language program code to clear and set bit 7th and 19th in a 32-bit variable called N.
Please use assembly language x86 Visual Studio Write a program to add the following word size...
Please use assembly language x86 Visual Studio Write a program to add the following word size numbers:15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
Need to code this is assembly language. Using the windows32 framework, write a procedure to read...
Need to code this is assembly language. Using the windows32 framework, write a procedure to read a string and shift each character of the string by one. As an example, if your input string is Abcz, your output should be Bcda. Note that you must test your string for non-alphabetic characters (such as numbers and special characters). If there are non-alphabetic characters, you should terminate your program with an appropriate message. You should display your converted string using the output...
Using x86 assembly language, create a flowchart and write an example of code that will sort...
Using x86 assembly language, create a flowchart and write an example of code that will sort 2 arrays of unsigned doubleword integers in ascending order and output the largest element in each array. Any sorting procedure can be used, but this procedure must be called twice for each array. The first time it is called, the first array should be sorted and the second time it is called, the second array must be sorted. As well as outputting which is...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE...
Q1: A. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO EXCHANGE 16-BIT NUMBERS B. WRITE AN ASSEMBLY LANGUAGE PROGRAM TO SOLVE THE EQUATION Z=A+B-(C/D)+E please write the answer separately part A its own code and part B its own code this is microprocessor the ASSEMBLY LANGUAGE emu8086 should be written like this EX: mov ax,100h mov bx,200h etc
Code using assembly language Create a program using the Irvine32 procedures were the user can input...
Code using assembly language Create a program using the Irvine32 procedures were the user can input a list of 32-bit unsigned integers an “x” number of times, then display these integers to the console in reverse order. Hint: Use loops and PUSH & POP instructions. Extra Challenge: Inform the user with a message what to do; also, tell them what they are seeing.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT