0% found this document useful (0 votes)
8 views33 pages

Embedded 4

The document provides an overview of the PIC18F452 microcontroller, detailing its features such as 34 I/O pins, timers, analog-to-digital converters, and communication protocols like I2C and SPI. It also discusses the functionality of various ports, programming basics, and hardware circuits necessary for operation. Additionally, it includes programming examples and the use of keypads and relays in embedded systems applications.

Uploaded by

hossammedhat81
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)
8 views33 pages

Embedded 4

The document provides an overview of the PIC18F452 microcontroller, detailing its features such as 34 I/O pins, timers, analog-to-digital converters, and communication protocols like I2C and SPI. It also discusses the functionality of various ports, programming basics, and hardware circuits necessary for operation. Additionally, it includes programming examples and the use of keypads and relays in embedded systems applications.

Uploaded by

hossammedhat81
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/ 33

EMBEDDED SYSTEMS

Computer Engineering and Control Systems Dept.,


Faculty of Engineering,
Mansoura University

Prof. Dr Labib M. Labib


Lec. 4
PIC 18F452 MC
• PIC18F452 is an 8-bit FLASH-based microcontroller that has 34
I/O pins out of 40 Pin packages. It is a powerful microcontroller
with one 8-bit and three 16-bit timers,
• 8-Channels 10-bit Analog-to-digital converter , and I2C, SPI,
USART peripheral. It is a Low power microcontroller unit that
consumes about less than 0.2 uA standby current and 1.6 mA
normal current during 5V and 4 Mhz operations, 17- Interrupts
• USART(universal synchronous/asynchronous receiver/
transmitter) is hardware that enables a device to communicate
using serial protocols.
• SPI = Serial Peripheral Interface
• I2C is a two-wire serial communication protocol using a
serial data line (SDA) and a serial clock line (SCL).
• PIC18F452 also has the feature of Programming code
protection,
• Power-on Reset (POR), Power-up Timer (PWRT),
Oscillator Start-up timer with power saving sleep mode.
• The watchdog timer features its own On-Chip RC Oscillator
for reliable operations. 2V to 5.5V operating voltage makes
the 18F452 suitable for 3.3V
• A-D Converter
• Memory , Flash
• High Encrypted
PIC 18F452
40 pins – 34 I/O - 7 pins general
Functionality of pins
1- 𝑀𝐶𝐿𝑅 Master clear (reset)
Oscillator
2- OSC1
3-OSC2
Can be obtained by
i)crystal - frequency
• ii)using RC
5
• iii)Ic555 v
R
• 4,5 VDD + 5V
• 6, 7 VSS 0 V

0v +5v
0v +5v
Input/ output pins
• 34 pins for I/O
• are divided as follows
Name Numbers Names of
pins
• PortA 7 RA0-RA6
PortB 8 RB0-RB7
PortC 8 RC0-RC7
PortD 8 RD0-RD7
PortE 3 RE0-RE2
PORT A
Port A pins First function Second function Third function
number
1-RA0/AN0 Digital input Analog Input
2- RA1/AN1 Digital input Analog Input
3-RA2/AN2/Vref- Digital input Analog Input Vref-
4-RA3/AN3/Vref+ Digital input Analog Input Vref+
5-RA4 /T0clkI Digital input Timer 0- Input
6-RA5/AN4 Digital input Analog Input
7-RA6/OSC2 Digital input Osc2

Vref+
T0clkI T0
ADC Osc1

OSc2

Vref-
PORT B
Port B pins First function Second function Third function
number
1- RB0/INT0 Digital I/O INTERRUPUT 0(EX)
2-RB1/NT1 Digital I/O INTERRUPUT 1(EX))
3- RB2/NT2 Digital I/O INTERRUPUT 2 (
4-RB3 Digital I/O
5-RB4-RB7 Digital I/O Change Interrupts
/Change interrupt
There are 17 interrupts
External Interrupts
Internal I Interrupts
Change Interrupts 4 pins if the contents of these pins changed an
Interrupts
occurs
Ex f RB4- RB7 =1011 and f t becomes 1101 an Interrupts occurs
Used n control sgnals
PORT C
Port C pins number First function Second function Third function
RC0 Digital I/O
RC1/CCP2/T1CLKI Digital I/O CCP1 T1ClkI
RC2/CCP1 Digital I/O CCP2
RC3-RC9 Digital I/O

CCP : Capture, compare, PWM

PORT E
Port C pins First function Second function Third
number function
RE0/AN5 Digital I/O Analog input 5
RE0/AN6 Digital I/O Analog input 6
RE0/AN7 Digital I/O Analog input 7

Microcontroller has 8 pins for analog I/O


Hardware circuit on MC
• Any microcontroller board has 5 circuits mainly
• These circuits are :
• 1- Power
• 2- Reset
• 3-Oscillator
• 4- Input
• 5- Output
• If any of these circuits are faulted the MC doesn't work
Power Circuit

Battary
• AC-DC
• Diode (I)
• Cost

Trans
V,I
VA

Regulator LM 78XX
• Capacitor (V, Farad)
• Types of capacitors:
• 1-Electrolytic Capacitor
• High capacity, 400 v, has polarity ,used in DC
• Paper Capacitor
• capacitance range of 0.001 to 2.000 microfarads and a voltage range
of up to 2000V.
• Ceramic Capacitor
• Ceramic capacitors typically have values ranging from 1nF to 1F, with
values up to 100F being feasible.
Mica Capacitor
• Mica capacitors are low-loss capacitors that are utilized at high
frequencies.
• τ = RC , full charge in 5 τ
RESET
PULL UP RESISTOR

OSCILLATOR
CRYSTAL
LP 100K – 1MHZ
XT 1MHZ – 4 MHZ
HS 4MHZ – 20 MHZ
PLL 20 MHZ - …….
555 OSC1
EC
OSC2 OR ECIO
F/4 OR RA6
RC OR
RCIO
Cont. Oscillator

If use 555 oscillator it connects to


555 OSC1 OSC1
EC
OSC2 In programming use EC {using osc1
OR ECIO
only)
F/4 OR RA6 Or ECIO (using osc1 and osc2)

If use RC oscillator it connects to


OSC1
In programming use RC {using osc1
only)
Or RCIO (using osc1 and osc2)
RC OR
RCIO
Input

R1=10 k Ω
output
Output from MC is 5 v,
25 ma Where R is placed?

led

R= 330 Ω
Driving a motor
Blocking of transistor)on/ off)
Relay v= 12,24, 60, 70 -100 mA,
Noise of transistor(diode)
Use capacitor if AC
Spark of transistor
+12 v power supply has 12v
Free wheeling diode
To create a pass to the current
To avoid spark on transitor
mc

Motor
220 v
5A
Base current of transistor is
in micro A

220
N
There are many series of transistor ‫ال يمكن عكس اطراف الريالي و‬
Bc, 2n, ,,,,, ‫الترانزستور‬
Each series has each base current ‫تفريغ المجال المغناطيسي‬
Capacitor is placed instead
of diode
Relay
A
• relay is an electrical switch
that opens and closes under the
control of another electrical
circuit. It is therefore connected
to output pins of the
microcontroller and used to turn
on/off high-power devices such
as motors, transformers, heaters,
bulbs, etc. These devices are
almost always placed away
from the board’s sensitive
components.
An optoisolator (also known as an optical
coupler, photocoupler, optocoupler) is a
semiconductor device that transfers an
electrical signal between isolated circuits
using light.
programming
• Programming a units of MC
• I/O ports
• Ports are A,B,C,D,E each port has two registers
• One of each register is the TRIS X , where X may be A,B, ..
• PORT A
• 0 – TRISA , 8 bits register, control the pins to be input or
output , input = 1 , output= 0
• The second register is called 0 0 1 1 0 1 0

• The second register is called RA6 RA5 RA4 RA3 RA2 RA1 RA0

• PORTA reg. : store Data entered or output


• All the ports are similar to port A
• Cont. PortA
• As portA has pins that may be digital or analog
to define that use a register name ADCon1 = 6
or 7 means the data are digital in port A 12 v

• RA4 is open collector


10 v
each output is 0
1
o/p 0 0
i/p F
1
O
0 Open collector
0
1
RA4 is is input to timer1
Normal TranAct as NOT Can be connected to 12 v why ?
GATE Can drain current greater than
the others
Basics
• 1- Variable types

int Float 32 bits


Character 8bits

2- Numbers
signed
unsigned Decimal 89 = 89
binary 11110011 = 0b11110011
Short 8 bits -128 :127 Hex AF = 0XAF
Int 16 bits -215: 215 --1 Short 8 bits 0 : 255
Long 32 bits -231 :231-1 Int 16 bits 0 : 216 3- Assignment
Long 32 bits 0 : 232
a-Register
Register_name = value;
Ex X=6;
ADCon1 = 6;
B-Bit in register
Except PORTA, B,….. Register_name.bit_number= 0 or 1
Ex TRISC.4 = 1; as input
Ex PORTA.b5=1
5- Delay
Delay_ms(500); delay = 500 msec
Delay_us(500); delay = 500 microsec
Function
Delay
Using timer Loop 1000 …… calculates the
……. Loop 1000 …… time as function
……..
……. ………
Delay in inst.
…. ……. execution
……….
……….. …nop……10 ..
Finished timer
Each inst. Take time of
200 Nano sec

What is the difference between Delay and


timer?
In delay Nop for a certain period
Using In timer start count until finished , while
Mikro.c (Fed.c , Ansi) processor operates
Porotous to simulation

Programming lang. of microcontroller are basic, Pascal, c


and java , assembly
Programming
• Example : Write a program to flash 8 Leds connected to po
• Porta B with delay 500 msec
• First step is draw the circuit of the PIC with five
circuits(Power, Reset, Oscillator, I/p, O/P )
• Second Declaration of variables
• Third Initialization
Example 1
• Main ()
• {

• While(1)
• { TRISB= 0; /* or =0b00000000 or 0X00;
• PORTB = 255;
• Delay_ms(500);
• PORTB = 0;
• Delay_ms(500);
• }
• }
Example 2
• Write a program to count number of pressed of Switch
connected to RA0 and display the result on 8 leds connected
to portB in binary manner until press a switch connected to
RA1 exit
• From the
• loop


Main()
{unsigned short int count= 0; program
• TRISB= 0;
• TRISA = 0XFF;
• ADCON1=6; T0 RA4
• Loop: If (PORTA.B0==1 ) T1 RC1
• {
• Count ++;
• PORTB = count;
• Delay_ms (300);
• }
• While((PORTA.b0== 1);
• Delay_ms (300); We can add capacitors 10 μf
• If (PORTA.b1== 0) between switch and ground
• Goto loop;
• {Poortb=0;
• Count = 0;
• }}

Keypads
• Types of keypads
• a)Direct
• Matrix
7- segments

You might also like