• No results found

4.2.1 MicrocontrollersMicroprocessorsMicrocomputers.pptx

N/A
N/A
Protected

Academic year: 2020

Share "4.2.1 MicrocontrollersMicroprocessorsMicrocomputers.pptx"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)

Microcontrollers,

Microcomputers, and

(2)

2

A microcontroller is a small, low cost computer on a single

integrated circuit.

ATmega328 Microcontroller

• Processor • Memory

• Programmable Input/Output(I/O)

Microcontroller, Microcomputer, or Microprocessor?

What is the difference?

Arduino Uno Microcontroller Board

SparkFun Electronics, . Arduino Uno - R3. 2013. Photograph. Wikipedia Commons Web. 7 Jan 2014.

Microcontrollers are used to perform one dedicated task. One specific program.

(3)

A microcomputer is a small, relatively inexpensive computer with a microprocessor as its

central processing unit. It includes:

• a microprocessor • memory

• input/output (I/O) facilities

Microcontroller, Microcomputer, or Microprocessor?

What is the difference?

Commodore 64 Microcomputer

Evan-Amos, . Commodore-64-Computer. 2011. Photograph. Wikipedia Commons Web. 7 Jan 2014.

(4)

4

Why is it called a “micro” computer? Early computers such as

ENIAC filled entire rooms.

A “micro”computer by comparison with a keyboard, monitor, and

mouse are commonly referred to as a personal computer today.

The prefix “micro” is not commonly used in describing computers

anymore.

Microcontroller, Microcomputer, or Microprocessor?

What is the difference?

U.S. Army Photo, . ENIAC. 197. Photograph. Wikipedia Commons Web. 7 Jan 2014.

(5)

Microcontroller, Computer, or Processor?

What is the difference?

Application Processors

As the use of smart phones and mobile devices has

expanded, a new type of

processor has been defined.

Today, microprocessors in computers are often just referred to as processors. All computers today have a processor as the CPU.

Microprocessors designed for use in mobile applications are called application processors.

(6)

6

Microcontroller, Microcomputer, or Microprocessor?

What is the difference?

A microprocessor is an IC which has only the Central Processing Unit inside them. They only have processing powers. Microprocessors don’t have RAM, ROM, and other peripheral on the chip.

A system designer has to add them externally to make them functional. Once again, the prefix “micro” is

increasingly left today in favor of just processor.

(7)

What is a Microcontroller?

Microcontrollers are used to control many everyday products like garage door openers, traffic lights, home thermostats, and robots. Embedded controllers are everywhere.

(8)

What are the Parts of a

Microcontroller?

8

Microcontrollers contain:

• A Central Processing Unit (CPU)

• Some form of memory (MEMORY)

• Programmable Input / Output (I/O)

(9)

What are the Parts of the

Arduino Microcontroller Board?

The Arduino Microcontroller Board Specifications: • (14) Digital I/O Pins:

(6) are PWM Specific • (6) Analog I/O Pins

• Power: USB or external. If using power supply with 2.1mm center-positive plug, recommend range 7V-12V. • USB Connection: Type B • 5V or 3.3V option

Analog Digital / PWM

USB

Vext

(10)

Programming a Microcontroller

10

Programming languages have

their own grammar called syntax.

Programs written with the Ardiuno

software are called Sketches.

A Sketch

(program written with Arduino) will contain:

• Variables • Functions

• Setup() • Loop() • Structures • Comments

(11)

Programming a Microcontroller

• The Arduino software consists of an Integrated development environment (IDE) and the core libraries. • The core libraries are written

in C and C++ and compiled using avr-gcc and AVR Libc. • The Arduino software

language you program in is very similar to C++ because it is derived from C/C++.

(12)

Example: Blink

12

This sketch (program) will

continue to turn on LED on for 1 second and off for 1 second.

The sketch (program) includes :

setup() function - Initializes

variables, pin modes, start using libraries, etc.

loop() function - loops code consecutively.

(13)

Example: Blink

void - The void keyword is used

only in function declarations. It indicates that the function is

expected to return no information to the function from which it was called.

(14)

Example: Blink

14

Syntax: { } Curly Braces

(also referred to as just "braces" or as "curly brackets")

Curly Braces are a major part of the C programming language.

Balanced Braces - An opening curly brace "{" must always be followed by a closing curly brace "}".

(15)

Example: Blink

Curly Braces –

Beginning programmers, and programmers coming to C from the BASIC language often find using braces confusing or

daunting.

The same curly braces in C replace:

the RETURN statement in a subroutine (function), the ENDIF statement in a conditional and

(16)

Example: Blink

16

Syntax: The main uses of { } Curly Braces

Functions

void myfunction(datatype argument){ statements(s)

}

Loops

while (boolean expression) { statement(s) } do { statement(s)

} while (boolean expression);

for (initialisation; termination condition; incrementing expr)

{

statement(s) }

Conditional statements

if (boolean expression) {

statement(s) }

else if (boolean expression) { statement(s) } else { statement(s) }

(17)

Example: Blink

/* Blink

Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain.

*/

// Pin 13 has an LED connected on most Arduino boards. // give the variable “integer” the name “led”:

intled = 13;

// the setup routine runs once to declare function when you press reset:

void setup() {

// initialize the digital pin “pinMode” you defined as “led” as an output.

pinMode(led, OUTPUT); }

// the void loop routine runs over and over again forever:

void loop() {

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

(18)

Example: Blink

18

/* Blink

Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain.

*/

// Pin 13 has an LED connected on most Arduino boards. // give the variable “integer” the name “led”:

intled = 13;

A variable is a place for storing a piece of data. It has a type, a name, and a value.

For example, the Blink sketch declares a variable with:

(19)

Example: Blink

Variable Data Types Include: void

boolean char

unsigned char byte

int

unsigned int word

unsigned long short

float double

string - char array String - object

Array long

(20)

Example: Blink

20

/* Blink

Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain.

*/

// Pin 13 has an LED connected on most Arduino boards. // give the variable “integer” the name “led”:

intled = 13;

// the setup routine runs once to declare function when you press reset:

void setup() {

// initialize the digital pin “pinMode” you defined as “led” as an output.

pinMode(led, OUTPUT); }

A function (also known as a sub-routine) is a named piece of code that can be used from elsewhere in the code.

The setup() function in this example sets the variable

(21)

Example: Blink

// the void loop routine runs over and over again forever:

void loop() {

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)

delay(1000); // wait for a second

digitalWrite(led, LOW); // turn the LED off by making the voltage LOW

delay(1000); // wait for a second

}

The loop() function loops consecutively, allowing your

program to change and respond.

Use it to actively control the Arduino board.

/* Blink

Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain.

*/

(22)

Your Turn

22

Open Source Community

Arduino Software is free. You can install it at home if you

would like to continue work on your DE projects and/or create new projects of your own.

For the newest version of Aurdino IDE visit their website. In the next activities, you will program a microcontroller to

integrate new types of sensors and input devices.

Memsic 2125

Dual-axis Accelerometer 2-Axis Joystick

PIR Sensor

References

Related documents

These variables include the value of the content ratio, the reduction in external tariffs stemming from the FTA formation, the differences in costs between using a regional input

There’s no doubt the iPad is a great device for personal entertainment uses, such as web browsing, email, music, games, movie watching, etc., but there are some

Recent high-profile performance and security failures are bringing renewed focus to the importance of sufficient testing to ensure content-aware network devices can perform

banca actuó como comisionado de la Compañía General Española por la provincia de Pontevedra e intervino muy activamente en la puesta en marcha de numerosos proyectos

The government co ll ect s revenue f rom taxes on capital and labour income and value-added taxes on fina l demand , production taxes on intermediate inputs, and...

memorize law, you will be expected to become familiar with legal principles, and be able to access and apply laws and processes to social service situations with an emphasis

Bar plots showing LiDAR April/May measurement ratios (with 95% confidence intervals) for four 5 m grid-cell statistics: maximum, mean, standard deviation and skewness.

Comments This can be a real eye-opener to learn what team members believe are requirements to succeed on your team. Teams often incorporate things into their “perfect team