actualmente trabajando en el software rebotar botón. Usando el libro de Davies MSP430. Estoy tratando de escribir código similar en C (usando CCS) para un MSP430FR6989. El programa usa cambio de bits, y entiendo la idea de ello. Lo que no puedo entender es cómo descifrar estas # definiciones que usa Davies. No sé cómo convertir eso para el FR6989. Sigo recibiendo errores que tengo elementos indefinidos.
Al igual que defino RAW_BUTTON_PRESS1 como P1IN_bit.P1IN_1 y obtengo errores de que P1IN_bit no está definido. Tengo problemas para entender estas conversiones de asignación de pin
fragmento de davies
mi código
// Device: FR6989
// See Davies MSP430 Software Debounce starting on pg 233
#include <msp430.h>
#include <intrinsics.h>
#include <stdint.h>
union debounce{
unsigned char debounceP1IN;
struct {
unsigned char debounceP1IN_0 : 1;
unsigned char debounceP1IN_1 : 1;
unsigned char debounceP1IN_2 : 1;
unsigned char debounceP1IN_3 : 1;
unsigned char debounceP1IN_4 : 1;
unsigned char debounceP1IN_5 : 1;
unsigned char debounceP1IN_6 : 1;
unsigned char debounceP1IN_7 : 1;
} debounceP1IN_bit;
};
#define RAW_BUTTON_PRESS1 P1IN_bit.P1IN_1
#define DEBOUNCE_BUTTON_PRESS1 debounceP1IN_bit.debounceP1IN_1
#define LED1 P1OUT_bit.P1OUT_0
void main (void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
P1OUT &= ~BIT0; //Pre-load LED P1.0 Off
P1DIR |= BIT0; //Set P1.0 LED to output
P1DIR &= ~BIT1; //set P1.1 button to input
P1REN |= BIT1; //Enable Resistor Button P1.1
P1OUT |= BIT1; //Set as Pullup resistor Button P1.1
debounceP1IN = 0xFF; //initialize debounce state of P1.1
TA0CCR0 = 5000; // TA0 interrupt triggers every 5 ms
TA0CCTL0 |= CCIE; //Enable TA0 interrupt
TA0CTL |= (TASSEL_2 + MC_1 + TACLR); //SMCLK (1mhz) count to CCR0, clear timer
__enable_interrupt();
for(;;)
{
LED1 = DEBOUNCE_BUTTON_PRESS1; //Update LED1 from debounced button
}
}
#define PRESS_THRESHOLD 0x3F
#define RELEASE_THRESHOLD 0xFC
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TA0_ISR (void)
{
static unsigned char P11ShiftReg = 0xFF; // Shift Reg for history of P1.1
P11ShiftReg >>= 1; // Update history in shift register
if (RAW_BUTTON_PRESS1 == 1) //Insert latest input from P1.1
{
P11ShiftReg |= BIT7; //Set MSB of Shiftreg P1.1 to 1
}
if (DEBOUNCE_BUTTON_PRESS1 == 0) //when debounce value is low
{
if(P11ShiftReg >= RELEASE_THRESHOLD) //when button is released
{
DEBOUNCE_BUTTON_PRESS1 = 1; //set new debounce state high
}
}
else if(P11ShiftReg <= PRESS_THRESHOLD) //when debounce value is high and button is pressed
{
DEBOUNCE_BUTTON_PRESS1 = 0; //set new debounce state low
}
}