nothing9099
Newbie level 4
I'm using an MSP430 MC and I've got a basic task to perform. I've not been coding for long so I'm unsure.
i have to fill in the code so that it will output 27 degrees C. Do I just simply do
Code:
#define STATUS_PASS (1)
#define STATUS_FAIL (0)
#define USB_STRING_LEN (15)
#define V_ones (9) // USB_string[9] = ones of V
#define V_tenths (11) // USB_string[11] = tenths of V
#define C_tens (0) // USB_string[0] = tens of deg C
#define C_ones (1) // USB_string[1] = ones of deg C
#define F_hundreds (4) // USB_string[4] = hundreds of deg F
#define F_tens (5) // USB_string[5] = tens of deg F
#define F_ones (6) // USB_string[6] = ones of deg F
unsigned char format_temperature_string(unsigned int degrees, unsigned char c_or_f)
{
unsigned char hundreds = '0'; // Init to '0' to code in ASCII
unsigned char tens = '0';
unsigned char ones = '0';
unsigned char status = STATUS_PASS;
// Calculate the hundreds, tens and ones places...
while (degrees >= 100){
hundreds++;
degrees-=100;
}
while (degrees >= 10){
tens++;
degrees-=10;
}
ones+=degrees;
switch(c_or_f)
{
case 'c':
case 'C':
// FILL IN CODE THAT GOES HERE
break;
case 'f':
case 'F':
// FILL IN CODE THAT GOES HERE
break;
default:
status = STATUS_FAIL; // Invalid parameter
break;
}
return status;
}
i have to fill in the code so that it will output 27 degrees C. Do I just simply do
Code:
unsigned char format_temperature_string(unsigned int degrees, unsigned char c_or_f)
{
unsigned char hundreds = '0'; // Init to '0' to code in ASCII
unsigned char tens = '0';
unsigned char ones = '0';
unsigned char status = STATUS_PASS;
// Calculate the hundreds, tens and ones places...
while (degrees >= 100){
hundreds++;
degrees-=100;
}
while (degrees >= 10){
tens++;
degrees-=10;
}
ones+=degrees;
switch(c_or_f)
{
case 'c':
case 'C':
// FILL IN CODE THAT GOES HERE
USB_string[0] = ’2’;
USB_string[1] = ’7’;
break;
case 'f':
case 'F':
// FILL IN CODE THAT GOES HERE
break;
default:
status = STATUS_FAIL; // Invalid parameter
break;
}
return status;
}