This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2744: PROBLEMS WITH C MIXED ASSEMBLY FUNCTION

Part Number: MSP430G2744

Tool/software: Code Composer Studio

Goodmorning Everybody!

I have some debugging troubles with the code I wrote, but first of all let me explain a bit more about my program.

I want my little keyboard with UP and DOWN buttons to change a value on the display by incrementing or decrementing a start point value and, in the ISR of the TIMER A, I need to call my .asm function every 10ms so that I would be able to know if the general button (that is my variable TASTO) is or not pressed by the user.

After reading that value I call the .c function "button_pushed" for doing some different operations in the case the button pushed is UP or DOWN button.

I have a .c header file shared with an .asm file: here there are the definitions of all the variables  and functions I want to use in the .asm file.

In this header file I declared the variable TASTO as follows:

extern unsigned char TASTO;

In the .asm file I wrote something like this:

.bss TASTO, 1

.global TASTO

and until this point everything looks fantastic: infact when I compile my code I haven't any errors and warnings.

But unfortunately I can't tell the same for the debug step because my program doesn't do what I want (as described above).

It seems like the linker file doesn't match the variable TASTO decleared in .c header file with the variable that I'm using in the .asm function.

Is it possible? Have I write something wrong?

Which is the easiest way to declare a variable in C header file and use it in .asm file, sharing that header file?

(The files mantioned before are attached to this post).

I hope someone could really help me to find out a solution so that I can proceed with my work.

Thank You very much for the attention,

Kind Regards,

Maria Angela

;	/***********************************************************************************************************
;	* 						Tastiera.asm
;	***********************************************************************************************************/
;	/* Created on: 24 luglio 2017
;	*  Author: Maria Angela Cianci
;	*/

;***************************************************************************************************************
;	La macro tastiera gestisce la pressione dei tasti e la funzione del tasto premuto, purch� il dat gli arrivi
; 	all'interno del registro R4 in posizione LSB. Questa sar� poi la funzione che vado a chiamare per il
;	controllo della tastiera (tasto premuto o no, per quanto tempo, ecc...).
;***************************************************************************************************************
;***************************************************************************************************************
;	La direttiva cdecl mi permettere di includere i vari header file di cui ho bisogno per il funzionamento
;	del programma.
;***************************************************************************************************************

		.cdecls C,LIST, "msp430g2744.h"
		.cdecls C,LIST, "Definizioni_Tastiera.h"

		.align 2
		.bss	TASTO,1
		.bss	OLD_TASTO,1
		.bss	PRENDITASTO,1
		.bss	FLAG_VARI,2,2
		.bss	TIMER_BLINK,1
		.bss	TIMER_TASTOSOLO,1
		.text
		.global	TASTO
		.global OLD_TASTO
		.global	tastiera_standard

tastiera_standard:	.asmfunc
				
				push.w	R5
				mov.b	P2IN, R5
				inv.b	R5
				and.b	#00111111b, R5
				cmp.b 	OLD_TASTO, R5
				jeq		tasto_premuto
ritasto:		mov.b 	R5, OLD_TASTO
				clr.b	TASTO
				bic.w	#(FLAG_TASTOCONTINUO+FLAG_TASTOSOLO+FLAG_TASTOPREMUTO),FLAG_VARI
				mov.b	#CAMPIONI_TASTI, PRENDITASTO
				clr.b	TIMER_TASTOSOLO
				br		#tastiera_exit
tasto_premuto:	bit.w	#(FLAG_TASTOCONTINUO+FLAG_TASTOSOLO+FLAG_TASTOPREMUTO),FLAG_VARI
				jne		PRESO
				dec.b	PRENDITASTO
				jn		PRESO
				mov.b	R5, OLD_TASTO
				br		#tastiera_exit
PRESO:			mov.b	#CAMPIONI_TASTI, PRENDITASTO
				mov.b	OLD_TASTO, TASTO
				tst.b	TASTO
				jeq		ritasto
				bit.b	#TIMER_BLINK800,TIMER_TASTOSOLO
				jne		tasto_continuo
				bit.w	#(FLAG_TASTOCONTINUO + FLAG_TASTOSOLO),FLAG_VARI
				jne		tastiera_exit
				bis.w	#FLAG_TASTOSOLO, FLAG_VARI
				bic.b	#FLAG_TASTOCONTINUO, FLAG_VARI
				br		#tastiera_exit
tasto_continuo:	bis.b	#TIMER_BLINK800, TIMER_TASTOSOLO
				bis.w	#FLAG_TASTOCONTINUO, FLAG_VARI
				bic.w	#FLAG_TASTOSOLO, FLAG_VARI
tastiera_exit:
				pop.w	R5
				ret
				.endasmfunc

/************************************************************************************************************
 * 						Routine_Tastiera.c
 ***********************************************************************************************************/
 /* Created on: 26 luglio 2017
 *  Author: Maria Angela Cianci
 */

#include <msp430.h>
#include <Board_Initialization.h>
#include <Definizioni_Tastiera.h>
#include <Definizioni_Display.h>


void botton_pushed (unsigned char tasto) {
	unsigned char tasto_up;
	unsigned char tasto_down;
	tasto_up=TASTO_UP;
	tasto_down=TASTO_DOWN;
	tasto=TASTO;
	if(tasto==tasto_up) {
		VALUE++;
		Temp_Setpoint=VALUE;
		}
	if(tasto==tasto_down) {
		VALUE--;
		Temp_Setpoint=VALUE;
		}
	else {
		VALUE;
		Temp_Setpoint=VALUE;
			}
}


/************************************************************************************************************
 * 						Definizioni_Tastiera.h
 ***********************************************************************************************************/
 /* Created on: 24 luglio 2017
 *  Author: Maria Angela Cianci
 */
/************************************************************************************************************
 * 					DEFINIZIONI DELLE MASCHERE DEI TASTI
 *			 Associa ogni PIN della porta 2 ad un determinato tasto sulla tastiera.
 *
 ***********************************************************************************************************/
#define	TASTO_UP	0b00001000
#define	TASTO_DOWN	0b00000010

extern unsigned char TASTO;
extern unsigned char OLD_TASTO;
unsigned int Temp_Setpoint;
extern void tastiera_standard();
void botton_pushed (unsigned char tasto);


/**************************************************************************
 * 				PROGETTO EL_0002_17_V00
 *  Created on: 22 giugno 2017
 *  Poject Name: SOUS COOKER SEMIPROFESSIONAL
 *  Mcu: MSP430G2744
 *  Author: Maria Angela Cianci
 *************************************************************************/

#include <msp430.h>
#include <Clear_RAM.h>
#include <Watchdog.h>
#include <Board_Initialization.h>
#include <Tlv_Structure.h>
#include <Definizioni_Tastiera.h>
#include <Definizioni_Display.h>
#include <Timer_Variable.h>

/**************************************************************************
 				* 	MAIN	*
 *************************************************************************/

int main(void) {
	WDTCTL = WDTPW | WDTHOLD;	//watchdog_disable;
	/* Inizializzo lo stack pointer al valore 0x5FF in fondo alla RAM */
	__asm (" MOV.W   #0x0600,SP");
	clear_RAM();
	delay_watchdog(wdt_delay);
	watchdog_enable();
	configurazione_iniziale();
	Temp_Setpoint=100;
	VALUE=Temp_Setpoint;
	display_initialization();
	while (1) {
		 watchdog();
		botton_pushed(TASTO);
		display_startup(VALUE);		--> routine to display the value on 8-segment 4 digit display

	}

}

  • Hi Maria Angela,

    I think you might really be declaring the TASTO variable twice, but you are really wanting TASTO to be a global variable that the .asm file can also modify, correct? I think you should not be declaring the TASTO variable in your .asm file, just make sure you have the header file included and then start using it in the assembly file. Here is an example I made for having a global variable that an assembly function can use and modify:

    main.c:

    /* main.c */
    #include <msp430.h> 
    #include "asm_func.h"
    
    unsigned char test = 0;
    unsigned char i = 0;
    
    /**
     * main.c
     */
    void main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    	
    	while(1)
    	{
    	    for(i = 0; i < 255; i++)
    	    {
    	        asm_func();
    	        __no_operation();
    	    }
    
    	    test = 0;
    	}
    }

    asm_func.h

    /*
     * asm_func.h
     *
     *  Created on: Aug 25, 2017
     *      Author: a0282836
     */
    
    #ifndef ASM_FUNC_H_
    #define ASM_FUNC_H_
    
    extern unsigned char test;
    void asm_func(void);
    
    #endif /* ASM_FUNC_H_ */
    

    asm_func.asm

    		;asm_func.asm
    
    		.cdecls C,LIST, "msp430g2744.h"
    		.cdecls C,LIST, "asm_func.h"
    
    asm_func: .asmfunc
    		push.w R5
    		mov.b test, R5
    		inc test
    		pop.w R5
    		ret
    		.endasmfunc
    

    Does this help?

    Regards,

    Katie

  • Dear Katie,
    Thank you very much for your precious answer and exemple.
    It really help me a lot with my debugging troubles!! :)

    Regards,
    Maria Angela
  • Great! I'm so glad I could help.
    -Katie

**Attention** This is a public forum