SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on how to get your MSP JTAG programmer up and running.
By atmoss
#63114
hello

i'm trying to develop a code for real time clock using crossworks, but i don`t understand so much how the assembly code "speak" with c code.

the function to export from assembly code is not being reconigzed by c code.

also i was testing several interrupt rutines...and i think its ok.

the code is:

#include <msp430x14x.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "MSP430lib.c"



extern void modus(int mod, int offset);

void InitTimer_A (void);
void InitOsc_TA (void);
void Clock (void);

int ii, jj;

unsigned int SEC;
unsigned int MIN;
unsigned int HR;
unsigned int DIA;
unsigned char LCDtime[32];

void main (void)
{
ii = 0;
SEC = 0;
MIN = 7;
HR = 12;
InitOsc_TA(); //
InitPorts(); // ports
InitTimer_A(); // Timer A
InitLCD(); // LCD
while (1)
{
LPM3; // enter low power mode 3
Clock(); // update clock
}
}


void InitTimer_A (void)
{
P1SEL = 0x80;
P1DIR |= BIT7; // enable Dallas output (P1.7)
/* Config. Timer_A*/
TACTL = ID1 | ID0 | TASSEL0 | TAIE; // use ACLK = 1 M / 8 = 125 kHz
TACCTL2 |= OUTMOD1 | OUTMOD0 | CCIS0; // output mode 3, por P1.7 (Dallas)
TACCTL2 &= ~CAP; // compare mode
TACCR0 = 0xF424; // 62500
TACCR2 = 0x7A12; // 31250
TACTL |= MC1 | MC0; // start timer in up/down-mode
_EINT();
}
void Clock (void)
{
SEC++;
if (SEC == 60)
{
SEC = 0;
MIN++;
if (MIN == 60)
{
MIN = 0;
HR++;
if (HR == 24)
{
HR = 0;
DIA++;
}
}
}

sprintf (LCDtime, "Hora Chile Cont: %d:%d:%d ", HR, MIN, SEC);
for (jj=0; jj != sizeof(LCDtime) - 1; jj++)
{
SEND_CHAR(LCDtime[jj]);
if (jj==15)
{
SEND_CMD (DD_RAM_ADDR2);
}
}
SEND_CMD (CUR_HOME);
}

void InitOsc_TA (void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
BCSCTL1 |= XTS; // XT1 as high-frequency
_BIC_SR(OSCOFF); // turn on XT1 oscillator
do // wait in loop until crystal is stable
IFG1 &= ~OFIFG;
while (IFG1 & OFIFG);
BCSCTL1 |= DIVA1 | DIVA0; // ACLK = XT1 / 8 = 1 MHz
IE1 &= ~WDTIE; // disable WDT int.
IFG1 &= ~WDTIFG; // clear WDT int. flag
WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS1;
// use WDT as timer, flag each. 512 pulses from ACLK
while (!(IFG1 & WDTIFG)); // count 1024 pulses from XT1 (until XT1's
// amplitude is OK)
IFG1 &= ~OFIFG; // clear osc. fault int. flag
DCOCTL |= DCO2 | DCO1 | DCO0;
BCSCTL1 |= RSEL2 | RSEL1 | RSEL0; // MCLK = DCO, 8 MHz
}

/*

//original
#pragma vector=TIMERA1_VECTOR
__interrupt void ClockHandler (void)
{
if (TAIV == 10) // check for timer overflow
{
modus(0x00,12); // exit low power mode 3
}
}
*/

/*
//managedment
void ClockHandler __interrupt [TIMERA1_VECTOR](void)
{
if (TAIV == 10) // check for timer overflow
{
modus(0x00,12); // exit low power mode 3
}
}

*/

//#if defined(__CROSSWORKS_MSP430)
/* This is the Rowley Crossworks compiler */
//#define ISR(a,b) void b __interrupt[a TIMERA1_VECTOR](void)

//#endif

//my own atventure...

void
ClockHandler(void) __interrupt [TIMERA1_VECTOR]
{
if (TAIV == 10)
{
modus(0x00,12);
}
}

assembly code:

NAME MODUS
RSEG CODE(1)
PUBLIC modus
RSEG CODE

modus:

PUSH R6 ; save R6
MOV.W SP,R6 ; load SP to R6
ADD.W R14,R6 ; add offset
MOV.W @R6,R14 ; load SR
BIC.W #0xF0,R14 ; clear modus bits
BIS.W R12,R14 ; set modus bits
MOV.W R14,0(R6) ; save SR to old location
POP R6 ; restore R6
RET
END

the "NAME" its not recognized by crossworks....(¿?)

and the problem is that "modus" is not exported correctly.

any help for this inexpert boy please

rewards
By gm
#63262
Why do you need to use assembler? If you need to exit low-power mode, just use

LPM3_EXIT;

HTH,

gm
By atmoss
#63408
thanks gm, now works , but it was more simple.....just i call the clock function at the interrupt... :o