Notes
Notes
-> simulator
-> problem statement
design ->
stand alone
take decision on its own
example tesla cars :-
location airport , road construction
reroute
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
EPROM/UVROM;- uv rays
R-> infinite , W-> n times
ex : Rand D
memory
masked ROM;-
data stored below this memory will never get currpted
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
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
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
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
TRISB
-> 0x00
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
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++
PORTB
TRISB = RB0 = input
TRISB0 = 1;
PORTD =
TRISD = 0x00
level triggering
once = 1 once =1
edge trigger
Off
ON
}
voidinit_digital_keypad(void)
{ PORTB = RB7 6 5 4 3 2 1 0
}
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
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
while(1)
{
// application code
}
LED->
SWITCHES -> switches for washing machine
timer -> interrupt source
interrupt ->
high priority execution
timers ->
-> 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
down tick
start timer time = no of ticks * Q
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
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
6 0
count = 1sec/ 1 * 200* 10^ -9 s * 250 255 1
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->