Trying to make a multiplexed counter with a MSP430

53 views Asked by At

I'm currently trying to get a counter from 30 to 0 with a 4 digit 7 segment display using a msp430f5529 launchpad but I can't make it count and the display only shows "1". I don't know where the mistake could be, since I'm pretty new at microcontrollers. I'm using code composer studio to make this code.

#include <msp430.h>

#define delay_ms 100

int main(void) { WDTCTL = WDTPW | WDTHOLD;  // stop watchdog timer 

volatile unsigned int valor=30; int unidades = valor%10; int decenas = valor/10;
P2DIR = 0xFF; // Todo el puerto 2 de salida (segmentos)
PJDIR = 0x0F; // Bits de salida PJ.3 PJ.2 PJ.1 PJ.0 (digitos)

while(1)
{
    PJOUT &=~ 0xFF;
    PJOUT |= 0x08;
    for(valor=30;valor>0;valor++)
    {
        imprimir_numero(decenas);
        __delay_cycles(delay_ms);
        PJOUT &=~ 0xFF;
        PJOUT |= 0x04;
        imprimir_numero(unidades);
        __delay_cycles(delay_ms);
    } // Termina for

    valor--;
} 

return 0;
}

void imprimir_numero (unsigned int numero)
{
    P2OUT &=~ 0xFF; // Forzar todos los bits a estar apagados
    switch(numero)
    {
    case 0: P2OUT |= 0x3F;
        break;
    case 1: P2OUT |= 0x06;
        break;
    case 2: P2OUT |= 0x5B;
        break;
    case 3: P2OUT |= 0x4F;
        break;
    case 4: P2OUT |= 0x66;
        break;
    case 5: P2OUT |= 0x6D;
        break;
    case 6: P2OUT |= 0x7D;
        break;
    case 7: P2OUT |= 0x07;
        break;
    case 8: P2OUT |= 0x7F;
        break;
    case 9: P2OUT |= 0x6F;
        break;
    }
} 

I tried to change the __delay_cycles and using a for function as well (maybe I didn't implement it the right way). I was expecting to get a counter from 30 to 0 with a 4 digit 7 segment display by multiplexing it but didn't seem to work. The result I got was just my displays turning on and off showing "1" in a cycle.

0

There are 0 answers