Embedded 4
Embedded 4
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
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
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
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
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
• 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