void printStr(char *str) { if (str == NULL) return; //Print each character until null character is seen while (*str != '\0') { OUTA_UART(*str); //print character to Terminal str++; //move to next character } OUTA_UART(0x0A); //Print carriage return to Terminal OUTA_UART(0x0D); //Print Newline to Terminal }
int main(void){ volatile unsigned char a[100]="Laboratory #2 for EEL4742 Embedded Systems0";//string to print volatile unsigned char b; volatile unsigned int i=0; // index of string WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer Init_UART(); while(i>=0){//loop until entire string is printed b=a[i];//temp variable to hold character if(a[i]=='0'){//if null character is found, break loop break;//break statement } OUTA_UART(b);//display character in hyperterminal i++;//increment index } // go blink the light to indicate code is running P2DIR |= 0x02; // Set P1.0 to output direction // Use The LED as an indicator for (;;){ P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR i = 10000; // SW Delay do i--; while (i != 0); } }
void toggleLED(){ char a; a = INCHAR_UART(); //Receive from user OUTA_UART(a); //Echo character to the hyper terminal if ( a == 'G') //If user enters G then toggle the green LED P2OUT ^= 0x04; else if ( a == 'Y') //If user enters Y then toggle the yellow LED P2OUT ^= 0x02; else ;//Stay the same }
int main(void){ volatile unsigned char a; volatile unsigned int i=1; // volatile to prevent optimization WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer //initalized UART communication with MSP430 to hyperterminal Init_UART(); while(i!=0){ a=INCHAR_UART();//function that reads character from keyboard if(a=='0x00'){//if character enter is null, break loop break; } OUTA_UART(a);//display character in hyperterminal } // go blink the light to indicate code is running P2DIR |= 0x02; // Set P1.0 to output direction // Use The LED as an indicator for (;;){ P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR i = 10000; // SW Delay do i--; while (i != 0); } }
int main(void){ volatile unsigned char d; volatile unsigned int i, j[20], x[5], temp[3]; // volatile to prevent optimization volatile unsigned int a, b, c, e; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2DIR |= 0x02; // Set P1.0 to output direction Init_UART(); Init_LCD(); j[0] = 0x5F; j[1] = 0X06; j[2] = 0X6B; j[3] = 0X2F; j[4] = 0X36; j[5] = 0X3D; j[6] = 0X7D; j[7] = 0X07; j[8] = 0X7F; j[9] = 0X37; j[10] = 0X77; j[11] = 0X7C; j[12] = 0X68; j[13] = 0X6E; j[14] = 0X79; j[15] = 0X71; for (;;){ //letter input 1 a=INCHAR_UART(); OUTA_UART(a); //Check if it's a digit or a character and transform to binary if((a>=0x30) && (a<=0x39)){ a = a-0x30; } else{ a = a-0x37; } //letter input 2 b=INCHAR_UART(); OUTA_UART(b); //Check if it's a digit or a character and transform to binary if((b>=0x30) && (b<=0x39)){ b = b-0x30; } else{ b = b-0x37; } //Multiply a by 16 because of Hex, add together to obtain final number temp[1] = (a*16)+(b); d=INCHAR_UART(); OUTA_UART(d); //letter input 3 a=INCHAR_UART(); OUTA_UART(a); //letter input 4 b=INCHAR_UART(); OUTA_UART(b); OUTA_UART(0x3D); //Repeat procedure for the next two characters if((a>=0x30) && (a<=0x39)){ a = a-0x30; } else{ a = a-0x37; } if((b>=0x30) && (b<=0x39)){ b = b-0x30; } else{ b = b-0x37; } //Multiply a by 16 because of Hex, add together to obtain final number temp[2] = (a*16)+(b); //If both numbers are equal if(temp[1]==temp[2]){ e = 0; LCDSeg[2]=0x00; } //If the first number is bigger simply subtract else if(temp[1]>temp[2]){ e = temp[1]-temp[2]; LCDSeg[2]=0x00; //reset LCD } //If second number is bigger, invert numbers and add (-) before answer else{ e=temp[2]-temp[1]; OUTA_UART(0X2D); LCDSeg[2]=0x20; } //The next three steps will yield the digits we'll print onto the LCD if((e/16)>15){ x[3] =1; x[2]=(e/16)-16; } else{ x[3]=0; x[2]=e/16; } x[1]= e%16; //Print on LCD LCDSeg[1] = j[x[2]]; LCDSeg[0] = j[x[1]]; //Convert our decimal characters back to ascii if(x[3]<=9) x[3]=x[3] + 0x30; else x[3]=x[3] + 0x37; if(x[2]<=9) x[2]=x[2] + 0x30; else x[2]=x[2] + 0x37; if(x[1]<=9) x[1]=x[1] + 0x30; else x[1]=x[1] + 0x37; //print the characters onto the Hyperterminal OUTA_UART(x[2]); OUTA_UART(x[1]); //Print New line OUTA_UART(0X0A); OUTA_UART(0X0D); } }
int main(void){ volatile unsigned char d; volatile unsigned int i, j[20], x[5], temp[3]; // volatile to prevent optimization volatile unsigned int a, b, c, e; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2DIR |= 0x02; // Set P1.0 to output direction Init_UART(); Init_LCD(); j[0] = 0x5F; j[1] = 0X06; j[2] = 0X6B; j[3] = 0X2F; j[4] = 0X36; j[5] = 0X3D; j[6] = 0X7D; j[7] = 0X07; j[8] = 0X7F; j[9] = 0X37; j[10] = 0X77; j[11] = 0X7C; j[12] = 0X68; j[13] = 0X6E; j[14] = 0X79; j[15] = 0X71; for (;;){ //letter input 1 a=INCHAR_UART(); OUTA_UART(a); //Check if it's a digit or a character and transform to binary if((a>=0x30) && (a<=0x39)){ a = a-0x30; } else{ a = a-0x37; } //letter input 2 b=INCHAR_UART(); OUTA_UART(b); //Check if it's a digit or a character and transform to binary if((b>=0x30) && (b<=0x39)){ b = b-0x30; } else{ b = b-0x37; } //Multiply a by 16 because of Hex, add together to obtain final number temp[1] = (a*16)+(b); d=INCHAR_UART(); OUTA_UART(d); //letter input 3 a=INCHAR_UART(); OUTA_UART(a); //letter input 4 b=INCHAR_UART(); OUTA_UART(b); OUTA_UART(0x3D); //Repeat procedure for the next two characters if((a>=0x30) && (a<=0x39)){ a = a-0x30; } else{ a = a-0x37; } if((b>=0x30) && (b<=0x39)){ b = b-0x30; } else{ b = b-0x37; } //Multiply a by 16 because of Hex, add together to obtain final number temp[2] = (a*16)+(b); //Multiply e = temp[1]*temp[2]; //The next few steps will be used to display our output x[4] = e/4096; temp[0]=e%4096; x[3]=temp[0]/256; temp[0]=temp[0]%256; x[2]=temp[0]/16; temp[0]=temp[0]%16; x[1]= temp[0]; //Print on LCD LCDSeg[3] = j[x[4]]; LCDSeg[2] = j[x[3]]; LCDSeg[1] = j[x[2]]; LCDSeg[0] = j[x[1]]; //Convert our decimal characters back to ascii if(x[4]<=9) x[4]=x[4] + 0x30; else x[4]=x[4] + 0x37; if(x[3]<=9) x[3]=x[3] + 0x30; else x[3]=x[3] + 0x37; if(x[2]<=9) x[2]=x[2] + 0x30; else x[2]=x[2] + 0x37; if(x[1]<=9) x[1]=x[1] + 0x30; else x[1]=x[1] + 0x37; //print the characters onto the Hyperterminal OUTA_UART(x[4]); OUTA_UART(x[3]); OUTA_UART(x[2]); OUTA_UART(x[1]); //Print New line OUTA_UART(0X0A); OUTA_UART(0X0D); } }
int main(void){ volatile unsigned char a, b; volatile unsigned int i, j[20], x; // volatile to prevent optimization WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2DIR |= 0x02; // Set P1.0 to output direction Init_UART(); Init_LCD(); j[0] = 0x5F; j[1] = 0X06; j[2] = 0X6B; j[3] = 0X2F; j[4] = 0X36; j[5] = 0X3D; j[6] = 0X7D; j[7] = 0X07; j[8] = 0X7F; j[9] = 0X37; j[10] = 0X77; j[11] = 0X7C; j[12] = 0X68; j[13] = 0X6E; j[14] = 0X79; j[15] = 0X71; //Run indefinitely for (;;){ //letter input 1 a=INCHAR_UART(); OUTA_UART(a); //Check if input is digit or character and print //onto the board's LCD screen if(isdigit(a)){ a = a - 0x30; LCDSeg[1]=j[a]; } else{ a = a - 0x37; LCDSeg[1]= j[a]; } //letter input 2 b=INCHAR_UART(); OUTA_UART(b); //Repeat procedure followed for input a if(isdigit(b)){ b = b - 0x30; LCDSeg[0]=j[b]; } else{ b = b - 0x37; LCDSeg[0]= j[b]; } Print New line OUTA_UART(0X0A); OUTA_UART(0X0D); P2OUT ^= 0x02; // Toggle P1.0 using exclusive-OR i = 10000; // SW Delay do i--; while (i != 0); } }