Programming Energia (and Arduino)
MSP430 Workshop - Using Energia (Arduino) 8 - 9
How Does ‘Wiring’ Compare?
How does the ‘Wiring’ language compare to standard C code?
MSP430 C Code vs Wiring Language
Background
Loop
Setup
Code
void setup() {
// Setup pin for output
pinMode (LED_PIN, OUTPUT);
}
void loop() {
digitalWrite (LED_PIN, HIGH); // LED on
delay (1000); // wait 1 second
digitalWrite (LED_PIN, LOW); // LED off
delay (1000);
}
void main() {
// Setup pin for output
P1DIR = 0x40;
P1OUT = 0;
// Disable watchdog timer
WDTCTL = WDTPW | WDTHOLD;
// Setup Master Clock (MCLK)
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
BCSCTL2 &= ~(DIVS_0);
// Setup ACLK
BCSCTL3 |= LFXT1S_2;
while(1) {
P1OUT = 0x40; // LED on
_delay_cycles(1000); // wait 1 sec
P1OUT = 0; // LED off
_delay_cycles(1000);
}
}
This comparison helps to demonstrate the simplicity of programming with Energia. As stated
before, this can make for very effective rapid prototyping.
Later, during one of the lab exercises, we will examine some of the underpinings of Wiring.
Although the language makes programming easier, the same actual code is required for both
sides of this diagram. In the case of Wiring, this is encapsulated by the language/library. You will
see later on where this is done; armed with this knowledge, you can change the default values
defined by the folks who ported Arduino over to Energia for the TI microcontrollers.