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.

MSP430G2553: lpm

Part Number: MSP430G2553

Tool/software:

We are working on a project on MSP430G2553, the function of this project is to implement a charge controller, so that through a matrix keyboard the days and times for the activation of the loads will be chosen, remembering that it must run in LPM3 mode, but we get stuck, someone can send any tips or recommendations

#include <msp430.h> // Inclui o cabeçalho para a família de microcontroladores MSP430
#include "hd44780.h" // Inclui o cabeçalho específico para um display LCD HD44780
#include <stdlib.h> // Inclui o cabeçalho padrão da biblioteca de funções de uso geral em C
#include <math.h> // Inclui o cabeçalho para operações matemáticas
#include <stdint.h> // Inclui o cabeçalho padrão da biblioteca de inteiros de largura fixa em C
#include <inttypes.h> // Inclui o cabeçalho padrão da biblioteca de tipos inteiros de largura fixa em C
#include <Temporizador.h>
#include <Utilidades.h>
#include <Botao.h>
#define segunda BIT6
#define terca BIT5
#define quarta BIT4
#define quinta BIT3
#define sexta BIT2
#define sabado BIT1
#define domingo BIT0


#define byte char // Define um alias 'byte' para 'char'
#define hab BIT7 // Define um alias 'hab' para 'BIT7'
#define s(lo) 1<<lo

byte Dia; // Declara uma variável 'dia' do tipo 'byte'
byte vet_circular[8]={0x7F, 0x7E, 0x7C, 0x03, 0x50, 0x0A, 0x54, 0x2A}; // Inicializa um array 'vet_circular' de 8 elementos
byte lo;
byte T;
char tecla;
char teclado[4][4]= {{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}};

//CONTROLE DE Carga inicio//
typedef struct prog { // Define uma estrutura 'prog'
byte Diason; // Membro 'Diason' da estrutura 'prog'
byte Diasoff; // Membro 'Diasoff' da estrutura 'prog'
int hon, hoff;// 23 59
} Programacao; // Define um alias 'Prog' para 'struct prog'

struct carga { Programacao prog[3]; byte bite;}; // Define uma estrutura 'carg' com membros 'programacao' e 'bite'

void main(){// Função principal 'main'
struct carga Carga[2]; // Declara um array de 2 elementos do tipo 'struct carg'
int i, j; // Declara variáveis inteiras 'i' e 'j'
byte Dia = segunda;// 7 6 5 4 3 2 1 0
int Horas = 0;
// h/d
for(i=0; i<2; i++){ //desabilita a programação de todas as cargas. Loop externo de 0 a 1
for(j=0; j<3; j++){ // Loop interno de 0 a 2
Carga[i].prog[j].Diason= 0x7F; Carga[i].prog[j].Diasoff= 0x7F; // Inicializa membros 'Diason' e 'Diasoff' de cada elemento de 'Carga'
}
Carga[i].bite = (1<<i); // Define o valor do membro 'bite' de cada elemento de 'Carga'
}
configTeclado();

P2IE &= 0x0F; // desabilita interrupção dos bits 4 a 7 da P2
P2IES &= 0x0F; // configura para borda de subida (BIT4 a 7)
P2IFG &= 0x0F; // limpa flag de interrupção
P2IE |= 0xF0; // habilita interrupção

//RTI_PORTA 2
for( i=4;i<8;i++){ //linha que gerou interrupção
if(P2IFG & s(i)){
P2IE &=~s(i);
lo = i;
if(!(P2IES & s(i))){
for( j=0;j<4;j++){
LPM3;
if(P2IN & s(j)){
tecla = teclado[i-4][j];
break;
}
}
}
}
}
TA0CCR1 += T;
TA0CCTL1 &=~ CCIFG;
TA0CCTL1 |= CCIE;

P2OUT = 0; // Limpa o registrador P2OUT
while(1){ // Loop infinito
for (i = 0; i < 2; i++) { //procura pela carga habilitada para ligar e desligar a carga. Loop externo de 0 a 1
for (j = 0; j < 3; j++) { // Loop interno de 0 a 2
if (((Carga[i].prog[j].Diason & (hab | Dia)) == (hab | Dia))
&& (Carga[i].prog[j].hon == Horas)) { //verifica se é pra ligar
P1OUT |= Carga[i].bite;
}
if (((Carga[i].prog[j].Diasoff & (hab | Dia)) == (hab | Dia))
&& (Carga[i].prog[j].hoff == Horas)) { //verifica se é pra ligar
P1OUT &= ~Carga[i].bite;
}
}
} //for externo
}
}
byte opcoes_dias(byte i){ // Função 'opcoes_dias' com argumento 'i'
if ((i>= 0) && (i <= 7)) { // Condição se 'i' está entre 0 e 7
return vet_circular[i]; // Retorna o valor do índice 'i' do array 'vet_circular'
}else{ // Caso contrário
if((i>7) && (i<=13)){ // Condição se 'i' está entre 8 e 13
return(i-6); // Retorna 'i-6'
}else{ // Caso contrário
return 1; // Retorna 1
}
}
}
//CONTROLE DE Carga fim //


#pragma vector=TIMER1_A0_VECTOR // Define um vetor de interrupção para o TIMER1_A0
__interrupt void TIMER1_A0_ISR(void) { // Rotina de serviço de interrupção para o TIMER1_A0
//inicio relogio//
switch(TA0IV){
case 0x02://canal 1
P2IES ^= s(lo);
P2IFG &=~ (0XF0);
P2IE |= 0XF0;
TA0CCTL1 &=~ CCIE;
break;

case 0x04://canal 2
TA0CCR2 += 32768;
LPM3_EXIT;
break;
}
//fim relogio
TA1CCTL0 &= ~CCIFG; // Limpa a bandeira de interrupção
}


/*
for(i=0; i<2; i++){ // Loop externo de 0 a 1
for (j = 0; j < 3; j++) { // Loop interno de 0 a 2
if (Carga[i].prog[j].Diason & (hab | Dia) == (hab | Dia)) { // Condição baseada no valor dos membros 'Diason' e 'dia' de cada elemento de 'Carga'
P2OUT |= (1 << Carga[i].bite); // Configura o bit correspondente do registrador P2OUT
}

if (Carga[i].prog[j].Diasoff & (hab | Dia) == (hab | Dia)) { // Condição baseada no valor dos membros 'Diasoff' e 'dia' de cada elemento de 'Carga'
P2OUT &= ~(1 << Carga[i].bite); // Limpa o bit correspondente do registrador P2OUT
}
}
}*/

  • I don't see where you start TA0. Are you using TASSEL__ACLK?

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

    #pragma vector=TIMER1_A0_VECTOR // Define um vetor de interrupção para o TIMER1_A0

    Since you're working with TA0CCTL1:CCIFG, this should be

    > #pragma vector=TIMER0_A1_VECTOR // Define um vetor de interrupção para o TA0

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

    > P2IE |= 0xF0; // habilita interrupção

    You're enabling pin interrupts in P2, but I don't see an ISR  (PORT2_VECTOR) for them

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

    Either of these would send you off to the unused_vector function (I've forgotten what it's called).

  • Hi Erick,

    Please give some descriptions about what the issues is, and what's your expectation.

    It is out of my ranges to review your code without some background.

    B.R.

    Sal

**Attention** This is a public forum