مسيطرات كامل
مسيطرات كامل
مسيطرات كامل
Arduino UNO
Raspberry PI 3
The Difference between µC and µP
• µC (microcontroller):
o RAM
o ROM
o I/O ports
o Timer
o ADC and other peripherals
o No. of bits (8-32) bits
o Low cost
• µP (microprocessor):
o No RAM
o No ROM
o No I/O ports
o No. Of bits (32-64) bits
o High cost
Types of Microcontrollers:
o Microcontrollers can be classified on the basis of internal bus width,
architecture, memory, and instruction set.
o When the ALU performs arithmetic and logical operations on a byte (8- bits)
at an instruction, the microcontroller is an 8-bit microcontroller. The internal
bus width of the 8-bit microcontroller is 8-bit. Examples of 8-bit
microcontrollers are Intel 8051 family and Motorola MC68HC11 family.
o When the ALU performs arithmetic and logical operations on a word (16-
bits) at an instruction, the microcontroller is a 16-bit microcontroller. The
internal bus width of the 16-bit microcontroller is 16-bit. Examples of 16-bit
microcontrollers are Intel 8096 family and Motorola MC68HC12 and
MC68332 families.
o The performance and computing capability of 16-bit microcontrollers are
enhanced with greater precision as compared to the 8-bit microcontrollers.
Types of Microcontrollers:
• When the ALU performs arithmetic and logical operations on a
double word (32- bits) at an instruction, the microcontroller is a
32-bit microcontroller. The internal bus width of the 32-bit
microcontroller is 32-bit. Examples of 32-bit microcontrollers are
Intel 80960 family and Motorola M683xx and Intel/Atmel 251
family.
This is a unit that monitors and controls all processes within the microcontroller and the user cannot
affect its work.
• The size of the program that can be written depends on the size of this memory.
• ROM can be built in the microcontroller or added as the external chip, which depends on the
type of the microcontroller.
• Today’s microcontrollers commonly use 16-bit addressing, which means that they are able to
address up to 64 Kb of memory, i.e. 65535 locations. As a novice, your program will rarely
exceed the limit of several hundred instructions.
6
3. Random Access Memory (RAM)
Random Access Memory (RAM) is a type of memory used for temporary storing data and
intermediate results created and used during the operation of the microcontrollers.
The content of this memory is cleared once the power supply is off.
EEPROM (Electric Erasable Programmable ROM) Data Memory: EEPROM-type data memory is
also very common in many microcontrollers.
The advantage of an EEPROM memory is that the programmer can store nonvolatile data there
and change this data whenever required. For example, in a temperature monitoring application, the
maximum and minimum temperature readings can be stored in EEPROM memory. If the power
supply is removed for any reason, the values of the latest readings are available in the EEPROM
memory.
4. Registers & Special Function Registers (SFR)
• Counters: If the timer receives pulses from the microcontroller input pin, then it
turns into a counter. Obviously, it is the same electronic circuit able to operate in two
different modes. The only difference is that in this case pulses to be counted come
over the microcontroller input pin and their duration (width) is mostly undefined.
8. A/D Converter
• This module is used for input pin voltage measurement (analog value). The
result of the measurement is a number (digital value) used and processed later
in the program.
• Brown Out
• It is a potentially dangerous state which occurs when the
microcontroller is being turned off or when the power supply
voltage drops to the lowest level due to electric noise.
• Reset Pin
• Master Clear Reset (MCLR) serves for the external reset of the
microcontroller. Reset puts the microcontroller into a known
state. Usually, after a reset, the program starting from memory
address 0 of the microcontroller is executed
10. Oscillator
• An electronic circuit that produces a periodic oscillating electronic signal often a sine
wave or square wave.
• We use capacitors with the oscillators to reduce noises and we chose the values of the
capacitors depending on the oscillator frequency and type.
• There are four steps taken by the CPU to do an instruction:
• One of the factors that control the speed of the microcontroller is the frequency
• of the oscillator.
• 1. Fetch
• 2. Decode
• 3. Execute
• 4. Transfer
• Thanks for listening
• Good Luck
جمهورية العراق
وزارة التعليم العالي والبحث العلمي
جامعة االمام جعفر الصادق (عليه السالم) – كركوك
كلية تكنلوجيا المعلومات – قسم هندسة تقنيات الحاسوب
Digital Controller
Lecture 3 - C Programming Language
م.م سماره خميس
• Programming is writing the instruction that the Microprocessor will
do.
• At first programs were written in Machine Code (0, 1).
• Then Assembly Language was invented as the hardware became
complex and we needed to make an easier language.
• Then the higher level languages were invented, They are much
easier than assembly Language (C, Java, Python).
1 /* Fig. 2.1: fig02_01.c
2 A first program in C */
3 #include <stdio.h>
4
5 int main()
6 {
7 printf( "Welcome to C!\n" );
8
9 return 0;
10 }
Welcome to C!
We use Variables and constants to store the data of the program
and deal with them like doing mathematical operations or
displaying their values.
Variables are stored in RAM so we can change their values during
the program.
Constants are stored in ROM so we can't change their values during
the program.
• To declare a variable we need to describe the following:
1. Variable Type.
2. Variable name.
3. Value of the Variable (not a must).
And we write the declaration statement like this:
Bitwise operators
جمهورية العراق
وزارة التعليم العالي والبحث العلمي
جامعة االمام جعفر الصادق (عليه السالم) – كركوك
كلية تكنلوجيا المعلومات – قسم هندسة تقنيات الحاسوب
Digital controllers
Lecture -4-
) ) Arduino
م.م سماره خميس
What is a Microcontroller (µC, MCU)
Computer on a single integrated chip
Processor (CPU)
Memory (RAM / ROM / Flash)
I/O ports (USB, I2C, SPI, ADC)
Common microcontroller families:
– Intel: 4004, 8008, etc.
Atmel: AT and AVR
Microchip: PIC
ARM: (multiple manufacturers)
Used in:
Cellphones,
Toys
Household appliances
Cars
Cameras
What is Arduino Not?
It is not a chip (IC)
It is not a board (PCB)
It is not a company or a manufacturer
It is not a programming language
It is not a computer architecture
AC/DC adapter
jack DC voltage
6 analog
supply
inputs
(IN/OUT)
Arduino Sketch Structure
◦ Will be executed }
void loop{ )(
only when the //put your main code here, to run repeatedly:
program begins }
void setup() {
pinMode(11, OUTPUT); //Use pin 11 for digital out
pinMode(12, INPUT); //Use pin 12 for digital input
digitalWrite(12, HIGH); //Enable pull‐up resistor
}
void loop() {
boolean state;
state =digitalRead(12); // read state of pin 12
digitalWrite(11, state); // set state of pin 11 (LED)
delay(;)100 // wait for a 1/10 second
}
Digital controllers
Lecture -5-
)(7-Segment Display
م.م سماره خميس
Outlines:-
1. 7-segment Display Introduction
2. 7-Segment Display Features
3. Selecting your 7-Segment Display
4. Seven-Segment Display Table
5. How to use a 7-Segment display
6. 7-Segment Display Pin Configuration
7. Applications
7-segment Display Introduction
The seven segments displays are the oldest yet one of the efficient types of display used in
embedded applications. This display has nothing more than 8 LEDs inside it. These 8 LEDs
are separated into each segment which can be named as a,b,c,d,e,f,g, DP as shown in the
picture.
These entire 8 segment LEDs have one end of their pins pulled out of the module as
shown above and the other ends are connected together and pulled out as the Common
pin.
So to make an LED of a particular segment glow we just have to power the common pin
along with the segment pin. This way we can power more than one segment at a time to
represent the numeric number 0-9
7-Segment Display Features
Available in two modes Common Cathode (CC) and Common Anode (CA)
Available in many different sizes like 9.14mm, 14.20mm, 20.40mm, 38.10mm,
57.0mm and 100mm (Commonly used/available size is 14.20mm)
Available colors: White, Blue, Red,Yellow and Green (Res is commonly used)
Low current operation
Better, brighter, and a larger display than conventional LCD displays.
Current consumption : 30mA / segment
Peak current: 70mA
Selecting your 7-Segment Display
As discussed in the Features there are many options to
choose from for a 7-segment display. Their many
different types of size and colors to select from. The
default and most commonly used / available one is the
14.20mm with Red color display as shown in the above
animation. If you are planning to make your project
look out of the box, then other color displays can also
be used. Also, note that as size and color differ the
amount of current consumed by the display will also
differ. The Red color one is universally used since it
consumes less current than other colors.
Now, there is another important parameter that you have to
concentrate on before buying this module. That is either a
Common Anode display or a Common Cathode display. We cannot
use a circuit/program designed for Common Anode display for
Common Cathode or vice versa
Seven-Segment Display Table
How to use a 7-Segment display
One important advantage of a 7-segment display is that it is very easy to use. Unlike other display
modules, a 7-segment display can be made to work even without a Microcontroller or a Microprocessor.
This is possible because of the readily available 7-segment counter IC’s like IC CD4026. This IC can be
used in combination with the display for projects which have very simple circuits. The IC can drive one
7-segment display module and the number that is being displayed can also be incremented or
decremented.
But, most commonly a seven-segment display is used along with an MCU/MPU in that case, the eight
segment pins will be connected to the I/O pins of the Microcontroller and the com pin will be
connected to the ground of Vcc depending upon its type (CC/CA). Then these IO pins can be toggled
in a particular sequence to display the desired numbers. For displaying each number in the seven-
segment display its respective sequence is given in the table. If we want to display the number “0”, then
we need to glow all the LEDs except LED which belongs to line “g”
7-Segment Display Pin Configuration
Applications
• 1- Used in applications where font size is required to be bigger
• 2- Microcontroller Independent, hence used in small circuit
projects
• 3- Used in combination with four segments to display
measurement/sensor value with four characters
• 4- Has bright illumination, hence used where the display is
required to work in low light or dark conditions
جمهورية العراق
وزارة التعليم العالي والبحث العلمي
جامعة االمام جعفر الصادق (عليه السالم) – كركوك
كلية تكنلوجيا المعلومات – قسم هندسة تقنيات الحاسوب
Digital controllers
Lecture -6-
)PIC microcontrollers ( Programmable Interface Controllers
Input / Output ports
م.م سماره خميس
PIC microcontrollers
I/O Introduction
I/O is one of the most basic and critical functions of the PIC
microcontroller.
It is the method that we use to interface with the externals
we are trying to control.
PIC 8-bit I/O is quite robust and supports fairly high output
currents of up to 100mA.
The PIC16F18875 has 35 I/O points, organized into five
ports, A E
PIC microcontrollers
I/O
Ports
The older PIC only had a few registers needed to set up the I/O ports.
This newer one has quite a few more.
This makes it more difficult to set up, but it also leads to a much more
powerful I/O system.
PORTx registers (reads the levels on the pins of the device)
LATx registers (output latch)
TRISx registers (data direction)
ANSELx registers (analog select)
Ports
WPUx registers (weak pull up)
CCDPx registers (current control positive)
Digital controllers
Lecture -7-
)PIC microcontrollers ( Programmable Interface Controllers
Input / Output ports part -2-
م.م سواره خويس
I/O Port
The latch register allows you to
read the latch state of the Flip Flop
instead of the input state.The TRIS
register determines if the port is an
input or an output. If it is a 1, then
the port is an input. If it is a 0, then
the port is an output
Buffers
I/O Port
Flip-Flop
I/O Port
Logic Gate
DC Electrical Characteristics
Port A Registers
PORTA is an 8 bit wide, bidirectional port. The corresponding data direction register is TRISA.
Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e., disable the output
driver). Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., enables
output driver and puts the contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the pins, whereas writing to it will write to the
PORT A latch.
All write operations are read modify write operations. Therefore, a write to a port implies that the
port pins are read, this value is modified and then written to the PORT data latch (LATA).
The PORT data latch LATA holds the output port data and contains the latest value of a LATA or
PORTA write. The TRISA register controls the PORTA pin output drivers, even when they are
being used as analog inputs. The user should ensure the bits in the TRISA register are maintained
set when using them as analog inputs. I/O pins configured as analog inputs always read ‘0’.
جمهورية العراق
وزارة التعليم العالي والبحث العلمي
جامعة االمام جعفر الصادق (عليه السالم) – كركوك
كلية تكنلوجيا المعلومات – قسم هندسة تقنيات الحاسوب
Digital controllers
Lecture -8-
EEPROM
م.م سماره خميس
EEPROM
The EEPROM is stands for: Electrically Erasable
Programmable Read Only Memory.
This is non-volatile memory which means any data
which will be written to the EEPROM will be
remain in the memory even when no power is
supplied and it can be read at any time to retrieve
the data.
NOTE
Important fact to note is that the AVR’s internal
EEPROM memory has a limited lifespan of 100,000
writes per EEPROM. Keep this in mind and always try to
keep writes to a minimum, so that you only write the
least amount of information required for your
application each time you update the EEPROM.
Digital controllers
Lecture -9-
How to read Analog Signals in PIC Microcontrollers
م.م سماره خميس
Analog to digital Converter(ADC(
• Analog to Digital Converter (ADC) is an electronic integrated
circuit used to convert the analog signals such as voltages to
digital or binary form consisting of 1s and 0s. Most of the ADCs
take a voltage input as 0 to 10V, -5V to +5V, etc., and
correspondingly produces digital output as some sort of a binary
number.
ADC
• ADCs can vary greatly between
microcontrollers. The ADC on the Arduino is a
10-bit ADC meaning it has the ability to detect
1,024 (2^10) discrete analog levels. Some
microcontrollers have 8-bit ADCs (2^8 = 256
discrete levels) and some have 16-bit ADCs
(2^16 = 65,536 discrete levels).
Liquid-Crystal Display (LCD):
A liquid-crystal display (LCD) is a flat-panel display or another electronically modulated
optical device that uses the light-modulating properties of liquid crystals combined with
polarizes.
in this subject we choose one of the types of the crystal screen, which is 2 * 16, which is
considered the most popular, as well as the most common among electronic tools and in
electronic projects because to its availability at a low price and also for its ease of
programming since the Arduino, contains ready offices to facilitate dealing with this type
of screens. As shown in the figure below:
NOTE: It was named by this name because it contains two lines and 16 columns, so the
screen has a parallel communication system. As shown in the figure:
Using of LCD: -
LCDs are used in a wide range of applications, including:
Advantages of LCD:
1- Very compact, thin, and light.
2- Low power.
Disadvantages of LCD:
1. Loss of brightness.
2. Loss of contrast in high-temperature environments.
3. Black levels may not be as dark as required.