Upload
le-nguyen
View
219
Download
0
Embed Size (px)
Citation preview
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
1/44
Da Nang University of Science and Technology
DaNang University of Science and TechnologyAdvanced Program in Digital Systems
Ho Viet Viet, Pham Xuan Trung, Nguyen The Nghia
EE472 LAB 5 REPORTHexadecimal Calculator using MSP-EXP430FG4618/2013
Experimenter Board
March 3, 2014
10ECE Group 03:
L Quang Ha Trng Hong Lnh V Quang Tuyn
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
2/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
OBJECTIVES:
To develop a C language and an assembly language program that adds, subtracts and multiplies
two hexadecimal digits. The resulting answer is then displayed on the LCD display of the
MSP430FG4618 experimenter board.
PROCEDURE:Part 1. Generating Basic input with C language programs
1. Write a C language program that input from the keyboard two hexadecimal numbers via
hyperterminal. Next these two numbers are to be displayed in the hyperterminal window and
on the right most two digits of the LCD display on the experimenter board. To convert an
ASCII 0- 9 to a four bit number, 0x30 is subtracted from the ASCII number. To convert the
ASCII capital letters A-F to a four bit number, 0x37 is subtracted from these capital letters.
To help write this program, please use as reference the C language programs written for labs
#3 and #4.
Source code
2. Write a C language program that inputs two ASCII hexadecimal digits followed by the +
symbol to indicate addition. Next, the user enters a second set of two hexadecimal digits that
are to be added to the first two hexadecimal digits. The addition result is shown on both the
hyperterminal display as well as the LCD display. Three digits are required for this resulting
addition. For example, what should be displayed is:
FF + 02 = 101 (0xFF + 0x01 = 0x101)
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
3/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
This program should run indefinitely and start on a new line each time waiting for user input.
Source Code
3. Write a C language program that inputs two ASCII hexadecimal digits followed by the
symbol to indicate subtraction. Next, the user enters a second set of two hexadecimal digits
that are to be subtracted from the first two hexadecimal digits. The subtraction result is shownon both the hyperterminal display as well as the LCD display. Care must be taken when the
second hexadecimal number is greater than the first so the proper sign is given. The best way
to perform the subtraction is to subtract the smaller of the two numbers from the larger of
the two numbers and display a negative sign if the second number is larger than the first
number. For example, what should be displayed is:
01 FF = FE (0x01 0xFF = 0xFE)
This program should run indefinitely and start on a new line each time waiting for user input.
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
4/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Source Code
4. Write a C language program that inputs two ASCII hexadecimal digits followed by the *
symbol to indicate multiplication. Next, the user enters a second set of two hexadecimal digits
that are to be multiplied with the first two hexadecimal digits. The multiplication result is
shown on both the Hyperterminal display as well as the LCD display. Multiplication of two
eight bit hexadecimal numbers can produce a result as large as sixteen bits. As such four
hexadecimal digits should be used to display the result. For example what should be
displayed is:
4E * A1 = 310E (0x4E * 0xA1 = 0x310E)
Source Code
5. Write a program that merges steps 2, 3, and 4 together and uses the ASCII symbols +, -,
and * to determine which arithmetic operation to perform. This program should run
indefinitely and start on a new line each time waiting for user input.
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
5/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Source Code
Part 2. Generating Basic input with assembly language programs.
The demonstrate are the same in Part I
1. Write an assembly language program that inputs from the keyboard two hexadecimal
numbers via hyperterminal. Next, these two numbers are displayed in the hyperterminal
window and on the right most two digits of the LCD display on the experimenter board. Toconvert an ASCII 0- 9 to a four bit number, 0x30 is subtracted from the ASCII number. To
convert the ASCII capital letters A-F to a four bit number, 0x37 is subtracted from these
capital letters. To help write this program, please use as reference the assembly language
programs written for laboratory experiments #3 and #4.
Source code
2. Write an assembly language program that inputs two ASCII hexadecimal digits followed by
the + symbol to indicate addition. Next, the user enters a second set of two hexadecimaldigits that are to be added to the first two hexadecimal digits. The addition result is shown on
both the hyperterminal display as well as the LCD display. Three digits are required for this
resulting addition. For example, what should be displayed is:
FF + 01 = 100 (0xFF + 0x01 = 0x100)
This program should run indefinitely and start on a new line each time waiting for user input.
Source code
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
6/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
3. Write an assembly language program that inputs two ASCII hexadecimal digits followed by
the - symbol to indicate subtraction. Next, the user enters a second set of two hexadecimal
digits that are to be subtracted from the first two hexadecimal digits. The subtraction result is
shown on both the hyperterminal display as well as the LCD display. Care must be taken when
the second hexadecimal number is greater than the first so the proper sign is given. The best
way to perform the subtraction is to subtract the smaller of the two numbers from the largerof the two numbers and display a negative sign if the second number is larger than the first
number. For example, what should be displayed is:
01 FE = FD (0x01 0xFF = 0xFD)
This program should run indefinitely and start on a new line each time waiting for user input.
Source code
4. Write an assembly language program that inputs two ASCII hexadecimal digits followed by
the * symbol to indicate multiplication. Next, the user enters a second set of twohexadecimal digits that are to be multiplied with the first two hexadecimal digits. The
multiplication result is shown on both the hyperterminal display as well as the LCD display.
The MSP430 does not have an assembly language multiplication instruction. For this project,
the program needs to implement the shift and add multiplication
algorithm.For example, what should be displayed is:
4E * A1 = 310E (0x4E * 0xA1 = 0x310E)
Finally, this program should run indefinitely and start on a new line each time waiting for user
input.
Source code
5. Write a program that merges steps 2, 3, and 4 together and uses the ASCII symbols +, -,
and * to determine which arithmetic operation to perform. This program should run
indefinitely and start on a new line each time waiting for user input.
Source code
SOURCE CODE:
Part IC language programs
Procedure 1:
//---------------------------------------------------------------// Console I/O through the on board UART for MSP 430X4XXX//---------------------------------------------------------------#include"msp430fg4618.h"#include"stdio.h"#include"string.h"
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
7/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
voidInit_UART(void);voidOUTA_UART(unsignedcharA);voidOUTA_UART_ENTER();unsignedcharINCHAR_UART(void);voidprintString(char*myString);
voidInit_LCD(void);unsignedchar*LCDSeg = (unsignedchar*) &LCDM3;intLCD_SIZE=11;
intmain(void){volatileunsignedchara;volatileunsignedinti; // volatile to prevent optimizationvolatileunsignedcharj;// LCD digit EncodingunsignedcharLCDdigit[] =
{0x5F,0x06,0x6B,0x2F,0x36,0x3D,0x7D,0x07,0x7F,0x3F,0x77,0x7C,0x68,0x6E,0x79,0x71};
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerInit_UART();Init_LCD();
//Finish SET-UP
for(;;){
a = INCHAR_UART();OUTA_UART(a);
// First Hex Displayi = a;if(i>=0x30 && i =0x41 && i =0x61 && i = 0x30 && j =0x41 && j =0x61 && j
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
8/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
}while((IFG2 & 0x02)==0);// send the data to the transmit bufferUCA0TXBUF =A;}
unsignedcharINCHAR_UART(void){
do{}while((IFG2 & 0x01)==0);
// go get the char from the receive bufferreturn(UCA0RXBUF);}
voidInit_UART(void){P2SEL=0x30;UCA0CTL0=0;UCA0CTL1= 0x41;UCA0BR1=0;UCA0BR0=3;UCA0MCTL=0x06;UCA0STAT=0;UCA0CTL1=0x40;
IE2=0;}voidInit_LCD(void){
intn;for(n=0;n
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
9/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
volatileunsignedchara;volatileunsignedinti; // volatile to prevent optimizationvolatileunsignedcharj;volatileunsignedintsum;
unsignedcharLCDdigit[] ={0x5F,0x06,0x6B,0x2F,0x36,0x3D,0x7D,0x07,0x7F,0x3F,0x77,0x7C,0x68,0x6E,0x79,0x71};
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
Init_UART();Init_LCD();//Finish SET-UP
for(;;){sum = 0; // Reset the Sum
//--|#1 Hex |-----------------------------a = INCHAR_UART(); // Get CharOUTA_UART(a);i = ascii2digit(a); // Convert ASCII code into digit code (0-F)
//--|#2 Hex |-----------------------------a = INCHAR_UART();
OUTA_UART(a);j = ascii2digit(a); // Convert ASCII code into digit code (0-F)
OUTA_UART(0x2B); // Print out "+" on Hyperterminal
i = i 4; // Get tens
j = sum >> 8; // Get hundreds
OUTA_UART(0x3D); // Print out "="//Display in Hyperterminal
OUTA_UART(hex2ascii(j) );OUTA_UART(hex2ascii(i) );OUTA_UART(hex2ascii(a) );
// New Line in HyperterminalOUTA_UART(0x0D);
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
10/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
OUTA_UART(0x0A);
// Display on LCDLCDSeg[0]= LCDdigit[a];LCDSeg[1]= LCDdigit[i];LCDSeg[2]= LCDdigit[j];
}}charhex2ascii(unsignedcharhex){
if(hex < 0x0A) hex += 0x30;elseif(hex> 0x09 && hex < 0x10) hex += 0x37;
returnhex;}charascii2digit(unsignedcharascii){
unsignedchardigit;
if(ascii>=0x30 && ascii =0x41 && ascii =0x61 && ascii
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
11/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
}voidInit_LCD(void){
intn;for(n=0;n
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
12/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
i = getting_data(); // #3 HEXj = getting_data(); // #4 HEX
OUTA_UART(0x3D); // Print out "="
i = i = i){sub = sub - i;LCDSeg[2]= 0x00; // Clear the third LED
}else{
sub = i - sub ;OUTA_UART(0x2D); // Print out "-"LCDSeg[2]= 0x20; // Display "-"
}
i = sub & 0x0F ; // units Digitj = sub >> 4; // tens Digit
// Display in Hyperterminal
OUTA_UART(hex2ascii(j) );OUTA_UART(hex2ascii(i) );
OUTA_UART(0x0D); // New LineOUTA_UART(0x0A);
// Display on LCDLCDSeg[0]= LCDdigit[i]; // Display on LCDLCDSeg[1]= LCDdigit[j];
}}chargetting_data(){
a = INCHAR_UART();
OUTA_UART(a);returnascii2digit(a);
}charhex2ascii(unsignedcharhex){
if(hex < 0x0A) hex += 0x30;elseif(hex> 0x09 && hex < 0x10) hex += 0x37;
returnhex;}charascii2digit(unsignedcharascii){
unsignedchardigit;
if(ascii>=0x30 && ascii =0x41 && ascii =0x61 && ascii
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
13/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
voidOUTA_UART(unsignedcharA){do{}while((IFG2 & 0x02)==0);// send the data to the transmit bufferUCA0TXBUF =A;}
unsignedcharINCHAR_UART(void){do{
}while((IFG2 & 0x01)==0);// go get the char from the receive bufferreturn(UCA0RXBUF);}
voidInit_UART(void){P2SEL=0x30; // transmit and receive to port 2 bits 4 and 5UCA0CTL0=0; // 8 data, no parity 1 stop, uart, asyncUCA0CTL1= 0x41;UCA0BR1=0; // upper byte of divider clock wordUCA0BR0=3; // clock divide from a clock to bit clock 32768/9600UCA0MCTL=0x06;UCA0STAT=0; // do not loop the transmitter back to the
UCA0CTL1=0x40;IE2=0; // turn transmit interrupts off}voidInit_LCD(void){
intn;for(n=0;n
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
14/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
unsignedchar*LCDSeg = (unsignedchar*) &LCDM3;constunsignedintLCD_SIZE=11;volatileunsignedchara;volatileunsignedinti; // volatile to prevent optimizationvolatileunsignedcharj;volatileunsignedintmulti;constunsignedcharLCDdigit[] =
{0x5F,0x06,0x6B,0x2F,0x36,0x3D,0x7D,0x07,0x7F,0x3F,0x77,0x7C,0x68,0x6E,0x79,0x71};intmain(void){
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerInit_UART();Init_LCD();//Finish SET-UP
for(;;){multi = 0; // Initial Multiple data
i = getting_data(); // Gather data #1 HEXj = getting_data(); // #2 HEX
OUTA_UART(0x2A); // Print out "-"
i = i 12; // #4 digitOUTA_UART(hex2ascii(i) );LCDSeg[3]= LCDdigit[i]; // LCD Display for #4 digit
i = (multi & 0x0F00) >> 8; // #3 digitOUTA_UART(hex2ascii(i) );LCDSeg[2]= LCDdigit[i];
i = (multi & 0x0F0) >> 4; // #2 digitOUTA_UART(hex2ascii(i) );LCDSeg[1]= LCDdigit[i];
i = multi & 0x0F ; // units DigitOUTA_UART(hex2ascii(i) );LCDSeg[0]= LCDdigit[i];
OUTA_UART(0x0D); // New LineOUTA_UART(0x0A);
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
15/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
}chargetting_data(){
a = INCHAR_UART();OUTA_UART(a);returnascii2digit(a);
}charhex2ascii(unsignedcharhex){
if(hex < 0x0A) hex += 0x30;elseif(hex> 0x09 && hex < 0x10) hex += 0x37;
returnhex;}charascii2digit(unsignedcharascii){
unsignedchardigit;
if(ascii>=0x30 && ascii =0x41 && ascii =0x61 && ascii
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
16/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
}
Procedure 5:
//---------------------------------------------------------------// Console I/O through the on board UART for MSP 430X4XXX//---------------------------------------------------------------#include"msp430fg4618.h"#include"stdio.h"#include"string.h"
voidInit_LCD(void);voidInit_UART(void);voidOUTA_UART(unsignedcharA);unsignedcharINCHAR_UART(void);
chargetting_data();voiddetermine_arithmetic();voidimplement_arithmetic();charascii2digit(unsignedcharascii);charhex2ascii(unsignedcharhex);voiddisplay_result();
//Declarationunsignedchar*LCDSeg = (unsignedchar*) &LCDM3;constunsignedintLCD_SIZE=11;volatileunsignedchara;volatileunsignedinti; // volatile to prevent optimizationvolatileunsignedcharj;volatileunsignedintresults;volatileunsignedchararithmetic;constunsignedcharLCDdigit[] =
{0x5F,0x06,0x6B,0x2F,0x36,0x3D,0x7D,0x07,0x7F,0x3F,0x77,0x7C,0x68,0x6E,0x79,0x71};intmain(void){
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timerInit_UART();Init_LCD();//Finish SET-UP
for(;;){results = 0; // Initial Result
i = getting_data(); // Gather data for #1 HEXj = getting_data(); // #2 HEX
//----------------------------------------determine_arithmetic(); // Determine Arithmetic ( + - * )
//----------------------------------------i = i
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
17/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
implement_arithmetic();
//Display resultdisplay_result();}
}
voiddetermine_arithmetic(){a = INCHAR_UART();
OUTA_UART(a);if(a == 0x2D) arithmetic = 0x02; // Subtractelseif(a == 0x2A) arithmetic = 0x03; // Multipleelsearithmetic = 0x01; // Add
}voidimplement_arithmetic(){
if(arithmetic == 0x03) results = results * i; // Multiple arithmeticelseif(arithmetic == 0x02) { // Substract
arithmetic
if(results >= i){results = results - i;
LCDSeg[2]= 0x00;LCDSeg[3]= 0x00;
}else{
results = i - results;OUTA_UART(0x2D); // Print out "-"LCDSeg[2]= 0x20;LCDSeg[3]= 0x00; // Turn off LCD Led #4
}}
elseresults = results + i; // AddArithmetic
}voiddisplay_result(){
if(results> 0x0FFF){i = (results & 0xF000) >> 12; // #4 digitOUTA_UART(hex2ascii(i) );LCDSeg[3]= LCDdigit[i]; // LCD Display
}
if(results> 0x0FF & arithmetic != 0x02){i = (results & 0x0F00) >> 8; // #3 digitOUTA_UART(hex2ascii(i) );LCDSeg[2]= LCDdigit[i];
}
if(results > 4; // #2 digitOUTA_UART(hex2ascii(i) );LCDSeg[1]= LCDdigit[i];
i = results & 0x0F ; // #1 digitOUTA_UART(hex2ascii(i) );LCDSeg[0]= LCDdigit[i];
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
18/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
OUTA_UART(0x0D); // New LineOUTA_UART(0x0A);
}chargetting_data(){
a = INCHAR_UART();OUTA_UART(a);returnascii2digit(a);
}charhex2ascii(unsignedcharhex){
if(hex < 0x0A) hex += 0x30;elseif(hex> 0x09 && hex < 0x10) hex += 0x37;returnhex;
}charascii2digit(unsignedcharascii){
unsignedchardigit;
if(ascii>=0x30 && ascii =0x41 && ascii =0x61 && ascii
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
19/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
}
Part IIAssembly language programs
Procedure 1:
.cdecls C,LIST,"msp430.h" ; Include device header file.sect".sysmem" ; data ram for
initializedLOOKUP .byte0x5F,0x06,0x6B,0x2F,0x36 ; Encoded digits
.byte0x3D,0x7D,0x07,0x7F,0x3F
.byte 0x77,0x7C,0x68,0x6E,0x79,0x71LCD_SIZE .byte11 ; eleven bytes needed bythe LCD;-------------------------------------------------------------------------------
.text ; Assemble into program memory
.retain ; Override ELF conditional linking
.retainrefs ; Additionally retain any sections;-------------------------------------------------------------------------------RESET mov.w #__STACK_END,SP ; Initialize stackpointerStopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer; Initial
call#Init_LCDcall#Init_UART
;-------------------------------------------------------------------------------Mainloop
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitmovR4,R12 ; Get #1 Hex
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitmovR4,R11 ; Get #2 Hex
call#Dis_digit ; Display on LCD#2 Hex
call#Dis_tenth ; Display on LCD#1 Hex;------- New line in Hyperterminal
mov#0x0D, R4call#OUTA_UARTmov#0x0A, R4call#OUTA_UART
jmp Mainloop;-------------------------------------------------------------------------------Ascii2HexDigit; Only accept the uppercase for character from A -> F;-------------------------------------------------------------------------------;------------Value of R4 in range 0 - 9Number1 cmp#0x3A, R4 ; if R4 < A (10)
jlNumber2 ; move to Number2jmpChar1 ; else move to Char1 (R4 not a
number)
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
20/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Number2 cmp#0x30, R4 ; R4 > 0jgeconvert1 ;jmpretn ; Finish convert
convert1 sub#0x30, R4jmpretn
;------------Value of R4 in range A - FChar1 cmp#0x41, R4 ; if R4 >= A
jgeChar2 ; move to Char2jmpretn
Char2 cmp#0x47, R4 ; if R4 < G (mean: R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
21/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
INCHAR_UARTpushR5
lpb mov.b&IFG2,R5and.b#0x01,R5cmp.b#0x00,R5jzlpbmov.b&UCA0RXBUF,R4popR5ret
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_UARTmov.b#0x30,&P2SELmov.b#0x00,&UCA0CTL0mov.b#0x41,&UCA0CTL1mov.b#0x00,&UCA0BR1mov.b#0x03,&UCA0BR0mov.b#0x06,&UCA0MCTLmov.b#0x00,&UCA0STATmov.b#0x40,&UCA0CTL1mov.b#0x00,&IE2ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_LCDmov.b#0x00, R6mov.w#LCDM3, R5mov.b#0x00, R7
lpt mov.bR7, 0(R5)inc.wR5inc.bR6cmp.bLCD_SIZE, R6jnzlptmov.b#0x1C, &P5SEL
mov.b#0x00, &LCDAVCTL0mov.b#0x7E, &LCDAPCTL0mov.b#0x7d, &LCDACTLret
; Stack Pointer definition.global__STACK_END.sect .stack
; Interrupt Vectors.sect ".reset" ; MSP430 RESET Vector.short RESET
Procedure 2:
.cdecls C,LIST,"msp430.h" ; Include device header file.sect".sysmem" ; data ram for
initializedLCDencode .byte0x5F,0x06,0x6B,0x2F,0x36 ; Encoded digits
.byte0x3D,0x7D,0x07,0x7F,0x3F
.byte0x77,0x7C,0x68,0x6E,0x79,0x71Hex .word 0x0000,0x0000RESULT .word0x0000 ; Store result value
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
22/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Offsets .byte0x00;Dis_digit .byte0x00,0x00,0x00,0x00 ; Temporary for splitingResult into digitLCD_SIZE .byte11 ; eleven bytes needed bythe LCD
;-------------------------------------------------------------------------------.text ; Assemble into program memory
.retain ; Override ELF conditional linking
.retainrefs ; Additionally retain any sections;-------------------------------------------------------------------------------RESET mov.w #__STACK_END,SP ; Initialize stackpointerStopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer;------- Initial ---------------------------------------------------------------
call#Init_LCDcall#Init_UARTmov#Dis_digit,R10 ; Use R10 as address for
display digitmov#Hex,R6 ; Use R5 as
address for stores value;---| Main loop |---------------------------------------------------------------
Mainloop
call#Get2_hexmov0(R6),&RESULT ; Store 2 first Hex in
Result
mov#0x2B,R4 ; Print out "+"call#OUTA_UART
add#0x02,R6 ; R6 point to next .WORD
call#Get2_hex
mov#0x3D,R4 ; Print out "="call#OUTA_UART
add0(R6),&RESULT ; ADD arithmetic
call#Split_digit ; Split into digitscall#Dis_hyper ; Display on
Hyperterminal;------| Display on LCD |---------------------------------------------------
mov.b0(R10),R9mov #0x00,&Offsets ; Display on LCD
#1 Hexcall#Display_digit
mov.b1(R10),R9;mov #0x01,&Offsets ; Display on LCD
#2 Hexcall#Display_digit
mov.b2(R10),R9;mov #0x02,&Offsets ; Display on LCD
#3 Hexcall#Display_digit
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
23/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
;------| New line in Hyperterminal |-------------------------------------------mov#0x0D, R4call#OUTA_UARTmov#0x0A, R4call#OUTA_UART
jmp Mainloop
;-------------------------------------------------------------------------------Dis_hyper;----------- Display on Hyperterminal
mov.b2(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b1(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b0(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
ret;++++++++++++++++++++++++++++++++++++++++++++++++++
Split_digitpushR11pushR12mov#Dis_digit,R10 ; Set R10 as Address
mov&RESULT,R11 ; Store data in R11 for processmovR11,R12 ; Back-up R11bic#0xFFF0,R11 ; Get the LSB digitmov.bR11,0(R10) ; Store units digit
movR12,R11 ; Restore R11 for shiftingrram#0x04, R11movR11,R12 ; Back-up after shiftingbic#0xFFF0,R11mov.bR11,1(R10) ; Store units digit
movR12,R11rram#0x04, R11movR11,R12bic#0xFFF0,R11mov.bR11,2(R10) ; Store tens digit
movR12,R11rram#0x04, R11movR11,R12bic#0xFFF0,R11mov.bR11,3(R10) ; Store hundreds digit
popR12popR11ret
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
24/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Get2_hex;Store 2 Hexadicimal at address: R6
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitrlam#0x04,R4 ; 0X h =>
X0 hmovR4,0(R6) ; store #1
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitaddR4,0(R6) ; store next HEX ( XX h)
ret;+++++++++++++++++++++++++++++++++++++++++++++++++
HexDigit2AcsiiNum1 cmp#0x0A, R4
jlNum2jmpChar1c
Num2 cmp#0x00, R4jgecon1jmpretn1
con1 add#0x30, R4jmpretn1
Char1c cmp#0x0A, R4jgeChar2cjmpretn1
Char2c cmp#0x10, R4
jlcon2
con2 add#0x37, R4jmpretn1
retn1 ret;+++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascii2HexDigit; Only accept the uppercase for character from A -> F;-------------------------------------------------------;------------| R4 in range 0 - 9 |----------------------Number1 cmp#0x3A, R4 ; if R4 < A (10)
jlNumber2 ; move to Number2jmpChar1 ; else move to Char1 (R4 not a
number)
Number2 cmp#0x30, R4 ; R4 > 0jgeconvert1 ;jmpretn ; Finish convert
convert1 sub#0x30, R4jmpretn
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
25/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
;------------| R4 in range A - F |----------------------Char1 cmp#0x41, R4 ; if R4 >= A
jgeChar2 ; move to Char2jmpretn
Char2 cmp#0x47, R4 ; if R4 < G (mean: R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
26/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov.b#0x00,&UCA0CTL0mov.b#0x41,&UCA0CTL1mov.b#0x00,&UCA0BR1mov.b#0x03,&UCA0BR0mov.b#0x06,&UCA0MCTLmov.b#0x00,&UCA0STATmov.b#0x40,&UCA0CTL1mov.b#0x00,&IE2ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_LCDmov.b#0x00, R6mov.w#LCDM3, R5mov.b#0x00, R7
lpt mov.bR7, 0(R5)inc.wR5inc.bR6cmp.bLCD_SIZE, R6jnzlptmov.b#0x1C, &P5SELmov.b#0x00, &LCDAVCTL0mov.b#0x7E, &LCDAPCTL0mov.b#0x7d, &LCDACTLret
;------------| Stack Pointer definition |---------------------------------------.global__STACK_END.sect .stack
;---------------| Interrupt Vectors |-------------------------------------------.sect ".reset" ; MSP430 RESET Vector.short RESET
Procedure 3:
.cdecls C,LIST,"msp430.h" ; Include device header file.sect".sysmem" ; data ram for
initializedLCDencode .byte0x5F,0x06,0x6B,0x2F,0x36 ; Encoded digits
.byte0x3D,0x7D,0x07,0x7F,0x3F
.byte0x77,0x7C,0x68,0x6E,0x79,0x71,0x20,0x00
Hex .word 0x0000,0x0000RESULT .word0x0000 ; Store result value
Offsets .byte0x00;Dis_digit .byte0x00,0x00,0x00,0x00 ; Temporary for spliting
Result into digitLCD_SIZE .byte11 ; eleven bytes needed bythe LCD
;-------------------------------------------------------------------------------.text ; Assemble into program memory.retain ; Override ELF conditional linking.retainrefs ; Additionally retain any sections
;-------------------------------------------------------------------------------RESET mov.w #__STACK_END,SP ; Initialize stackpointer
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
27/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer;------- Initial ---------------------------------------------------------------
call#Init_LCDcall#Init_UARTmov#Dis_digit,R10 ; Use R10 as address for
display digitmov#Hex,R6 ; Use R6 as
address for stores value;-------------------------------------------------------------------------------
Mainloopcall#Get2_hex ; Gather 2 first
HEX
mov#0x2D,R4 ; Print out "-"call#OUTA_UART
add#0x02,R6 ; R6 point to next .WORD
call#Get2_hex ; Gather 2 lastHEX
mov#0x3D,R4 ; Print out "="call#OUTA_UART
call#Sub_arithmetic ; SUB arithmetic
call#Split_digit ; Split into digitscall#Dis_hyper ; Display on
Hyperterminalcall#Dis_LCD ; Display on LCD
;------- New line in Hyperterminalmov#0x0D, R4call#OUTA_UARTmov#0x0A, R4
call#OUTA_UART
jmp Mainloop;-------------------------------------------------------------------------------Sub_arithmetic
mov#Hex,R6 ; Reset R6pointer
cmp2(R6),0(R6);jl minus_sign ; If 2(R6) >
0(R6)mov0(R6),&RESULTsub2(R6),&RESULTmov.b#0x00,R15 ; Use R15 = 0 for
plus signjmpfinish_sub
minus_signmov2(R6),&RESULTsub0(R6),&RESULTmov#0x01,R15 ; R15 = 1 for minus sign
finish_sub ret
Dis_LCD
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
28/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
;----------- Display on LCDmov.b0(R10),R9mov #0x00,&Offsets ; Display on LCD
#1 Hexcall#Display_digit
mov.b1(R10),R9;mov #0x01,&Offsets ; Display on LCD
#2 Hexcall#Display_digit
cmp#0x00,R15jeqplus_sign ; Plus signmov.b#0x10,R9; ; Display "-"jmpdis_next
plus_sign mov.b#0x11,R9; ; Turn Off the LCDdis_next mov #0x02,&Offsets ; Display on LCD #3 Hex
call#Display_digit
ret
Dis_hyper;----------- Display on Hyperterminal
cmp#0x00,R15jeqNot_minusmov#0x2D,R4 ; Display "-"call#OUTA_UART
Not_minus
mov.b1(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b0(R10),R4;
call#HexDigit2Acsiicall#OUTA_UART
ret;+++++++++++++++++++++++++++++++++++++++++
Split_digitpushR11pushR12mov#Dis_digit,R10 ; Set R10 as Address
mov&RESULT,R11 ; Store data in R11 for processmovR11,R12 ; Back-up R11bic#0xFFF0,R11 ; Get the LSB digit
mov.bR11,0(R10) ; Store units digit
movR12,R11 ; Restore R11 for shiftingrram#0x04,R11movR11,R12 ; Back-up after shiftingbic#0xFFF0,R11mov.bR11,1(R10) ; Store units digit
movR12,R11rram#0x04,R11
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
29/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
movR11,R12bic#0xFFF0,R11mov.bR11,2(R10) ; Store tens digit
movR12,R11rram#0x04,R11movR11,R12bic#0xFFF0,R11mov.bR11,3(R10) ; Store hundreds digit
popR12popR11ret
Get2_hex;Store 2 Hexadicimal at address: R6
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitrlam #0x04,R4 ; 0X h => X0 hmovR4,0(R6) ; store #1
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitaddR4,0(R6) ; store next HEX ( XX h)
ret;---------------------------------HexDigit2AcsiiNum1 cmp#0x0A, R4
jlNum2jmpChar1c
Num2 cmp#0x00, R4
jgecon1jmpretn1
con1 add#0x30, R4jmpretn1
Char1c cmp#0x0A, R4jgeChar2cjmpretn1
Char2c cmp#0x10, R4jlcon2
con2 add#0x37, R4jmpretn1
retn1 ret;+++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascii2HexDigit; Only accept the uppercase for character from A -> F;-------------------------------------------------------------------------------;------------ R4 in range 0 - 9
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
30/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Number1 cmp#0x3A, R4 ; if R4 < A (10)jlNumber2 ; move to Number2jmpChar1 ; else move to Char1 (R4 not a
number)
Number2 cmp#0x30, R4 ; R4 > 0jgeconvert1 ;jmpretn ; Finish convert
convert1 sub#0x30, R4jmpretn
;------------ R4 in range A - FChar1 cmp#0x41, R4 ; if R4 >= A
jgeChar2 ; move to Char2jmpretn
Char2 cmp#0x47, R4 ; if R4 < G (mean: R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
31/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
lpb mov.b&IFG2,R5and.b#0x01,R5cmp.b#0x00,R5jzlpbmov.b&UCA0RXBUF,R4popR5ret
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_UARTmov.b#0x30,&P2SELmov.b#0x00,&UCA0CTL0mov.b#0x41,&UCA0CTL1mov.b#0x00,&UCA0BR1mov.b#0x03,&UCA0BR0mov.b#0x06,&UCA0MCTLmov.b#0x00,&UCA0STATmov.b#0x40,&UCA0CTL1mov.b#0x00,&IE2ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_LCDmov.b#0x00, R6mov.w#LCDM3, R5mov.b#0x00, R7
lpt mov.bR7, 0(R5)inc.wR5inc.bR6cmp.bLCD_SIZE, R6jnzlptmov.b#0x1C, &P5SELmov.b#0x00, &LCDAVCTL0mov.b#0x7E, &LCDAPCTL0mov.b#0x7d, &LCDACTL
ret;-------------| Stack Pointer definition |--------------------------------------
.global__STACK_END
.sect .stack;-------------| Interrupt Vectors |---------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
Procedure 4:
.cdecls C,LIST,"msp430.h" ; Include device header file.sect".sysmem" ; data ram for
initializedLCDencode .byte0x5F,0x06,0x6B,0x2F,0x36 ; Encoded digits
.byte0x3D,0x7D,0x07,0x7F,0x3F
.byte0x77,0x7C,0x68,0x6E,0x79,0x71,0x20,0x00
Hex .word 0x0000,0x0000RESULT .word0x0000 ; Store result value
Offsets .byte0x00;
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
32/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Dis_digit .byte0x00,0x00,0x00,0x00 ; Temporary for splitingResult into digitLCD_SIZE .byte11 ; eleven bytes needed bythe LCD
;-------------------------------------------------------------------------------.text ; Assemble into program memory.retain ; Override ELF conditional linking.retainrefs ; Additionally retain any sections
;-------------------------------------------------------------------------------RESET mov.w #__STACK_END,SP ; Initialize stackpointerStopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer;------- Initial ---------------------------------------------------------------
call#Init_LCDcall#Init_UARTmov#Dis_digit,R10 ; Use R10 as address for
display digitmov#Hex,R6 ; Use R6 as
address for stores value;------------------| Main loop |-------------------------------------------Mainloop
call#Get2_hex ; Gather 2 first HEXadd#0x02,R6 ; R6 point to next .WORD
mov#0x2A,R4 ; Print out "*"call#OUTA_UART
call#Get2_hex ; Gather 2 last HEX
mov#0x3D,R4 ; Print out "="call#OUTA_UART
call#Multi_arithmetic
call#Split_digit ; Split into digitscall#Dis_hyper ; Display on
Hyperterminalcall#Dis_LCD ; Display on LCD
;------- New line in Hyperterminalmov#0x0D, R4call#OUTA_UARTmov#0x0A, R4call#OUTA_UART
jmp Mainloop;----------------------------------------------------------------------------------
-Multi_arithmetic
mov#Hex,R6 ; Reset R6 pointermov#0x0000,&RESULT ; Empty the resultspushR9 ; Use R9pushR10 ; and R10 as temporary
lp8 mov#0x08,R10
mult_start
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
33/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov2(R6),R9 ; Back-up 2nd termbic#0xFE,R9cmp#0x01,R9 ; If the current digit = 1jeq implementjmpmult_skip
implementadd0(R6),&RESULT ; implement binary adding
mult_skiprla0(R6)rra2(R6)
decR10cmp#0x00,R10jnemult_start
popR9popR10ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Dis_LCD;----------- Display on LCD
mov.b0(R10),R9mov #0x00,&Offsets ; Display on LCD
#1 Hexcall#Display_digit
mov.b1(R10),R9;mov #0x01,&Offsets ; Display on LCD
#2 Hexcall#Display_digit
mov.b2(R10),R9;mov #0x02,&Offsets ; Display on LCD
#3 Hex
call#Display_digit
mov.b3(R10),R9;mov #0x03,&Offsets ; Display on LCD
#4 Hexcall#Display_digit
ret;+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dis_hyper;----------- Display on Hyperterminal
mov.b3(R10),R4;
call#HexDigit2Acsiicall#OUTA_UART
mov.b2(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b1(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
34/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov.b0(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
ret;+++++++++++++++++++++++++++++++++++++++++
Split_digitpushR11pushR12mov#Dis_digit,R10 ; Set R10 as Address
mov&RESULT,R11 ; Store data in R11 for processmovR11,R12 ; Back-up R11bic#0xFFF0,R11 ; Get the LSB digitmov.bR11,0(R10) ; Store units digit
movR12,R11 ; Restore R11 for shiftingrram#0x04,R11movR11,R12 ; Back-up after shiftingbic#0xFFF0,R11mov.bR11,1(R10) ; Store units digit
movR12,R11rram#0x04,R11movR11,R12bic#0xFFF0,R11mov.bR11,2(R10) ; Store tens digit
movR12,R11rram#0x04,R11movR11,R12bic#0xFFF0,R11mov.bR11,3(R10) ; Store hundreds digit
popR12popR11ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++
Get2_hex;Store 2 Hexadicimal at address: R6
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitrlam #0x04,R4 ; 0X h => X0 hmovR4,0(R6) ; store #1
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitaddR4,0(R6) ; store next HEX ( XX h)
ret;+++++++++++++++++++++++++++++++++++++++++++
HexDigit2AcsiiNum1 cmp#0x0A, R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
35/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
jlNum2jmpChar1c
Num2 cmp#0x00, R4jgecon1jmpretn1
con1 add#0x30, R4jmpretn1
Char1c cmp#0x0A, R4jgeChar2cjmpretn1
Char2c cmp#0x10, R4jlcon2
con2 add#0x37, R4jmpretn1
retn1 ret;+++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascii2HexDigit; Only accept the uppercase for character from A -> F;------------------------------------------------------;------------| R4 in range 0 - 9 |---------------------Number1 cmp#0x3A, R4 ; if R4 < A (10)
jlNumber2 ; move to Number2jmpChar1 ; else move to Char1 (R4 not a
number)
Number2 cmp#0x30, R4 ; R4 > 0jgeconvert1 ;jmpretn ; Finish convert
convert1 sub#0x30, R4jmpretn
;------------| R4 in range A - F |---------------------Char1 cmp#0x41, R4 ; if R4 >= A
jgeChar2 ; move to Char2jmpretn
Char2 cmp#0x47, R4 ; if R4 < G (mean: R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
36/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov.w#LCDencode, R8 ; Initialize lookuptable to R8
add.wR9,R8 ; Offset addressof R8
add&Offsets,R5 ; Choose the LEDto display
mov.b0(R8), 0(R5) ; Display Digit
popR5popR8ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
OUTA_UARTpushR5
lpa mov.b&IFG2,R5and.b#0x02,R5cmp.b#0x00,R5jzlpamov.bR4,&UCA0TXBUFpopR5ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INCHAR_UARTpushR5
lpb mov.b&IFG2,R5and.b#0x01,R5cmp.b#0x00,R5jzlpbmov.b&UCA0RXBUF,R4popR5ret
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_UARTmov.b#0x30,&P2SELmov.b#0x00,&UCA0CTL0mov.b#0x41,&UCA0CTL1mov.b#0x00,&UCA0BR1mov.b#0x03,&UCA0BR0mov.b#0x06,&UCA0MCTLmov.b#0x00,&UCA0STATmov.b#0x40,&UCA0CTL1mov.b#0x00,&IE2ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Init_LCDmov.b#0x00, R6mov.w#LCDM3, R5mov.b#0x00, R7
lpt mov.bR7, 0(R5)inc.wR5inc.bR6cmp.bLCD_SIZE, R6jnzlpt
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
37/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov.b#0x1C, &P5SELmov.b#0x00, &LCDAVCTL0mov.b#0x7E, &LCDAPCTL0mov.b#0x7d, &LCDACTLret
;-------------------| Stack Pointer definition |--------------------------------.global__STACK_END.sect .stack
;------------| Interrupt Vectors |----------------------------------------------.sect ".reset" ; MSP430 RESET Vector.short RESET
Procedure 5:
.cdecls C,LIST,"msp430.h" ; Include device header file.sect".sysmem" ; data ram for
initializedLCDencode .byte0x5F,0x06,0x6B,0x2F,0x36 ; Encoded digits
.byte0x3D,0x7D,0x07,0x7F,0x3F
.byte0x77,0x7C,0x68,0x6E,0x79,0x71,0x20,0x00
Hex .word 0x0000,0x0000RESULT .word0x0000 ; Store result value
Offsets .byte0x00;Dis_digit .byte0x00,0x00,0x00,0x00 ; Temporary for splitingResult into digitLCD_SIZE .byte11 ; eleven bytes needed bythe LCD;-------------------------------------------------------------------------------
.text ; Assemble into program memory
.retain ; Override ELF conditional linking
.retainrefs ; Additionally retain any sections
;-------------------------------------------------------------------------------RESET mov.w #__STACK_END,SP ; Initialize stackpointerStopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer;------- Initial ---------------------------------------------------------------
call#Init_LCDcall#Init_UARTmov#Dis_digit,R10 ; Use R10 as address for
display digitmov#Hex,R6 ; Use R6 as
address for stores value;--------------------| Main loop here |-----------------------------------------Mainloop
call#Get2_hex ; Gather 2 first HEX
call#Dect_arithmetic ; Store in R14
add#0x02,R6 ; R6 point to next .WORD
call#Get2_hex ; Gather 2 last HEX
mov#0x3D,R4 ; Print out "="call#OUTA_UART
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
38/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
call#Arithmetic
call#Split_digit ; Split into digitscall#Dis_hyper ; Display on
Hyperterminalcall#Dis_LCD ; Display on LCD
;------- New line in Hyperterminalmov#0x0D, R4call#OUTA_UARTmov#0x0A, R4call#OUTA_UART
jmp Mainloop
;-----------------------------------Dect_arithmetic; Store arithmetic in R14
call#INCHAR_UARTcall#OUTA_UART
cmp#0x2A,R4 ; *jeqmulti_arithcmp#0x2D,R4 ; -jeqsub_arith
jmpadd_arith ; +
sub_arith mov#0x01,R14; -jmpquit_dectecion
multi_arith mov#0x02,R14; *jmpquit_dectecion
add_arith mov#0x00,R14; +
quit_dectecion ret;++++++++++++++++++++++++++++++++++++Arithmetic
cmp#0x02,R14jeqcall_multcmp#0x01,R14jeqcall_sub
cmp#0x00,R14
call_plus call#Plus_arithmetic
jmpfinish_arithcall_mult call#Multi_arithmetic
jmpfinish_arithcall_sub call#Sub_arithmetic ; SUB arithmetic
finish_arithret
;-------------------------------------------------------------------------------Plus_arithmetic
mov#Hex,R6
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
39/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov0(R6),&RESULTadd2(R6),&RESULTret
;++++++++++++++++++++++++++Sub_arithmetic
mov#Hex,R6 ; Reset R6pointer
cmp2(R6),0(R6);jl minus_sign ; If 2(R6) >
0(R6)mov0(R6),&RESULTsub2(R6),&RESULTmov.b#0x00,R15 ; Use R15 = 0 for
plus signjmpfinish_sub
minus_signmov2(R6),&RESULTsub0(R6),&RESULTmov#0x01,R15 ; R15 = 1 for minus sign
finish_sub ret;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Multi_arithmeticmov#Hex,R6 ; Reset R6 pointermov#0x0000,&RESULT ; Empty the resultspushR9 ; Use R9pushR10 ; and R10 as temporary
lp8 mov#0x08,R10
mult_startmov2(R6),R9 ; Back-up 2nd termbic#0xFE,R9cmp#0x01,R9 ; If the current digit = 1jeq implement
jmpmult_skip
implementadd0(R6),&RESULT ; implement binary adding
mult_skiprla0(R6)rra2(R6)
decR10cmp#0x00,R10jnemult_start
popR9
popR10ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Dis_LCD;----------- Display on LCD
mov.b0(R10),R9mov #0x00,&Offsets ; Display on LCD
#1 Hexcall#Display_digit
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
40/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
mov.b1(R10),R9;mov #0x01,&Offsets ; Display on LCD
#2 Hexcall#Display_digit
cmp#0x01,R14 ; Subjeqlcd_subcmp#0x00,R14 ; ADDjeqlcd_pluscmp#0x02,R14jeq lcd_multi
lcd_submov.b#0x11,R9; ; Turn Off the #4
LCD ledmov #0x03,&Offsetscall#Display_digit
cmp#0x00,R15jeqplus_sign ; Plus signmov.b#0x10,R9; ; Display "-" on
#3 LCD Ledmov #0x02,&Offsetscall#Display_digit
jmpdis_next
plus_sign mov.b#0x11,R9; ; Turn Off the LCD
dis_next mov #0x02,&Offsets ; Display on LCD #3 Hexcall#Display_digitjmpexit_lcd
lcd_plusmov.b2(R10),R9;mov #0x02,&Offsets ; Display on LCD
#2 Hexcall#Display_digitjmpexit_lcd
lcd_multimov.b2(R10),R9;mov #0x02,&Offsets ; Display on LCD
#3 Hexcall#Display_digit
mov.b3(R10),R9;mov #0x03,&Offsets ; Display on LCD
#4 Hex
call#Display_digitexit_lcd
ret
Dis_hyper;----------- Display on Hyperterminal
cmp#0x02,R14jeqhyper_multicmp#0x01,R14;jeqhyper_sub
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
41/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
cmp#0x00,R14; +jeqhyper_add
hyper_multimov.b3(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b2(R10),R4;call#HexDigit2Acsiicall#OUTA_UARTjmpNot_minus
hyper_subcmp#0x00,R15jeqNot_minusmov#0x2D,R4 ; Display "-"call#OUTA_UARTjmpNot_minus
hyper_addmov.b2(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
Not_minusmov.b1(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
mov.b0(R10),R4;call#HexDigit2Acsiicall#OUTA_UART
ret;+++++++++++++++++++++++++++++++++++++++++
Split_digitpushR11pushR12mov#Dis_digit,R10 ; Set R10 as Address
mov&RESULT,R11 ; Store data in R11 for processmovR11,R12 ; Back-up R11bic#0xFFF0,R11 ; Get the LSB digitmov.bR11,0(R10) ; Store units digit
movR12,R11 ; Restore R11 for shiftingrram#0x04,R11movR11,R12 ; Back-up after shifting
bic#0xFFF0,R11mov.bR11,1(R10) ; Store units digit
movR12,R11rram#0x04,R11movR11,R12bic#0xFFF0,R11mov.bR11,2(R10) ; Store tens digit
movR12,R11
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
42/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
rram#0x04,R11movR11,R12bic#0xFFF0,R11mov.bR11,3(R10) ; Store hundreds digit
popR12popR11ret
Get2_hex;Store 2 Hexadicimal at address: R6
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitrlam #0x04,R4 ; 0X h => X0 hmovR4,0(R6) ; store #1
call#INCHAR_UARTcall#OUTA_UARTcall#Ascii2HexDigitaddR4,0(R6) ; store next HEX ( XX h)
ret;---------------------------------HexDigit2AcsiiNum1 cmp#0x0A, R4
jlNum2jmpChar1c
Num2 cmp#0x00, R4jgecon1jmpretn1
con1 add#0x30, R4jmpretn1
Char1c cmp#0x0A, R4jgeChar2cjmpretn1
Char2c cmp#0x10, R4jlcon2
con2 add#0x37, R4jmpretn1
retn1 ret;+++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascii2HexDigit; Only accept the uppercase for character from A -> F;-------------------------------------------------------------------------------;------------ R4 in range 0 - 9Number1 cmp#0x3A, R4 ; if R4 < A (10)
jlNumber2 ; move to Number2jmpChar1 ; else move to Char1 (R4 not a
number)
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
43/44
Lab 5Hexadecimal Calculator using MSP-EXP430FG4618/2013 Experimenter Board
Number2 cmp#0x30, R4 ; R4 > 0jgeconvert1 ;jmpretn ; Finish convert
convert1 sub#0x30, R4jmpretn
;------------ R4 in range A - FChar1 cmp#0x41, R4 ; if R4 >= A
jgeChar2 ; move to Char2jmpretn
Char2 cmp#0x47, R4 ; if R4 < G (mean: R4
8/12/2019 QuangHoa HoangLinh QuangTuyen LAB5 EE472 Report.pdf
44/44