demo of the project
-> simulator
-> problem statement
1. select the washing program
2. select the water level
3. start
4. function selected and time
machine fan rotation,
automatic gate opening system( pure hardware)
1.sensor -> ir
uc -> hardware software
2.compator
3. relay ->
4. timers
design ->
stand alone
take decision on its own
example tesla cars :-
location airport , road construction
reroute
real time;- ES which will complete the task within deadline
ex ;-missile system , air bag
networked
ES which can connect to other devices and able transmit data and recive
mobile
ES which you carry it from one place to another
hybrid ES
processing unit
up , uc , soc
memory
RAm: random acess memory
-> write/read = infinite times
volatile memory -> requires powersupply to retain the data
if there is no power supply the data will be erased
sram:- constant power to retain the data , cost more
dram:- more power
constant power supply + extra power supply to refresh the data
Rom:read only memory
-> write =one time read -> infinite times
non volatile memory
-> doest require the power supply to retain the data
rom
OTP/PROM ;-one time programable memory ,
W -> 1 , r -> infinite
ex: micro oven, toys -> mobile
EPROM/UVROM;- uv rays
R-> infinite , W-> n times
ex : Rand D
memory
masked ROM;-
data stored below this memory will never get currpted
ex man fact date , chip id
taken selfie :-
ram ->
deleted
rom-> H ROM
RAM
i cannot delete
W-> inifite
non volatile
hybrid memories
EEPROM -
-non volatile memory
-persistant
-> r - infinite w -> 1 million times
byte acessable
size -> 256 bytes to 128 KB.
ex -> number or count or any state
Flash memories
Flash memories:-
nor-> byte accessable
non volatile memory
r- infinite w ->n
xip -> execute in place -> need not load code in ram for execution
store code in micro controllers
nand-> bolck acess able -> store data in blocks 256 bytes , 512 bytes
non volatile
r- infinite w ->n
less reliable
nand -> data is stored
ex: sd cards , pendrives
overview about the tools
simple program
switches ->
clcd ->
timer ->
buzzer->
fan/ motor ->
refer requirement document and start implementing the requirements one by one
host :- system which is used to develop the target
laptop
BOARD: picsimlab simulator pic genious board
pic16f877a
code execute in the board
target:- a system which is being developed
C programing
wrote ->laptop
->execute laptop
uc
development ->laptop -> c code = execute able file
being developed = board ->
host:
sytem which is used to develop the target
laptop
target :
system which is being developed for particular purpose
simulator -> picsimlab
board :- pic genious
controller : pic16f877a
First code :- simple pheripheral available board
less complication ,less overhead
code is simple
-> hardware is working or not
-> tools properly installed
-> conection host and target eshtablished or not
what pheripherals available on the board
RB
FB
OFF
condtion
ON
interfacing an LED to uC pin LED 2. +5v
1 ON
1
0 OFF
uC pin
vdd 1
pin 0 +
uC -
gnd
pin LED
pin -> 1 +5v vdd 1 OFF
0 gnd 0 ON
sourcing circuit sinking circuit
WAP to blink the LED? main()
-> 16 LEDs {
where the LEDS are conected? int led;
how they are connected?
led = 1;
led = 0;
i/0 ports
uC
external pheripheral to your micro controller
fixed number of I/O ports
pic16f877a
architecture of the uc
data sheet -> technical document information of the controller
pic16f877a -> 5 ports
33i/o pin
led-> schematic -> blue print of the board
PORTD , PORTB
sourcing
1 -> ON , 0 -> OFF
biderection out put / input port
PORTB -> 8 bit wide
PORTB -> leds RB7 RB6 .......... RB0
data sheet -> DDR
TRISB -> 8 bit
TRISB7 6 ....................... 0
TRSIB = 0000 0000
portb pin will be output pin
TRISB = 1111 1111
portb pin will be input pin
PORTB -> 0x06
<xc.h>
TRISB -> 0x86
include this header
TRISB
-> 0x00
unsigned char * portb = 0x06;
WAP to blink the LEDs connected to PORTB
8 leds -> poRTB , sourcing circuit
PORTB
DDR -> TRISB = 0x00 -> output pins
0xFF -> input pins
pointers -> <xc.h>
step 1
config the led port as output port
step2
turn on the leds
delay
turn off the leds
delay
goto step2
led :-
mc -> 5 ports
led -> PORTB , sourcing circuit fashion
DDR -> TRISB
WAP to toogle the LED
#include <xc.h>
#pragma config WDTE = OFF
void init_config(void)
xc.h ->
{
// one time initialisation code
}
watch dog timer
void main(void)
reseting the uc for configured time
{
init_config();
while (1)
{
//logic
}
} WDT
uc 1 hr
1 day
1 week
pheripherals :-
*lcd
*switches
*buzzer
*fan
*timer
Switches: tactile switches
interfaced with micro controller
detecte the switch pressed on the mic
pull up circuit pull down circuit
vdd vdd
pin R2> 10r1
uc uc pin
sw R1
R2
gnd
gnd
pin sw pin SW
0 prssed 0 R
1 released 1 P
detection type
level triggering
vdd edge trigerring 5v
0v
vol button 1
pin -> vol++ continous action
CRo sw level trig 0
vol++ vol++
gnd power button one time
->on /off
off ON off
edge edge
level : to trigger the task based on the value
edge : to triggger the task based on the change in the value
where the switches are connected and how they are connnected
6 switches -> rbo to rb5 , pull up circuit
WAp to toogle the led when sw is preesed
led -> rd0 , sw -> rb0
toogle as long as switch is pressed Rb0 = 0
PORTB
TRISB = RB0 = input
TRISB0 = 1;
PORTD =
TRISD = 0x00
level triggering
once = 1 once =1
edge trigger
one time action
once = 1
change state led one once =0 one
once =0 time time
led = on led = off
while (1)
{
/*check if the switch is pressed*/
if(RB0 == 0 && once )
{
PORTD = ~PORTD;
once = 0;
}
if(RB0 == 1)
{
once = 1;
}
Off
ON
}
voidinit_digital_keypad(void)
{ PORTB = RB7 6 5 4 3 2 1 0
/*to config RB0 to RB5 as input pins*/ TRISB = x x x x x x x x
KEYPAD_PORT_DDR = TRISB| 0x3F => x x 1 1 1 1 1 1
}
TRISB = x x x x x x x x
|0 0 11 1111
void init_config(void) = x x 11 1111
{ -> 0x3F
/*config led port as output port PORTD*/ TRISB = TRISB | 0x3F
TRISD = 0x00;
PORTD = 0x00;
TRISB = 00 11 1111
/*config RB0 to RB5 pin as input pin*/ RB7 , RB6
init_digital_keypad();
#define LEVEL 0
#define STATE 1
void main(void)
{
unsigned char once = 1, key ;
init_config();
while (1)
{
/*check if the switch is pressed*/
key = read_switches(STATE) SW1
if(key == SWITCH1)
{
PORTD = ~PORTD;
for(unsigned int wait = 50000; wait--;);
}
}
}
SWITCHES
#define ALL_RELESED 0x3F
#define SWiTCH1 0x3E PORTB = rb7 6 5 4 3 2 1 0 PORTB&0x3F
#define SWITCH2 0x3D & = x x 1 1 1 1 1 1
#define KEYPAD_PORT PORTB 0 0 1 1 1 1 1 1
#define KEYPAD_PORT_DDR TRISB => 0 0 1 1 1 1 1 1
#define INPUT_LINES 0x3F no swit = x x 1 1 1 1 1 1 0x3F
switch1 = x x 1 1 1 1 1 0 0x3E
unsigned char read_switches(detection_type) switch2 = x x 1 1 1 1 0 1 0x3D
{
static unsinged char once = 1;
if (detection_type == LEVEL)
{
return (KEYPAD_PORT & INPUT_LINES);
}
if (detection_type == STATE)
{ /* if any switch is pressed*/
if((KEYPAD_PORT & INPUT_LINES) != ALL_RELEASED && once )
{
once = 0;
return (PORTB & 0x3F)
}
if(PORTB &0x3F== ALL_RELEASED)
{
once = 1;
}
return ALL_RELESED;
}
}
A_R,A_R once=1
AR AR
SW1 AR AR AR SW1
once=0 once =0
project
main.c
main.h
digital_keypad.h
switches
digital_keypad.c
init_digital_keypad()
read_digital_keypad()
sw 2 =
toogle alternate led
portb = 0xaa 1010 1010
portb = 0x55 0101 0101
main() read_digital_kepad->
{ level->
init_config(); as long as switch is prresed
while(1) which switch is preesed
{ all_realsed
key= read_digital_keypad(LEVEL)
if(key == SWITCH1) state:-
{ return one time
code which switch is pressed
}
if(key == SWITCH2) example
{ vol++ -> level
code entering the password -> state
}
}
SW1
pattern1
alternate leds
PORTB = 0 1 0 1 0 1 0 1 -> 0x55
sw2
= 1 0 1 0 1 0 1 0 -> 0xAA
toogle the nibble
PORTB = 1 1 1 1 0 0 0 0 -> 0xF0
4 led on
0 0 0 0 1 1 1 1 -> 0x0F
4 led off
pORTB = 1 1 1 1 1 1 1 1 -> 0xFF
sw3
0 0 0 0 0 0 0 0 -> 0x00
toogle al the leds
0x55 - 0101 0101
~ 0xAA- 1010 1010
while(1)
{
// application code
}
LED->
SWITCHES -> switches for washing machine
timer -> interrupt source
interrupt ->
high priority execution
timers ->
external/ internal -> set interrupt flag
main()
{ Interrupt handler
isr()
while(1)
{
{
I1
clear the int flag
I2
I1 was being executed
}
I3
->complete the i1 instruction
->execute the isR()
}
-> i2
}
interrupt handlers pic isr()-> all interrupt source
-> IVT interrupt service routine()
timers 0x11 {
external 0x22
.
. }
.
-> ISR
while() exrternal / internal -> setting int_flag
{
ISR()
{
I1->requested 1. i1 should be completed
I2 2. PC -> stack
3. PC -> *(isr)
int_flag =0;
}
}
case1: I1
PC -> *(I2)
case2: I1
PC -> *(isr)
*(I2)saved on stack registers
interrupt latency :- delay in execution of the isr.
ISR will not be execute as soonas interrupt is requested
delay
-> completeion I1 dealy
-> PC
-> priorty execution
-> setting int flag
-> isr() function wiil be called
-> clear int_flag
timers: default pherpheral uC
calculate or tack the time resolution : width of the timer register
ex : 8 bit , 16 bit, 32
timer TMR0 tick : UP tick , down tick
1
timer regiters Quantum : time taken by one tick
255 0
2
sytem clock setting-> F =
3 8 bit 1 tick -> 4 clk pulse -> 4 * t
4
0 time -> 4 * 1/f
1 Q -> 4 * 1/ 20 * 1o^6
2 up tick = 0.2 us -> 200ns
3
. 1 tick -> 200ns
. 255 2 tick -> 400ns
down tick
start timer time = no of ticks * Q
start time= 255 * 200ns
counting ticking 8 bit
timer_int_flag
0
overflow-> 0
255 request interrupt-> isr()
main()
{
start timer
while(1) isr() count = 1
{ {
if (timer_int_flag)
++count;
} timer_int_flag = 0;
} }
time taken by one overrflow timer 8 bit
256
= 256 *200ns
= 51200ns -> 51.2us 255 2 1 0
time taken count overflow
time = count *time taken 1 ov time = count * no of tick in ov * Q * P
time= count * no of tick in ov * Q
= 2 * 256 *200ns -> 102.4us
while() isr()
scaling : way to increase the time to go to isr
{ {
51.2us
prescaling: Q is scaled
1:1 Q= 1IC-> 200ns ov-> 51.2us 102.4us
1:2 Q= 2IC ->400ns ov -> 102.4us }
}
postscaling: after how many ov isr()
1:1 1ov-> 51.2us 1 ov isr () will be called
1:2 51.2us 2 ov isr() will be called
1:4 4 ov isr()
R = 8 bit -> 256
R = 16 -> 65536
time = count * no of tick in ov * Q * P
count = time
P* Q * R
timer reg-> R/W
example : calculate count for the folowing
P 1:1 , Q = 200ns , R -> 8 bit = 256 , time = 1 sec
6 0
count = 1sec/ 1 * 200* 10^ -9 s * 250 255 1
count = 19531 .25 250
count = 20000
timer -> over flow ->int
timer reg
how to get 250 ticks
250
2 1 0
6
255
250
250 ticks
comparator reg
timer
resolution count = time / p*q*r
tick
q
ov
int
WAP to toggle the led for every one second using timers
use timer2
tmr2
resolution = 8 bit
TMR2 = timer register
PR2 => how tick for o.v
timer2 int flag pr2
-> TMR2IF = 1
intcon
-> gie -
-> peie -
10 min to be full
5 min->