Calculator with using MSP430G2553 and UB232R module .


Calculator with using MSP430G2553 and UB232R 
           







Purpose :
Creating Basic calculator(*,/,-,+) by using MSP430 . This will be done by processing the numbers entered from the computer into MSP and printing the result on the computer screen.

Used:
1 unit MSP430G2553
1 unit UB232R (uart modülü)
4  jumper cables
computer program called Putty (You can connect your computer with Putty via terminal via various commands )

CIRCUIT DIAGRAM

















In order to run the program, first you have to send the codes to MSP430, so plug the USB cable into MSP430 and embed the codes with the IAR program. Then remove the usb cable from msp and plug it into the UART module(UB232R).
Right click on the computer icon and press Manage. In the "Device Manager" section on the left you can find the Port number of the USB connected to the UART module in the PORTS. After you open the Putty program, come to "Serial" and type in the port name you see in Device Manager instead of COMxx in "Serial Line". Set the speed and turn it on (9600 baud is used in this program) When the black screen comes up , you can type anything .This signals send from computer into uart module than into MSP . MSP can catch the signals with 'UCA0RXBUF ' command, Every process sent by MSP (with UCA0TXBUF command) is also printed on the computer's black screen. The communication between the computer and the MSP is done according to the ASCII table. That is, each number and sign in the table equals "hexadecimal", "decimal", and 9-bit different numbers.
















//Enter the first number> 34
// Enter the operation mark > * 
// Enter the second number>12
//408


The codes you will find below are in trial mode.And they are half turkish. Please contact me if there is any error in the code or if you have a way to make it more effective.Sorry for my bad english. Have a nice day! Mail: g.haddeler@gmail.com

// UB232R uart module 1.pini msp is connected to the ground. The / 2. 7th and 8th pins are connected to pins 1.1 and 1.2 of MSPN.

Calculator Codes for Embedding into MSP430 

#include "msp430g2553.h"
//UB232R Uart module  1st pin is connected to the ground. 
//2nd pin is connected to MSP's pin which is  Vcc   .  
//7th and 8th pins are connected to MSP's pins which are 1.1 and 1.2 .

void UARTyolla( char *A, unsigned char uzunluk); // a funciton to print into screen.
 unsigned char data[];
int i=0;
char cevap;
char yazi[];
char deger=0 ;
char deger1=0 ;
 unsigned char data1[];
 unsigned  char data2[];
  unsigned char data3[];
  unsigned char data4[];
void main(void)
{
 WDTCTL = WDTPW + WDTHOLD; //
BCSCTL1 = CALBC1_1MHZ; // Set 1MHz 
 DCOCTL = CALDCO_1MHZ; // Set  1MHz 
 //UART SETTINGS
 P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
 P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
 UCA0CTL1 |= UCSSEL_2;  // We used SMCLK 
 UCA0BR0 = 104; // Baud rate is 9600 for1MHz (Data Sheet 15.3.13)
 UCA0BR1 = 0; // // Baud rate is 9600 for1MHz
 UCA0MCTL = UCBRS0; //  This UCBRSx equal to 1 
 UCA0CTL1 &= ~UCSWRST; // reversing USCI 
 IE2 |= UCA0RXIE; // Activating RX interrupt 
__bis_SR_register( GIE);

}
#pragma vector=USCIAB0RX_VECTOR // opening receiver interrupt
__interrupt void USCI0RX_ISR(void)
{     
  UARTyolla("ilk sayiyi girdiniz",20); // enter the first number
   while (!(IFG2&UCA0RXIFG));  // wait for entering the number
 
       data1[0]=UCA0RXBUF;// We send the first number's tens digit
       __delay_cycles(100);
       UARTyolla(data1,1);//  We send  the number which we enter on screen //after comma (data1,1) length of an array
          while (!(IFG2&UCA0RXIFG)); 
       data3[0]=UCA0RXBUF;// We send the first number's unit digit into MSP 
     __delay_cycles(100);
      UARTyolla(data3,1);
    UARTyolla("\n\r",2);
   UARTyolla("islem isaretini girdiniz",25); // enter the operation mark +,*,-,/
    while (!(IFG2&UCA0RXIFG)); 
    
       data[0]=UCA0RXBUF;
    
      UARTyolla(data,1);
    UARTyolla("\n\r",2);
   
   UARTyolla("ikinci sayiyi girdiniz",23); // enter the second number
   while (!(IFG2&UCA0RXIFG)); 
       data2[0]=UCA0RXBUF;
      
       __delay_cycles(100);
       UARTyolla(data2,1);
  
       while (!(IFG2&UCA0RXIFG)); 
       data4[0]=UCA0RXBUF;
       __delay_cycles(100);
      UARTyolla(data4,1);
    UARTyolla("\n\r",2);
  
switch(data[0]){ // assign function to process operation mark .
 case '+':
 {    int x; 

   deger = (data1[0]-48)*10+(data3[0]-48); // translate the hexadecimal data into known decimal //digits
   deger1 =(data2[0]-48)*10+(data4[0]-48);
   x= deger + deger1; 
      __delay_cycles(1000);
yazi[0] = x/100+48;// assign hundreds digit into first elements of array 
yazi[1]=x/10+48;//assign tens digit into second elements of array 
yazi[2]= x%10+48;//assign units digit into third elements of array 
  UARTyolla(yazi,3);
   UARTyolla("\n\r",2);
}  
 break;
 case '-':
 { char x;
 int z;
   deger = (data1[0]-48)*10+(data3[0]-48);
   deger1 =(data2[0]-48)*10+(data4[0]-48);
   z= deger - deger1;
   __delay_cycles(1000);
     if(z<0)  // if answer is negative 
     { x=(-z);
       yazi[0] = 45;
        yazi[1]=x/10+48;
        yazi[2]= x%10+48;    
     }  
  else
  {
yazi[0] = z/100+48;
yazi[1]=z/10+48;
yazi[2]= z%10+48;
  }
  UARTyolla(yazi,3); 
   UARTyolla("\n\r",2);
 }
 break;
 case '*':
        deger = (data1[0]-48)*10+(data3[0]-48);
   deger1 =(data2[0]-48)*10+(data4[0]-48);
   z= deger * deger1;
      __delay_cycles(1000);
 // yazi[0]= data3[0]+40;
yazi[0] = z/100+48;
yazi[1]=  (z%100)/10 +48;
yazi[2]= z%10+48;
  UARTyolla(yazi,3);
  
   UARTyolla("\n\r",2);
 
 }
 break;
 case '/':

    { float x ;
  int a ;
  int b ;
  int  c ;
  int y;
    deger = (data1[0]-48)*10+(data3[0]-48);
   deger1 =(data2[0]-48)*10+(data4[0]-48);
   x= (float)deger /deger1;//for the value appering in comma 
      __delay_cycles(1000);
     y =x*100;
  a= y%1000;
      b=y%100;
      c=y%10;
 yazi[0]= y/1000+48;
       yazi[1]= a/100+48;
       yazi[2]= 46;
       yazi[3]= b/10+48;
        yazi[4]= c+48;
      
        UARTyolla(yazi,5);        
   UARTyolla("\n\r",2);
 }
 break;
 default:
 {
  UARTyolla("UNKNOWN COMMAND",15);
  UARTyolla("\n\r",2);
 }
 break;
 }    }
void UARTyolla( char *A, unsigned char uzunluk){ 
  while(uzunluk--)
  {
    while (!(IFG2&UCA0TXIFG)); 
    UCA0TXBUF = (*A); // While the length  is become zero,  the char values of A is writing into //screen . (according to the ascii table )

    A++;
  }}



Yorumlar

Bu blogdaki popüler yayınlar

Girilen kelimeyi hecelerine ayıran program.(C++ Uygulamaları) Favori Uygulama :)

Girilen küçük harfi büyük harfe çeviren program (C++ uygulamaları )

Girilen kelimedeki büyük harf sayısını bulan program(C++ uygulamaları )