some doubts in mspgcc

Status
Not open for further replies.
I found this MSP430 interrupt code example which might be of helpful when coding interrupts:

Code:
// 2010 Kenneth Finnegan
// http://kennethfinnegan.blogspot.com/
// Two color blink clock running on MSP430 controller

#include "msp430G2101.h"

#define BLINK_ON 3000
#define BLINK_OFF 1500
#define BLINK_SPACE 6000

volatile unsigned char time[4];
volatile unsigned char mode;

// FUNCTIONS
void displayNum (int c);
void displayTime(void);
void displayTwiddle(void);
void pause (int c);

void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer

BCSCTL3 = (BCSCTL3 & ~(XCAP0 | XCAP1)) | XCAP_1; // 6pF xtal
BCSCTL2 = 0xF8; // MCLK:LFXT1CLK/8 SMCLK:LFXT1CLK


P1DIR = 0x41;
P1OUT = 0x0F; // pull up resistors
P1REN = 0x0E; // pull up resistors enable
P1IE = 0x08; // Setup P1.3 for interrupt
P1IES = 0x08; // High -> Low transistion
P1IFG &= ~0x08; // Clear int flag

CCTL0 = CCIE;
CCR0 = 0;
TACCR0 = 0x7FFF; // Period of 32767 + 1
TACTL = 0x0211; // Timer_A: SMCLK, UP MODE, TAIE

while(1) {
mode = 0;
[COLOR="#FF0000"]_BIS_SR(LPM1_bits + GIE);[/COLOR]
switch (mode) {
case 0x06: // display time
displayTime();
break;
case 0x04: // display hours

if (time[3]) displayTwiddle();
pause(BLINK_SPACE);
displayNum(time[2]);
break;
case 0x02: // increment minutes
displayNum(time[1]);
break;
}
}
}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void) {
//P1OUT ^= 1;
time[0] = (time[0] + 1) % 60;
if (time[0] == 0) { // new minute
time[1] = (time[1] + 1) % 60;
if (time[1] == 0) { // new hour
time[2] = (time[2] + 1) % 12;
time[2] = time[2]?time[2]:12;
if (time[2] == 12) { // new AM/PM
time[3] = !time[3];
}
}
}
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void) {
mode = P1IN & 0x06;
LPM1_EXIT; // Wake up the main loop

switch (mode) { // Needs debounce!
case 0x04:
time[2] = (time[2] + 1) % 12;
time[2] = time[2]?time[2]:12;
if (time[2] == 12) { // new AM/PM
time[3] = !time[3];
}
break;
case 0x02:
time[1] = (time[1] + 1) % 60;
time[0] = 0;
break;
}

P1IFG = 0; // Clear int flag
}


void displayTime(void) {
if (time[3]) { // twiddle on PM
displayTwiddle();
}

pause(BLINK_SPACE);
displayNum(time[2]);

pause(BLINK_SPACE);
displayNum(time[1]);
}

void displayNum (int c) {
int i;
for (i=c/10; i; i--) {
P1OUT |= 0x40;
pause(BLINK_ON);
P1OUT &= ~0x40;
pause(BLINK_OFF);
}
if ((c%10) > 4) {
P1OUT |= 0x41;
pause(BLINK_ON);
P1OUT &= ~0x41;
pause(BLINK_OFF);
}
for (i=c%5; i; i--) {
P1OUT |= 0x1;
pause(BLINK_ON);
P1OUT &= ~0x1;
pause(BLINK_OFF);
}
P1OUT &= ~(0x41);
}

void displayTwiddle(void) {
int i;
for (i=0; i<2; i++) {
P1OUT |= 0x40;
P1OUT &= ~(0x01);
pause(BLINK_ON);
P1OUT |= 0x01;
P1OUT &= ~(0x40);
pause(BLINK_ON);
}
P1OUT &= ~(0x41);
}

void pause (int c) {
volatile unsigned int t = c;
do { t--;} while (t);
}

MSP430 Bicolor LED Clock

Hope the example helps with your interrupt implementation,

BigDog
 
Thanks @ srizbf & bigdogguru. The problem is solved....

(I am not marking the thread as solved because I would like to ask all MSPGCC related doubts in this thread)
 

below is an asm file obtained from an led.c file :

command used:
Code:
msp430-gcc -mmcu=msp430x2013 -S led.c

the led.s asm file below:
PHP:
	.file	"led2.c"
	.arch msp430f2013
	.cpu 430
	.mpy none

	[B].text
	.p2align 1,0
.global	fun2
	.type	fun2,@function[/B]
/***********************
 * Function `fun2' 
 ***********************/
fun2:
	push	r4
	mov	r1, r4
	add	#2, r4
	mov.b	#3, &__P1OUT
	pop	r4
	ret
[B].Lfe1:
	.size	fun2,.Lfe1-fun2
;; End of function 

	.p2align 1,0
.global	fun
	.type	fun,@function
[/B]/***********************
 * Function `fun' 
 ***********************/
fun:
	push	r4
	mov	r1, r4
	add	#2, r4
	mov.b	#2, &__P1OUT
	pop	r4
	ret
[B].Lfe2:
	.size	fun,.Lfe2-fun
;; End of function 

	.section	.init9,"ax",@progbits
	.p2align 1,0
.global	main
	.type	main,@function
[/B]/***********************
 * Function `main' 
 ***********************/
main:
	mov	r1, r4
	add	#2, r4
	mov	#23168, &__WDTCTL
	mov.b	#65, &__P1DIR
	mov.b	#1, &__P1OUT
	call	#fun
	call	#fun2
.L4:
	jmp	.L4
[B].Lfe3:
	.size	main,.Lfe3-main
;; End of function 
[/B]


I made few part in program in between [ B ] and [ /B ]..
What are those?
Is it the perfect asm file?

And I feel this led.s file little bit confusing...

So, how to write assembly file for mspgcc toolchain? (i doesn't mean asm in c, but exact asm (here i think led.s is the asm file)
 
Last edited:

The MSPGCC toolchain has an assembler included.

Assembling assembly language programs

Or the following is another open source MSP430 assembler:

MSP430 Assembler

Here is TI's appnote concerning assembly code development for the MSP430:

**broken link removed**

The code sections you have highlighted in the above listing specify the section of storage, the alignment and symbol using to identify the beginning of the code for following routine/function.

BigDog
 
for assembly only programs in msp430 ,

use nakens assembler.

mspgcc is not for the beginning in assembly.

one must know more details of mspgcc to output a pure assembly to hex .
 

I searched for "nakens assembler" in google but I couldn't find such thing...Could you pls provide a link?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…