Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 22203

#29 expected an expression strings how to fix it?

$
0
0

Code Composer Studio

Version: 6.1.2.00015

I am trying to make a very simple code but I don't know why the #29 error pops out. It's on the same line repeated, the ones in grey. The idea of the project is that using PuTTY terminal or any other terminal, I would be able to make one of the leds blink and control the brightness of the other led and when I write 'EF' in the terminal, the MSP430G2553 should return a status message.

//******************************************************************
// USCI UART
//******************************************************************
#include "msp430g2553.h"
#define PER 50000
#define COUNT 10

//******************************************************************
// Global data
//******************************************************************
const char string1[25];
int counter=COUNT;
unsigned int i;
unsigned int blink=0;
unsigned int recieved=0;
unsigned int brightness;

//******************************************************************
// Function prototypes
//******************************************************************
void UARTSetup(void);
//*****************************************************************
// Main routine
//*****************************************************************


void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
//--------------------- Ports -----------------------------
P1DIR |= 0x41; //P1.0 and P1.6 as digital outputs - LED1 and LED2
P1DIR &= ~0x08; //P1.3 as input - SW1

P1SEL = BIT1 | BIT2 | BIT6; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 | BIT2 ; // P1.1 = RXD, P1.2=TXD


P1REN |= 0x08; //Enable PULL UP/DOWN resistor
P1OUT |= 0x08; //PULL UP resistor set

//--------------------- Basic Clock -----------------------------

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
//1Mhz
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */

//LFXTAL
BCSCTL1 |= DIVA_0;
BCSCTL2 = SELM_2 | DIVM_0;
BCSCTL3 = LFXT1S_0 | XCAP_1;
//blinking initial configuration
P1DIR |= 0x09;//xxxx 1xx1
P1DIR &= ~0x08;//xxxx 0xx1
P1REN |= 0x08;
P1OUT |= 0x08;

P1OUT &= ~0x09;
P1OUT |= 0x08;

P1IFG = 0x00;
P1IES |= 0x08;
P1IE |= 0x08;
//--------------------- Timer A -----------------------------
TA0CTL = TASSEL_2 |MC_1 | ID_0 ; // SMCLK, up mode
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = PER;
CCTL1 = OUTMOD_6; // CCR1 int. enabled
CCR1 = 25000;//HIGH_STATE_INI;
//--------------------- USCI ------------------------------------
UARTSetup();

__bis_SR_register(LPM1_bits + GIE); // Enter LPM3 w/ int until Byte RXed
}

//******************************************************************
// Interrupt service routine:
//******************************************************************
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A_CC0 (void)
{
if(blink==1){
counter--;
if(counter == 0) {// && counter1==0){
P1OUT ^= 0x01; // overflow
counter=COUNT;
}
}
}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
UCA0TXBUF = string1[i++]; // TX next character

if (i == sizeof string1 - 1){ // TX over?
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
UCA0TXBUF=UCA0RXBUF;
if (UCA0RXBUF == 'a') // 'u' received?
{
blink=1;
//i = 0;
//IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
//UCA0TXBUF = string1[i++];
}
else if(UCA0RXBUF == 'b'){
blink=0;
}
else if (UCA0RXBUF == 'c') {
CCR1 = CCR1 + 5000;//HIGH_STATE_INI;
if (CCR1==50000)
{
CCR1 = 0 ;
}

}
else if (UCA0RXBUF == 'd') {
CCR1 = CCR1 - 5000;//HIGH_STATE_INI;
if (CCR1==0)
{
CCR1 = 50000 ;
}

}
else if(UCA0RXBUF == 'E'){
recieved=1;
}

else if((UCA0RXBUF == 'F') && (recieved==1)){
brightness=(CCR1/50000)*100;
if(blink==0){
if(brightness==10){
string1[]={"Jose_not_blinking_10%\r\n" };
}
else if(brightness==20){
string1[]={"Jose_not_blinking_20%\r\n" };
}
else if(brightness==30){
string1[]={"Jose_not_blinking_30%\r\n" };
}
else if(brightness==40){
string1[]={"Jose_not_blinking_40%\r\n" };
}
else if(brightness==50){
string1[]={"Jose_not_blinking_50%\r\n" };
}
else if(brightness==60){
string1[]={"Jose_not_blinking_60%\r\n" };
}
else if(brightness==70){
string1[]={"Jose_not_blinking_70%\r\n" };
}
else if(brightness==80){
string1[]={"Jose_not_blinking_80%\r\n" };
}
else if(brightness==90){
string1[]={"Jose_not_blinking_90%\r\n"};
}
else if(brightness==100){
string1[]={"Jose_not_blinking_100%\r\n" };
}
}
else if(blink==1){
if(brightness==10){
string1[]={"Jose_blinking_10%\r\n" };
}
else if(brightness==20){
string1[]={"Jose_blinking_20%\r\n" };
}
else if(brightness==30){
string1[]={"Jose_blinking_30%\r\n" };
}
else if(brightness==40){
string1[]={"Jose_blinking_40%\r\n" };
}
else if(brightness==50){
string1[]={"Jose_blinking_50%\r\n" };
}
else if(brightness==60){
string1[]={"Jose_blinking_60%\r\n" };
}
else if(brightness==70){
string1[]={"Jose_blinking_70%\r\n" };
}
else if(brightness==80){
string1[]={"Jose_blinking_80%\r\n" };
}
else if(brightness==90){
string1[]={"Jose_blinking_90%\r\n"};
}
else if(brightness==100){
string1[]={"Jose_blinking_100%\r\n" };
}
}

i = 0;
IE2 |= UCA0TXIE; // Enable USCI_A0 TX interrupt
UCA0TXBUF = string1[i++];

}
else if(UCA0RXBUF != 'E'){
recieved=0;
}
}

//***************************************************************************
// UARTSetup
// **************************************************************************
void UARTSetup(void)
{

//1) -> initialization/re-configuration process <-BEGIN
UCA0CTL1 |= UCSWRST;//Set UCSWRST -- needed for re-configuration process
//1) END

//2) -> Initialize all USCI registersSet <- BEGIN
// CONTROL REGISTERS
//UCA0CTL0 -> Control Register 0
// 7 | 6 | 5 | 4 | 3 | 2-1 | 0 |
//------------------------------------------------------------------------
//UCPEN|UCPAR|UCMSB|UC7BIT|UCSPB|UCMODEx|UCSYNC|
//UCPEN (Parity) = 0b -> Parity disabled
//UCPAR (Parity select) = 0b -> Odd parity "Not importante"
//UCMSB (MSB first select) = 0b -> LSB first
//UC7BIT (Character length) = 0b -> 8-bit data
//UCSPB (Stop bit select) = 0b -> One stop bit
//UCMODEx (USCI mode) = 00b -> UART Mode
//UCSYNC (Synchronous mode enable) = 0b -> Asynchronous mode
UCA0CTL0 = 0x00;
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//UCA0CTL1 -> Control Register 1
// 6-7 | 5 | 4 | 3 | 2 | 1 | 0 |
//---------------------------------------------------------
//UCSSELx |UCRXEIE|UCBRKIE|UCDORM|UCTXADDR|UCTXBRK|UCSWRST|
//---------------------------------------------------------
//UCSSELx (USCI clock source select)= 01b -> ACLK 10b -> SMCLK
//UCRXEIE (interrupt-enable) = 0b -> Erroneous characters rejected
//UCBRKIE (interrupt-enable) = 0b -> Received break characters set
//UCDORM (sleep mode) = 0b -> Not dormant
//UCTXADDR (Transmit address) = 0b -> Next frame transmitted is data
//UCTXBRK (Transmit break) = 0b -> Next frame transmitted is not a break
//UCSWRST (Software reset) = 1b -> normaly Set by a PUC
UCA0CTL1 = 0x81;
//------------------------------------------------------------------------
// BAUD RATE GENERATION
// Prescaler N = 1MHz/(9600) = 104.16
// UCA0BRx = INT(N/16) = 6
// UCBRFx = round( ( N/16 – INT(N/16) ) × 16 ) = 8
//------------------------------------------------------------------------
UCA0BR0 = 6;
UCA0BR1 = 0x00;
//UCAxMCTL Modulation Control Register
// 7-4 | 3-1 | 0 |
//UCBRFx|UCBRSx|UCOS16|
//UCBRFx (First modulation stage) = 1000b -> from table 19-4
//UCBRSx (Second modulation stage) = 000b -> from table 19-4
//UCOS16 (Oversampling mode) = 1b -> Enabled
UCA0MCTL = UCBRF_8 | UCOS16;

//------------------------------------------------------------------------
//2) END

//3) Clear UCSWRST via software -> BEGIN
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
//3) ->END

//4) Enable interrupts -> BEGIN
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
//4) -> END
}

Thank you in advance

Arturo


Viewing all articles
Browse latest Browse all 22203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>