0% found this document useful (0 votes)
41 views18 pages

2024microprocessor BE3EC Lecture No.6

Uploaded by

SO Woon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views18 pages

2024microprocessor BE3EC Lecture No.6

Uploaded by

SO Woon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Chapter 6 Microcontrollers

Microcontroller
All the essential elements of a computer on a single chip
MPU, R/W memory, ROM, and I/O interfacing devices.

Examples: Intel MCS-51, Motorola MC68HC51, Microchip PIC series, Arduino series

6.1 Intel MCS-51 (8051) Single-Chip Family


Made by Intel in 1980

 40 pins
 Clock frequency 12 MHz of MPU
 128 bytes of data memory (RAM) plus 21 special-function registers
 4096 bytes of program memory (EPROM/ROM) for OS
 four programmable I/O ports (32 lines)
 two 16-bit timer/event counters
 a serial I/O port with a UART (Universal Asynchronous Receiver/Transmitter)
 five interrupt lines: two for external signals and three for internal operations

Frequency
Reference Counters

Oscillator 4096 Bytes 128 Bytes Two 16-bit Timer/Event


Program Memory
& Timing Data Memory Counters
(8051 & 8751)

8051 CPU

64K-Bytes  Programmable Serial Port


Programmable
Interrupts Bus Expansion  Full Duplex UART
I/O
Control  Synchronous Shifter

Interrupts Control Parallel Ports, Serial IN Serial OUT


Address Data Bus,
and I/O Pins

Fig. 6-1 Block Diagram: The 8051

-1-
6.2 Motorola MC68HC11 Microcontroller Family
Made by Motorola in 1984

 48 pins
 Used in industrial applications
 Clock frequency 2 MHz of MPU
 8K bytes of ROM and 512 bytes of EEPROM
 256 bytes of RAM (R/W memory)
 40 I/O pins with multiple functions
 Eight-channel, 8-bit AD converter
 16-bit timer system
 8-bit pulse accumulator system
 Serial communication and serial peripheral interface
 Computer operating properly (COP) watchdog system (Error → RESET)

6.3 Renesas RH850 Family


Started by Renesas in 2012

 48,64,80,100,144,176 pins
 Used in automobile
 Clock frequency 80 MHz of CPU G3
 32K bytes of ROM and 256K − 2M bytes of EEPROM
 Maximum sixty-channel, 8-bit AD converter
 Maximum two channel, computer operating properly (COP) watchdog system

6.4 Microchip PIC (Peripheral Interface Controller) Family


Started by Microchip in 1985

 6 pins − 144 pins


 Used in education and hobby
 Instructions and data on separate busses
 Three kinds of data bits
8-bit : 4−32 MHz
16-bit : 7.37 − 16 MHz
32-bit : 40, 80 MHz

-2-
Software Development Environment
MPLAB X IDE (Integrated Development Environment)
 Assembly language
 C language (MPLAB XC?? Compiler, CCS C-Compiler)

PIC16F84A
 8 bit series
 35 instructions (instruction width 14 bits, data width 8 bits)
 Maximum operating clock 20 MHz
 Program memory of size 1024 words = 1796 bytes (OS)
 Data ROM of 68 bytes
 Data EEPROM of 64 bytes
 13 I/O pins (PORTA 5 bits, PORTB 8 bits)
 8 bit timer counter module

RA2 ·1 18 RA1
RA3 2 17 RA0
RA4/T0CKI 3 16 OSC1/CLKIN
PIC16F84A-20/P

തതതതതതതത
MCLR 4 15 OSC2/CLKOUT
VSS 5 14 VDD
RB0/INT 6 13 RB7
RB1 7 12 RB6
RB2 8 11 RB5
RB3 9 10 RB4

Fig. 6-2 PIC16F84 Pinout and Signals

6.5 Arduino Family


Started in 2005

 An open-source prototyping board based on easy-to-use hardware and software


 An Atmel 8-, 16-, or 32-bit AVR microcontroller with complementary components that
facilitate programming and incorporation into other circuits
 Used in education and hobby
 Arduino UNO, Arduino Duemilanove, Arduino Leonardo, Arduino MEGA,
Arduino Nano

-3-
Arduino UNO R3
DC Power Supply through Power Jack
• must be a DC adapter.
• should be between 9V and 12V DC.
• must be rated for a minimum of 250mA current output.
• must have a 2.1mm power plug on the Arduino end.
• The plug must be "centre positive".

B-type USB Connector


A-B type USB 2.0 cable

Reset Button
By pushing the reset button, a sketch (user program) restarts from the beginning.

ICSP (In-Circuit Serial Programming) Header


By the use of the ICSP header, it is possible to burn the bootloader and a sketch.
Pin configuration is as follows.

Fig. 6-3 ICSP Header Pin Configuration of Arduino

Crystal Oscillator
• 16 MHz
• The crystal oscillator acts as the ridiculously fast metronome for ATmega328P.

Voltage Regulator
5V power supply constantly

Resettable Fuse
It protects the USB port from shorts and overcurrent.

USB-to-Serial Adapter Chip FTDI FT232RL


A USB to serial UART interface

-4-
Fig. 6-4 Components of Arduino UNO R3

Software Development Environment


Arduino IDE (Integrated Development Environment)
• Open-source software
• makes it easy to write code and upload it to the Arduino board.
• runs on Windows, Mac OS X, and Linux.
• can be downloaded from https://www.arduino.cc/en/main/software.

Functions of the software


• Open, Save, Close, Edit a program named ‘sketch’.
• Verify / Compile a sketch.
• Upload (Write) a sketch to Arduino.
• Open the serial monitor window and initiates the exchange of data with any
connected Arduino board on the currently selected Port.
• Include libraries.
• Export compiled binary.
• Archive a copy of the current sketch in .zip format.

-5-
6.6.1 Blinking Built-In LED
Simple programming on Arduino
The L LED mounted on the Arduino board is used to confirm action of a program. See Fig. 6-5.

Fig. 6-5 Built-In LED

The following sketch turns on/off the L LED at 500-millisecond intervals.


(Blinking_Built_In_LED)

//***************************************************************//
// Name : Blinking Built-In LED //
// Author : Kazuhiro Muramatsu //
// Date : 9 December 2020 //
// Version : 1.0 //
// Notes : Code on Blinking Built-In LED 13 //
//***************************************************************//

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}

-6-
Be careful to distinguish between upper- and lowercase letters. pinMode should be typed as
pinMode exactly. PinMode or Pinmode is wrong. The meaning of setup, pinMode, digitalWrite,
and delay are explained after.

setup()
Is called once when the sketch starts.
Setup tasks like setting pin modes or initializing libraries.
The code between the { and } = The body of the setup function
Returns no value The type of the functions is void.

void setup()
{
setup code here, to run once
}

pinMode(pin, mode)
Configures the specified pin to behave either as an input or an output.
Parameters: pin; the number of the pin whose mode you wish to set
mode; INPUT, OUTPUT, or INPUT_PULLUP

pinMode(13, OUTPUT);

configures pin 13 to an output.

loop()
Is called over and over and is heart of most sketches.
Loops consecutively
The code between the { and } = The body of the loop function
Returns no value The type of the functions is void.

void loop()
{
main code here, to run repeatedly
}

digitalWrite(pin, value)
Writes a HIGH or a LOW value to a digital pin.
Parameters: pin; the pin number
value: HIGH or LOW

-7-
digitalWrite(13, HIGH);

sets pin 13 to HIGH.

delay(ms)
Pauses the program for the amount of time (in milliseconds).
Parameters: ms; the number of milliseconds to pause (unsigned long)

delay(500);

pauses for 500 milliseconds.

digitalWrite(13, LOW);

Output of digital pin 13 is set to HIGH. The L LED is turned on.

digitalWrite(13, LOW);

Output of digital pin 13 is set to LOW. The L LED is turned off.

The L LED is turned on/off at 500-millisecond intervals as follows.

ON OFF ON OFF
500 millisec. 500 millisec. 500 millisec. 500 millisec.

Repeat

Fig. 6-6 Flow of Built-In LED Blinking

6.6.2 #define Directive


The function of the following sketch is same as Blinking_Built_In_LED.
However, #define Directive is used. (Blinking_Built_In_LED2)

//***************************************************************//
// Name : Blinking Built-In LED //
// Author : Kazuhiro Muramatsu //
// Date : 9 December 2020 //
// Version : 1.0 //

-8-
// Notes : Code on Blinking Built-In LED 13 //
// : #define is used //
//***************************************************************//

#define LED_PIN 13
void setup() {
pinMode(LED_PIN, OUTPUT);
}

void loop() {
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
}

#define CONSTANTNAME value


Gives a name to a constant value before the program is compiled.

#define LED_PIN 13

Any mention of LED_PIN is replaced with the value 13 at compile time.

The pin connected to LED is changed.

Only the value in #define statement will be modified.

6.6.3 Serial Monitor


Serial Monitor
A separate pop-up window that acts as a separate terminal that communicates by USART

Use of Serial Monitor

Don’t use Pins 0 and 1 for I/O devices

The following sketch is control of the L LED on/off by serial monitor. (Use_Serial_Monitor)

-9-
//***************************************************************//
// Name : Using Serial Monitor //
// Author : Kazuhiro Muramatsu //
// Date : 9 December 2020 //
// Version : 1.0 //
// Notes : Code for using the serial monitor //
//***************************************************************//

#define LED_PIN 13

void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}

void loop() {
int inputchar;
inputchar = Serial.read();

if(inputchar != -1) {
switch(inputchar) {
case 'o':
Serial.print("LED ON¥n");
digitalWrite(LED_PIN, HIGH);
break;
case 'p':
Serial.print("LED OFF¥n");
digitalWrite(LED_PIN, LOW);
break;
}
}
}

Serial.begin(speed[, config])
Opens serial port with the specific data rate in bits per second (baud).
Parameters: speed; in bits per second (baud), one of these rates: 300, 600, 1200, 2400, 4800,
9600, 14400, 19200, 28800, 38400, 57600, or 115200 (long int)
config; the data, parity, and stop bits are configured. [optional]

- 10 -
Serial.begin(9600);

opens USART with 9600 baud.

Serial.read()
Reads incoming serial data.
Return: the first byte of incoming serial data available (or -1 if no data is available)

inputchar = Serial.read();

reads the incoming byte and places it in inputchar.

Serial.print(val[, format])
Prints the val to the serial port as ASCII text.
Parameters: val; the value to print (any data type)
format; specifies the base (format) to use [optional]
BIN: binary or base 2
OCT: octal or base 8
DEC: decimal or base 10 (default)
HEX: hexadecimal or base 16
For floating point numbers, this parameter specifies the number of
decimal places to use.

Serial.print("LED ON¥n");

prints “LED_ON” and a newline

- 11 -
6.6 Architecture of ATmega328P Microcontroller
6.6.1 Pin Configuration of ATmega328P
The pin out diagram for ATmega328P

Fig. 6-7 Pin-out Diagram of ATmega328P


Pin Descriptions
VCC
Digital supply voltage
GND
Ground
Port B (PB[7:0])
An 8-bit bi-directional I/O port
Port C (PC[6:0])
An 7-bit bi-directional I/O port
Port D (PD[7:0])
An 8-bit bi-directional I/O port
XTAL1
Oscillator crystal input
XTAL2
Oscillator crystal output
തതതതതതതതത
RESET
A reset input

ADC[5:0]
Analog inputs to the 10-bit A/D converter

- 12 -
AVCC
The supply voltage for the A/D Converter

AREF
The analog reference for the A/D Converter
SCL
I2C / TWI (Two-Wire Interface) Serial Bus Clock Line
SDA
I2C / TWI (Two-Wire Interface) Serial Bus Data Input/Output Line
SCK
SPI (Serial Peripheral Interface) Bus Master clock Input
MISO
SPI (Serial Peripheral Interface) Bus Master Input/Slave Output
MOSI
SPI (Serial Peripheral Interface) Bus Master Output/Slave Input
തതത
SS
SPI (Serial Peripheral Interface) Bus Master Slave select
RXD
USART (Universal Synchronous Asynchronous Receiver/Transmitter) Input Pin
TXD
USART (Universal Synchronous Asynchronous Receiver/Transmitter) Output Pin
INT0
External Interrupt Request 0
INT1
External Interrupt Request 1

Block Diagram for ATmega328P

- 13 -
Fig. 6-8 Block Diagram of ATmega328P

6.6.2 Memory on ATmega328P


Three main memory sections
• Flash Electrically Erasable Programmable Read Only Memory (EEPROM)
• Byte-addressable EEPROM
• Static Random Access Memory (SRAM)

In-System Programmable Flash EEPROM


is used to store programs and bootloader.
Nonvolatile, size 32k bytes (of which 0.5k bytes are used for the bootloader)
Byte-addressable EEPROM
is used to permanently store and recall variables during program execution.
Nonvolatile, size 1k bytes
SRAM
is used to temporarily store and recall variables during program execution.
Volatile, size 2k bytes

- 14 -
6.6.3 Port System of ATmega328P
Three ports: PORTB (8-bit), PORTC (7-bit), and PORTD (8-bit)
All of these ports also have alternate functions.
Each port has three registers associated with it.
• 8-bit Data Register PORTx —- used to write output data to the port.
• 8-bit Data Direction Register DDRx —- used to set a specific port pin to either output (1)
or input (0).
• 8-bit Input Pin Address PINx —- used to read input data from the port.

6.6.4 Internal Systems


A brief overview of the internal features of the ATmega328P

(a) Time Base


The maximum frequency of the ATmega328P is 20 MHz.
The speed at which a microcontroller sequences through a predictable fetch-decode-execute
sequence

A precise time base called the clock

An external clock (16 MHz quartz crystal)


[But an internal clock 1, 2, 4 or 8 MHz]

(b) Timing Subsystem


A complement of timers which allows the user to generate a precision output signal

Two 8-bit timer/counters and one 16-bit counter

(c) Pulse Width Modulation (PWM) Channels


Pulse Width Modulation (PWM)
is a technique for getting analog results with digital mean.

A fixed frequency (500 Hz) and a varying duty cycle


𝑑𝑢𝑡𝑦 𝑐𝑦𝑐𝑙𝑒 [%] = (𝑜𝑛 𝑡𝑖𝑚𝑒⁄𝑝𝑒𝑟𝑖𝑜𝑑 ) × (100%)

- 15 -
2 ms

Fig. 6-9 Pulse Width Modulation

(d) Serial Communications


A host of different serial communication subsystems
• Universal Synchronous and Asynchronous Serial Receiver and Transmitter (USART)
RXD, TXD pins
• Serial Peripheral Interface (SPI)
SCK, MISO, MOSI, SS pins
• I2C Interface
SCL, SDA pins

Serial USART
is used for full duplex (two way) communication between a receiver and transmitter.
Example: Arduino and PC

Serial Peripheral Interface—SPI


can also be used for two-way serial communication between a transmitter and a receiver.
Example: Arduino and another microcontroller
I2C Interface
allows the system designer to network a number of related devices together into a system
using a two wire interconnecting scheme.

- 16 -
Example: Arduino and plural I/O devices

Fig. 6-10 I2C Connection

Fig. 6-11 Connecting Multiple LCDs on an I2C Bus

(e) Analog to Digital Converter—ADC


A six channel analogue to digital converter (ADC) subsystem
10-bit resolution
Default: an analogue voltage between 0 and 5 V

one of 1024 binary representations between (000)16 and (3FF)16


a voltage resolution of approximately 4.88 mV
AREF: an analogue voltage between 0 and AREF (< 5V)

one of 1024 binary representations between (000)16 and (3FF)16

(f) Interrupts
Interrupts
allow certain important tasks to happen in the background and are enabled by default.

- 17 -
jump program sequence to an interrupt routine.

A complement of 26 interrupt sources


PCINT[23:0] 24 Internal interrupts
INT0, INT1 2 External interrupts

INT0 and INT1 can be set to trigger on RISING or FALLING signal edges, or on low level.

- 18 -

You might also like