This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: Programmable Microcontrollers with Applications, p.115 | |
// Turning on the red LED when the push button is pressed | |
// MSP430 LaunchPad Rev.1.5 | |
#include <msp430g2553.h> | |
#define LED BIT0 // P1.0 | |
#define BUTTON BIT3 // P1.3 | |
void main(void){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Model for uA741 Op Amp (from EVAL library in PSpice) | |
* connections: non-inverting input | |
* | inverting input | |
* | | positive power supply | |
* | | | negative power supply | |
* | | | | output | |
* | | | | | | |
* | |
.subckt uA741 1 2 3 4 5 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: Programmable Microcontrollers with Applications, p.117 | |
// Toggling the green LED when the push button is pressed | |
// MSP430 LaunchPad Rev.1.5 | |
#include <msp430g2553.h> | |
#define LED BIT6 //P1.6 LED2 | |
#define BUTTON BIT3 //P1.3 S2 | |
void delay_ms(int); // declare function delay_ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a PWM signal is created with the TimerA0 where CCR0 is the periode 20ms and CCR1 the duty cycle | |
// the PWM signal is output through pin P1.6 that correspond to TA0.1 (see MSP430G2553 uC datasheet) | |
// this code does not generate interruptions but uses the reset/set mode to generate the PWM signal when the timer counts up to CCR1 | |
// in this case a duty cycle of 2ms (CCR1 = 2000 - 1) will rotate the axis clockwise (see sg90 datasheet) | |
// a duty cycle of 1.0ms (CCR1 = 1000 - 1) will rotate the axis anticlockwise | |
// a duty cycle of 1.5ms (CCR1 = 1500 - 1) will rotate the axis to the center position | |
// the servo used was a sg90 but I guess the code will work with any servo (refer to the servo's datasheet to confirm this) | |
#include <msp430g2553.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test external crystal by observing ACLK frequency on ACLK pin | |
// ACLK correspond to pin P1.0 in MSP430G2553 (see MSP430G2553 datasheet) | |
// an external crystal connects to the XIN, XOUT pins | |
// XIN and XOUT correspond to pins P2.6 and P2.7 respectively in MSP430G2553 (see MSP430G2553 datasheet) | |
// P1SEL = BIT0 and P1DIR = BIT0 show ACLK in P1.0 (see MSP430G2553 datasheet, pin functions) | |
// this only works with small crystals in cylindrical package | |
// stand-alone uC test: | |
// DVCC to 3.3V | |
// DVSS to GND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source current to a LED through digital pin 7 | |
// connection: pin7 set to high - LED's anode .. LED's cathode - 1k resistor - GND | |
// LED's anode (+) long terminal | |
// LED's cathode (-) short terminal | |
// 1k resistor color code: brown black red | |
// code executed on Arduino Leonardo | |
void setup(){ | |
pinMode(7, OUTPUT); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sink current through a LED to digital pin 7 | |
// connection: VCC - LED's anode .. LED's cathode - 1k resistor - pin7 set to low | |
// VCC is 5V | |
// LED's anode (+) long terminal | |
// LED's cathode (-) short terminal | |
// 1k resistor color code: brown black red | |
// code executed on Arduino Leonardo | |
void setup(){ | |
pinMode(7, OUTPUT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup(){ | |
pinMode(7, OUTPUT); | |
} | |
void loop(){ | |
digitalWrite(7, HIGH); | |
delay(500); | |
digitalWrite(7, LOW); | |
delay(500); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// turn LED ON and OFF using switch | |
// we read the state of the switch through pin 7 | |
// switch is connected between pin 7 and GND | |
// we use the microcontroller's internal 20k pullup resistor | |
// why do we use a pullup resistor? read here: https://learn.sparkfun.com/tutorials/pull-up-resistors | |
// you can choose between LED ON or LED OFF when switch is pressed | |
// pin 8 will source current to the LED | |
// refer to source_current.ino file to see how to connect the LED | |
// code executed on Arduino Leonardo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PWM signal through pin 3 | |
// 8 bits PWM: 0 (0% or GND) to 255 (100% or VCC) | |
// what's a PWM signal? read here: https://en.wikipedia.org/wiki/Pulse-width_modulation | |
// pin 3 will source current to the LED | |
// refer to source_current.ino file to see how to connect the LED | |
// code executed on Arduino Leonardo | |
void setup(){ | |
pinMode(3, OUTPUT); // observe that only pins preceded by ~ in the board can output a PWM signal | |
} |
OlderNewer