MSP430 Intro. Why embedded systems? Big bang-for-the-buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more.

Slides:



Advertisements
Similar presentations
Table 7.1 Verilog Operators.
Advertisements

Chung-Ta King National Tsing Hua University
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Chapter 4 Gates and Circuits.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Railway Foundation Electronic, Electrical and Processor Engineering.
Railway Foundation Electronic, Electrical and Processor Engineering.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
Bitwise Operations CSE 2451 Rong Shi. Working with bits – int values Decimal (not a power of two – used for human readability) – No preceding label –
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
Development. Development Environment Editor Assembler or compiler Embedded emulator/debugger IAR Embedded Workbench Kickstart Code Composer Essentials.
C Summary Wilmer Arellano. References Excerpts from the book: Predko, Myke. (2005). 123 PIC MICROCONTROLLER EXPERIMENTS FOR THE EVIL GENIOUS. USA: McGraw-Hill.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
Chapter 4 Register Transfer and Micro -operations
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
Lecture 11: TI MSP430 Timers Compare Modes
Flow of Control Part 1: Selection
Lecturers: Professor John Devlin Mr Robert Ross
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
CSIS 113A Lecture 3 Conditional & Switch Glenn Stevenson CSIS 113A MSJC.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
1 Compound Assignment C++ has a large set of operators for applying an operation to an object and then storing the result back into the object Examples.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Introducing programming March 24. Program structure Statements to establish the start of the program Variable declaration Program statements (block statements)
COMPUTER ARCHITECTURE TRUTH TABLES AND LOGIC GATES.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
ECOM 4311—Digital System Design with VHDL
Operators & Expressions
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Review : C Programming Language
ECE DIGITAL LOGIC LECTURE 5: BINARY LOGIC AND DIGITAL LOGIC GATES Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/28/2016.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
CS4101 嵌入式系統概論 General Purpose IO
Data types Data types Basic types
Chapter 12 Variables and Operators
University of Central Florida COP 3330 Object Oriented Programming
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
University of Central Florida COP 3330 Object Oriented Programming
CS4101 嵌入式系統概論 General Purpose IO
Introduction to C Programming
Control Structures – Selection
Chapter 12 Variables and Operators
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C Programming
Associativity and Prescedence
Introduction to Programming – 4 Operators
C Programming Getting started Variables Basic C operators Conditionals
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Decision making and control functions
Presentation transcript:

MSP430 Intro

Why embedded systems? Big bang-for-the-buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power decreases.

Which Embedded System? We will use Texas Instruments MSP very popular (#2 next to microchip) + 16 bits (instead of 8) + low power + clean architecture + low cost (free) development tools - relatively low speed/capacity (i.e., no video or fancy audio) - low level tools (compared to Stamp, Arduino…) - 16 bits (instead of 32)

Today Brief overview of o logic o numbers o C o MSP430 digital I/O

Brief Review of Logic Logic circuits are either true (logical 1, for us this is 3.3V) or false (logical 0, for us this is 0V). To deal with these signal levels we develop a special form of mathematics, Boolean algebra.

Boolean Operators Operators: o AND : C=A·B (Read as C equals A and B). Input AInput BOutput C logic gate images adapted from: Sometimes the “·” is dropped: C=AB “Truth Table”

More logic… ABD AF ABH

… and even more. ABG ABJ eXclusive OR Note: XOR with B=1 inverts bit (J=~A), XOR with 0 passes bit (J=A).

Number Systems Binary: = 1· · · ·2 0 = = 13 Hex: = 2A 16 = 0x2A = 2· ·16 0 = = 42 (check 1· · ·2 1 = = 42) 8 bits = 1 byte → x00 → 0xff 0 → =255 ( or -128 → 127 ( -(2 7 ) → ) ) ) 16 bits = 2 bytes = 1 word → x0000 → 0xffff 0 → =65535 ( or → ( -(2 15 ) → ) ) ) 4 bits = 1 nybble(0 → =15) DecimalBinaryHex A B C D E F

Basic Architecture of MSP430 (from Family User’s Guide)

MSP430G2533 (from device specific datasheet)

MSP430FG2533, 20 pin DIP (from datasheet)

Digital I/O (Family User’s Guide )

Some register functions (Family User’s Guide)

A typical I/O pin PxSELx=0, by default PxREN=0, by default Analog switch Inverted input Electronically controlled digital switch 2-1 Mux (multiplexer) Tri-State Output Schmitt trigger (hysteresis) Active low Transparent latch 4-1 Mux (multiplexer)

Effect of P1DIR Hi-Z, Pin is input Input=q q P1IN.0=q 1 1 P1OUT.0=r Hi-Z r Output=r 0 Also – P1REN P1SEL, and P1SEL2 = 0 for I/O buffer enabled, pin is output 1 buffer enabled

#include void main(void) { volatile int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0x01; // Set P1.0 to output direction while (1) { //Do this forever P1OUT = P1OUT | 0x01; // Set P1.0 with “or”, | for (i=0; i<0x5000; i++) {}// Delay P1OUT = P1OUT & ~0x01;// Clear P1.0 for (i=0; i<0x5000; i++) {}// Delay } A simple C program Constants associated with our chip Every program needs a “main” routine (between braces) Don’t worry about for now. Set bit 0 in “P1DIR” - this makes it an output (next page). “1” is always true, so loop forever. Set bit 0 high (connected to LED) Loop to waste time Set bit 0 low (LED turns off) Loop to waste time Also note that every statement ends with “;” or “}” Comments start with “//” and go to end of line. Declare “i” as volatile so compiler doesn’t optimize it out of existence (or turn optimizations off). All variables must be declare before they are used.

Variant 1 (more readable) #include #define LED0x01 void main(void) { volatile int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= LED; // Set P1.0 (LED bit) to output while (1) { //Do this forever P1OUT |= LED; // Turn on LED for (i=0; i<0x5000; i++) {}// Delay P1OUT &= ~0x01;// Turn off LED for (i=0; i<0x5000; i++) {}// Delay } Give constants meaningful names. Equivalent to: P1OUT = P1OUT | LED;

Variant 2 (macros) #include #define LEDBIT0 #define SETBIT(p,b) (p |= (b)) #define CLRBIT(p,b) (p &= ~(b)) void main(void) { volatile int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= LED; // Set P1.0 to output direction while (1) { //Do this forever SETBIT(P1OUT,LED); // Set P1.0 for (i=0; i<0x5000; i++) {}// Delay CLRBIT(P1OUT,LED); // Clear P1.0 for (i=0; i<0x5000; i++) {}// Delay } } Use Macros sparingly, but they can make code look much cleaner (see below) Expands to: (P1OUT |= (0x01)) Note “;” must be added. Can call bits by location

Variant 3 (shorter) #include #define LED BIT0 #define SETBIT(p,b) (p |= (b)) #define CLRBIT(p,b) (p &= ~(b)) #define TGLBIT(p,b) (p ^= (b)) void main(void) { volatile int i; WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= LED; // Set P1.0 to output direction while (1) { //Do this forever TGLBIT(P1OUT,LED); // Toggle LED for (i=0; i<0x5000; i++) {}// Delay } New macro to toggle (xor) bit Loop is half as long as before

C Data Types (that we will use) TypeSize (bits) RepresentationMinimumMaximum char, signed char8ASCII unsigned char, bool8ASCII0255 int, signed int162s complement unsigned int16Binary long, signed long322s complement unsigned long32Binary enum162s complement float32IEEE 32-bit± e-38± e+38

C Operators (Arithmetic) Arithmetic Operator nameSyntax Basic assignmenta = b Additiona + b Subtractiona - b Unary plus+a+a Unary minus (additive inverse)-a-a Multiplicationa * b Divisiona / b Modulo (remainder)a % b Increment Prefix++a Suffixa++ Decrement Prefix--a Suffixa--

More C Operators (Relational, Logical, Bitwise and Compound) Relational Operator nameSyntax Equal toa ==b Not equal toa !=b Greater thana > b Less thana < b Greater than or equal toa >=b Less than or equal toa <=b Logical Operator nameSyntax Logical negation (NOT)!a!a Logical ANDa &&b Logical ORa ||b Bitwise Operator nameSyntax Bitwise NOT~a~a Bitwise ANDa & b Bitwise ORa | b Bitwise XORa ^ b Bitwise left shifta <<b Bitwise right shifta >>b Compound Operator nameSyntax Addition assignmenta += b Subtraction assignmenta -= b Multiplication assignmenta *= b Division assignmenta /= b Modulo assignmenta %= b Bitwise AND assignmenta &= b Bitwise OR assignmenta |= b Bitwise XOR assignmenta ^= b Bitwise left shift assignmenta <<=b Bitwise right shift assignmenta >>=b

More C Statements a simple statement is a single statement that ends in a “;” a compound statement is several statements inside braces: { simple statement; … simple statement; } Indenting There are no rules about indenting code, but if you don’t adopt a standard style, your code becomes unreadable.

Even more C Array definition int a [100]; //Array elements are a[0] to a[99]. Don’t use a[100]! if…then…else if ( ) else if…then if ( ) may be a compound statement. if…then…else (shorthand) x = (y > 2) ? 3 : 4; // if y>2, then x=3, else x=4.

Yet more C Iteration (do…while while… for…) do while ( ); while ( ) for ( ; ; ) for (e1; e2; e3) s; is equivalent to e1; while (e2) { s; e3; } The break statement is used to end a for loop, while loop, do loop, or switch statement. Control passes to the statement following the terminated statement. Recall: for (i=0; i<0x5000; i++) {}// Delay

Again with the C switch (one choice of many) switch ( ) { case : case : break; default : } is compared against the label, and execution of the associated statements occur (i.e., if is equal to, are exectuted. No two of the case constants may have the same value. There may be at most one default label. If none of the case labels are equal to the expression in the parentheses following switch, control passes to the default label, or if there is no default label, execution resumes just beyond the entire construct. Switch statements can "fall through", that is, when one case section has completed its execution, statements will continue to be executed downward until a break; statement is encountered. This is usually not wanted, so be careful

Material taken from: (Family User’s Guide; 658 pages) (Datasheet; 70 pages)