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: SINGLE BIT MANIPULATION problem

Part Number: MSP430G2744


Tool/software: Code Composer Studio

Hi everybody!

As the title of the post said, I'm trying to manipulate a single bit of my variables but unfortunately I have some troubles with this!

What I want to do is:

--> set a 16bit-register in order to contain 16 different flags

--> manipulate each of these bits: I want to switch on and/or off and also test every bit.

I know that in assembly there are instruction like BIC.B, BIS.B and BIT.B.... but in C?!

How can I do that?

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

In my code I also have a routine for the display (composed by 4 7-segment display) that works perfectly with INT type variables.

Now, I need also to work with the POINT of each display and I tried so many combinations that I lost myself...

Can anyone help me with this problem? I think It is related to the question above about the bit manipulation

(infact the DP is the BIT7 of each display and unfortunately now i'm not able to set it in my routine.-->Why?!)

/************************************************************************************************************
 * 						Display.c
 ***********************************************************************************************************/
 /* Created on: 22 giugno 2017
 *  Author: Maria Angela Cianci
 */
/************************************************************************************************************
 * 					INIZIALIZZAZIONE DEL DISPLAY
  ***********************************************************************************************************/
#include <msp430.h>
#include <Definizioni_Display.h>
#include <Timer_Variable.h>
#include <Board_Initialization.h>
#include <Definizioni_Tastiera.h>
#include <Watchdog.h>
/************************************************************************************************************
 * 					ARRAY PER LA DECODIFICA
 * Definisco un array di tipo "char" per la decodifica dei numeri (per cui ho creato le maschere).
 *
 ***********************************************************************************************************/
const char MASK_DECODE []= {mask_00,mask_01,mask_02,mask_03,mask_04,mask_05,mask_06,mask_07,mask_08,mask_09,mask_DP};

void delay_display (unsigned long d) {
  unsigned long i;
  for (i=0;i<d;i++);

}


void display_startup (unsigned int numero) {

	int i=0;
	/*Ciclo per dividere cifra per cifra il numero nel corrispondente display*/
	for (i=0;i<4;i++) {
		display[i]=numero%10;
		numero=numero/10;
		}
}

#pragma vector= TIMERA0_VECTOR
__interrupt void timerDISPLAY (void) {
	TACCR0+= offset_timerA; //Aggiungo l'offset a TACCR0

//	P2OUT^=B_OSC; 			//Toggle x prova DEBUG OSCILLOSCOPIO

	/*Spegne tutti i display*/
	P1OUT|= (COL0+COL1+COL2+COL3);
	display_ptr=(display_ptr%4);
	P4OUT= MASK_DECODE [display[display_ptr]];

	P2OUT|=LATCH_ENABLE; 	//LATCH_ENABLE=1;
	P2OUT&=~LATCH_ENABLE;	//LATCH_ENABLE=0;

	switch (display_ptr) {
	/*Attiva il display indicato dal puntatore, mettendo a ZERO il pin corrispondente*/
	case 0: P1OUT&= ~COL3; break;
	case 1:	P1OUT&= ~COL2; break;
	case 2:	P1OUT&= ~COL1; break;
	case 3:	P1OUT&= ~COL0; break;
	}
	display_ptr ++;

	if (time_counter<4) {
		time_counter++;

	}
	else {
		time_counter=0;
		timer_10ms++;
		tastiera_standard();

		if (timer_10ms>9) {
			timer_10ms=0;
			timer_100ms++;
			delay_tasto++;
			delay_tastocont++;
			}
		if (timer_100ms>9) {
			timer_100ms=0;
			timer_1s++;
			}
		if (timer_1s>59) {
			timer_1s=0;
			timer_1min++;
		}
		if (timer_1min>59) {
			timer_1min=0;
			timer_1h++;
		}
	}
}

void display_initialization () {
	/*Attivo l'interrupt per il timer*/
	TACCTL0=CCIS_0+CCIE;
	/*Spengo tutti i display e inizializzo il contatore che mi scandir� i display*/
	P1OUT|=(COL0+COL1+COL2+COL3);
	display_ptr=0;
}


/************************************************************************************************************
 * 											Definizioni_Display.h
 ***********************************************************************************************************/
 /* Created on: 03 luglio 2017
 *  Author: Maria Angela Cianci
 */

#ifndef DEFINIZIONI_H_
#define DEFINIZIONI_H_
/************************************************************************************************************
 * 								DEFINIZIONI DELLE MASCHERE DEI CARATTERI
 * Indica quali LED di ogni display 7 segmenti accendere/spegnere per visualizzare il numero.
 * SEG_ON 0, SEG_OFF 1.
 *
 ***********************************************************************************************************/
#define mask_00 	(0b11000000)
#define mask_01		(0b11111001)
#define	mask_02		(0b10100100)
#define	mask_03		(0b10110000)
#define	mask_04		(0b10011001)
#define	mask_05		(0b10010010)
#define	mask_06		(0b10000010)
#define	mask_07		(0b11111000)
#define	mask_08		(0b10000000)
#define mask_09		(0b10010000)
#define	mask_DP		(0b01111111)

/************************************************************************************************************
 * 											DELAY DEL DISPLAY
 * Imposto un ritardo SW necessario per la visualizzazione sul display.
 *
 ***********************************************************************************************************/
#define DELAY	65000

/************************************************************************************************************
 * 					DEFINIZIONI DELL'HARDWARE: DISPLAY
 * Definizioni delle linee di pilotaggio dei display.
 *
 ***********************************************************************************************************/
#define COL0	BIT3
#define COL1	BIT4
#define COL2	BIT5
#define COL3	BIT6
/***********Definizione del bit su cui controllo il timing con l'oscilloscopio in fase di DEBUG*************/
//#define B_OSC 	BIT5

/************************************************************************************************************
 * 				DEFINIZIONI DELL'HARDWARE: LATCH D
 * Definisco il pin di latch enable. E' essenziale per la visualizzazione dei valori
 * sul singolo display selezionato.
 ***********************************************************************************************************/
#define LATCH_ENABLE	BIT6

/************************************************************************************************************
 * 					GESTIONE DEI 4 DISPLAY
 * Utilizzo un array di tipo "char" senza segno per la sequenza dei 4 display.
 * Creo anche una variabile "puntatore" che verr� utilizzata per la scansione dei display,indicando
 * quale display � acceso.
 *
 ***********************************************************************************************************/
unsigned char display [5];
#define	disuni	display[0]
#define disdec	display[1]
#define	discen	display[2]
#define	dismil	display[3]
#define	disLED	display[4]

char display_ptr;
/************************************************************************************************************
  *				PROTOTIPI DELLE FUNZIONI per il DISPLAY
  ***********************************************************************************************************/
 void display_initialization ();
 void display_startup (unsigned int numero);
 void delay_display (unsigned long d);
/************************************************************************************************************
   *					FLAG DEDICATI AL PUNTO SUL DISPLAY
 ***********************************************************************************************************/


#define	FLAG_DOTUNI			0x0001
#define	FLAG_DOTDEC			0x0002
#define	FLAG_DOTCEN			0x0004
#define	FLAG_DOTMIG			0x0008


#endif /* DEFINIZIONI_H_ */

/**************************************************************************
 * 			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_Display.h>
#include "Definizioni_Tastiera.h"
#include <Timer_Variable.h>

/**************************************************************************
 * 	MAIN PER PROVARE LA ROUTINE DI CONTROLLO DEL DISPLAY         *
 *************************************************************************/
unsigned char TASTO;
unsigned char OLD_TASTO;

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();
	//VALUE=5790;
	Temp_Setpoint=25;
	VALUE=Temp_Setpoint;
	display_initialization();

	while (1) {
		 	 watchdog();
		 	 botton_pushed(TASTO);
		 	 display_startup(VALUE);
		 	 //delay_display (DELAY);
	}

}

Hoping in Your answers,

thank You for the attention

Kind Regards

Maria Angela

 

**Attention** This is a public forum