You are on page 1of 28

C BASED EMBEDDED SYSTEM DESIGN LAB FILE

Submitted to: Mr. Neeraj Gupta Fa#u"ty$ECE ASET

Submitted by: Shubham Ba !a" ECE%B&$'th !em A()*)(**))**

E+perime t * Aim: To study 8051 Microcontroller kit. Theory:

,i De!#riptio )%p).) to p).-&: It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external "unctions as ultiplexed data and lo#-order address bus $D0-$D%. e ory access! it

,ort * %p*.) to p*.-&: It is 8-bit bi-directional I/O port. It is bit/ byte addressable. &'en logic (1( is #ritten into port latc' t'en it #orks as input ode. It "unctions as si ply I/O port and it does not 'a)e any alternati)e "unction. ,ort . %p..) to p..-&: It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external "unctions as 'ig'er order address bus *$8-$15+. e ory access it

,ort /%p/.) to port /.-&: It is 8-bit I/O port. In an alternating "unction eac' pins can be used as a special "unction I/O pin. ,/.)$0+D: It is an Input signal. T'roug' t'is I/, signal co unication circuit. icrocontroller recei)es serial data o" serial

,/.*$T+D: It is O/, signal o" serial port. T'roug' t'is signal data is trans itted. ,/..$ %INT)&: It is external 'ard#are interrupt I/, signal. T'roug' t'is user! progra interrupts to icrocontroller. ,/./$%INT*&: It is external 'ard#are interrupt I/, signal. T'roug' t'is user! progra interrupts to icrocontroller. er or perip'eral

er or perip'eral

,/.1$ T): It is I/, signal to internal ti er-0 circuit. -xternal clock pulses can connects to ti er-0 t'roug' t'is I/, signal. ,/.($T*: It is I/, signal to internal ti er-1 circuit. -xternal clock pulses can connects to ti er-1 t'roug' t'is I/, signal. ,/.2$340%bar&5: It is acti)e lo# #rite O/, control signal. During -xternal .$M *Data e ory+ access it is generated by icrocontroller. #'en /&.*bar+010! t'en per"or s #rite operation. ,/.-$30D%bar&5: It is acti)e lo# read O/, control signal. During -xternal .$M *Data e ory+ access it is generated by icrocontroller. #'en /.D*bar+010! t'en per"or s read operation "ro external .$M. 6TAL* a d 6TAL.: T'ese are t#o I/, line "or on-c'ip oscillator and clock generator circuit. $ resonant net#ork as 2uart3 crystal is connected bet#een t'ese t#o pin. 8051 icrocontroller also dri)es "ro external clock! t'en 4T$56 is used to dri)e 8051 "ro external clock and 4T$51 s'ould be grounded. 3EA%bar&578,,: It is and acti)e lo# I/, to 8051 icrocontroller. #'en *-$+1 0! t'en 8051 icrocontroller access "ro external progra e ory *.OM+ only. &'en *-$+ 1 1! t'en it access internal and external progra e ories *.OM7+. 3,SEN%bar&5: It is acti)e lo# O/, signal. It is used to enable external progra e ory *.OM+. &'en /,7-8*bar+01 0! t'en external progra e ory beco es enabled and icrocontroller read content o" external e ory location. T'ere"ore it is connected to *O-+ o" external .OM. It is acti)ated t#ice e)ery external .OM e ory cycle.

ALE: $ddress latc' enable9 It is acti)e 'ig' O/, signal. &'en it goes 'ig'! external address latc' beco es enabling and lo#er address o" external e ory *.$M or .OM+ latc'ed into it. T'us it separates $0-$% address "ro $D0-$D%. It pro)ides properly ti ed signal to latc' lo#er byte address. T'e $5- is acti)ated t#ice in e)ery ac'ine cycle. I" external .$M : .OM is not accessed! t'en $5- is acti)ated at constant rate o" 1/; oscillator "re2uency! #'ic' can be used as a clock pulses "or dri)ing external de)ices. 0ESET: It is acti)e 'ig' I/, signal. It s'ould be aintained 'ig' "or at least t#o oscillator is running t'en 8051 icrocontroller resets. ac'ine cycle #'ile

E+perime t . Aim: I ple entation using "las' Magic So9t:are u!ed: <las' Magic =.18.166= Theory: 84, 7e iconductors produce a range o" Microcontrollers t'at "eature bot' on-c'ip <las' e ory and t'e ability to be reprogra ed using In-7yste ,rogra ing tec'nology. <las' Magic is &indo#s so"t#are "ro t'e - bedded 7yste s $cade y t'at allo#s easy access to all t'e I7, "eatures pro)ided by t'e de)ices. T'ese "eatures include9 > -rasing t'e <las' > ,rogra e ory *indi)idual blocks or t'e #'ole de)ice+ e ory

ing t'e <las' e ory

> .eading <las'

> ,er"or ing a blank c'eck on a section o" <las' > .eading and #riting t'e security bits > Direct load o" a ne# baud rate *'ig' speed co

e ory

unications+

?nder &indo#s! only one application ay 'a)e access t'e @OM ,ort at any one ti e! pre)enting ot'er applications "ro using t'e @OM ,ort. <las' Magic only obtains access to t'e selected @OM ,ort #'en I7, operations are being per"or ed. T'is eans t'at ot'er applications t'at need to use t'e @OM ,ort! suc' as debugging tools! ay be used #'ile <las' Magic is loaded.<las' Magic pro)ides a clear and si ple user inter"ace to t'ese "eatures and ore as described belo#9

Bur i ; the pro;ram i a mi#ro#o tro""er 1. 6. B. =. 5. ;. %. 8. Open t'e "las' agic. 7elect icrocontroller $T8A@51. 7et baud rate. 7elect co port. 8o# c'eck t'e box -.$7- $55 <5$7C. @'eck t'e box D-.I<E $<T-. ,.OF.$MMI8F. @lick on bro#se to bro#se progra Cex "ile. @lick 7T$.T to start t'e burning process.

E+perime t / Aim: &rite a progra to add t#o 8-bit nu bers using icrocontroller 8051. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram:

<utput: 55C 01010101

E+perime t 1 Aim: &rite a progra to subtract t#o 8-bit nu bers using icrocontroller 8051. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram:

<utput: 10C 00010000

E+perime t ( Aim: &rite a progra to ultiply t#o 8-bit nu bers using icrocontroller 8051. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram:

<utput: 15C 00010101

E+perime t 2 Aim: &rite a progra to di)ide t#o 8-bit nu bers using icrocontroller 8051. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram:

<utput: 00000010

E+perime t Aim: Hlinking o" 5-D. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram:

<utput: Hlinking 5-D

E+perime t ' Aim: &rite a progra "or analog to digital con)ersion using icrocontroller 8051. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: Iinclude J,8A@51.D6.'K Iinclude Jstdio.'K Iinclude L"unde".'L Iinclude Lde"ines.'L Iinclude L)ars.'L Iinclude Llcd1;x6.'L Iinclude Luart.'L )oid putc'ar *c'ar putt'is+ M lcd1;x6N#rite *putt'is!0x86+ O P )oid s allNdelay*)oid+ M unsigned c'ar lNte p O "or *lNte p 1 0O lNte p J 60O lNte pQQ+ O P )oid ain*)oid+ M unsigned int delay O "loat )oltage 1 0 O $D@N@7 1 0 O -$ 1 0 O lcd1;x6Ninit*+ O lcd1;x6Nclear*+ O lcd1;x6Ncursor*0x80+ O lcd1;x6N#riteNstring *L@'annel 0 L+ O lcd1;x6Ncursor *0x@0+ O ,B 1 0x06 O #'ile *1+ M D$@D$T$ 1 0x<< O $D@D$T$ 1 0x01 O ,B 1 0x10 O s allNdelay*+ O ,B R1 0x=0 O s allNdelay*+ O ,B :1 0x-6 O s allNdelay*+ O

,B :1 0x06 O #'ile *$D@N-O@ S1 1+ O s allNdelay*+ O $D@D$T$ 1 0x<< O $D@D$T$ 1 0x<< O $D@N@7 1 1 O s allNdelay*+ O adcNdata 1 $D@D$T$ O s allNdelay*+ O adcNdata 1 $D@D$T$ O $D@N@7 1 0 O )oltage 1 *"loat+adcNdata O )oltage 1 *)oltage T 5.0+ / 65;.0 O lcd1;x6Ncursor*0x@0+ O print"N"astN" *L L+ O lcd1;x6Ncursor*0x@0+ O print"N"astN" *LCex 1 U6x L!adcNdata+ O//!*unsigned int+adcNdata+ O lcd1;x6Ncursor*0x@0+ O ,B 1 0x06 O "or *delay 1 0O delay J B0000OdelayQQ+ O PP

E+perime t = Aim: Digital to $nalog @on)erter. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: Iinclude J,8A@51.D6.'K Iinclude Jstdio.'K Iinclude L"unde".'L Iinclude Lde"ines.'L Iinclude L)ars.'L Iinclude Llcd1;x6.'L Iinclude Luart.'L Iinclude L isc.'L Iinclude Lisr.'L )oid putc'ar *c'ar putt'is+ M uartNsendNc'ar*putt'is+ O P unsigned c'ar getkey1*)oid+ M unsigned c'ar lNte p O unsigned int delay O GHD,O.T 1 0x<< O i" **GHD,O.T : 0x<<+ 11 0x<<+return *0+ O lNte p 1 GHD,O.T : 0x<< O "or *delay 1 0O delay J 6000O delayQQ+ O i" **GHD,O.T : 0x<<+ S1 lNte p+return*0+ O #aitNrelease9 #'ile **GHD,O.T : 0x<<+ S1 0x<<+ O "or *delay 1 0O delay J 1000O delayQQ+ O i" **GHD,O.T : 0x<<+ 11 0x<<+ return *lNte p+ O goto #aitNrelease O P )oid ain *)oid+ M unsigned c'ar key O lcd1;x6Ninit*+ O lcd1;x6Ncursor*0x80+ O lcd1;x6N#riteNstring*L&a)e"or L+ O lcd1;x6Ncursor*0x@0+ O lcd1;x6N#riteNstring*LFeneratorL+ O initNti er0*+ O -$ 1 1 O

#'ile*1+ M key 1 0 O #'ile **key 1 getkey1*++ 11 0+ O i" *key 11 0x<-+ M -$ 1 0 O #a)e"or 1 1 O dacdata 1 0 O direction 1 1 O -$ 1 1 O P i" *key 11 0x<D+ M -$ 1 0 O #a)e"or 1 6 O dacdata 1 0 O direction 1 1 O -$ 1 1 O P i" *key 11 0x<H+ M -$ 1 0 O dacdata 1 0 O #a)e"or 1 0 O sineptr 1 sinelookup O -$ 1 1 O P i" *key 11 0x<%+ M -$ 1 0 O #a)e"or 1 B O dacdata 1 0 O -$ 1 1 O P i" *key 11 0x-<+ M i" *sa pledelay K 1+ sa pledelay-- O P i" *key 11 0xD<+ M i" *sa pledelay J 0x""+ sa pledelayQQ O P PP

E+perime t *) Aim: &rite a progra to generate a s2uare #a)e. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: @,?L8051.TH5L CO<LI8T8L ,09 -V? 80C ,19 -V? A0C ,69 -V? 0$0C ,B9 -V? 0H0C .09 -V? 00C $9 -V? 0-0C H9 -V? 0<0C 5@D.79 -V? 0H5C 5@D-9 -V? 0$%C ,ortB=9 -V? 0H=C @ount9 -V? 060' @ount'i9 -V? 061' O.F 0000C 7T.T9 MOD ,6!I00C MOD ,1!I00C MOD ,B!I00C MOD ,0!I00C O?T,?T9 MOD ,0! I00C @5. ,ortB= @5. 5@D.7 5@$55 D-5$E MOD ,0! I0<<C 7-TH ,ortB= @5. 5@D.7 5@$55 D-5$E C-.-9 8O, 7WM, O?T,?T D-5$E9 D5E19 C19 -8D MOD .1!I0<<C MOD .6!I0<C DW8X .6! C1 DW8X .1!D5E1 .-T

E+perime t ** Aim: &rite a progra to operate a 7tepper $@ otor So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: @,?L8051.TH5L CO<LI8T8L ,09 -V? 80C ,19 -V? A0C ,69 -V? 0$0C ,B9 -V? 0H0C .09 -V? 00C .19 -V? 01C .69 -V? 06C .B9 -V? 0BC .=9 -V? 0=C .59 -V? 05C .;9 -V? 0;C .%9 -V? 0%C D,59 -V? 86C D,C9 -V? 8BC 5@D.79 -V? 0H5C 5@D-9 -V? 0$%C 5@D.&9 -V? 0H=C DI.9 -V? 0A0C @ount9 -V? 060' @ount'i9 -V? 061' O.F 00B0C MOD ,0!I0' 7T$.T9 MOD $!,0 W8H DI.!.-D MOD ,0!I00' $@$55 D-5$E MOD ,0!I06' $@$55 D-5$E MOD ,0!I0;' $@$55 D-5$E MOD ,0!I0=' $@$55 D-5$E MOD ,0!I0@' $@$55 D-5$E MOD ,0!I08' $@$55 D-5$E MOD ,0!I0A'

$@$55 D-5$E MOD ,0!I01' $@$55 D-5$E MOD ,0!I0B' $@$55 D-5$E 7WM, 7T$.T .-D9 MOD ,0!I0B' $@$55 D-5$E MOD ,0!I01' $@$55 D-5$E MOD ,0!I0A' $@$55 D-5$E MOD ,0!I08' $@$55 D-5$E MOD ,0!I0@' $@$55 D-5$E MOD ,0!I0=' $@$55 D-5$E MOD ,0!I0;' $@$55 D-5$E MOD ,0!I06' $@$55 D-5$E MOD ,0!I00' $@$55 D-5$E 7WM, 7T$.T D-5$E9 MOD .6!I100D C19 MOD .B!I655D C69 DW8X .B!C6 DW8X .6!C1 .-T -8D

E+perime t *. Aim: &rite a progra to operate a 7tepper D@ otor So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: Iinclude J,8A@51.D6.'K Iinclude Jstdio.'K Iinclude L"unde".'L Iinclude Lde"ines.'L Iinclude L)ars.'L Iinclude Llcd1;x6.'L Iinclude Luart.'L Iinclude Lisr.'L Iinclude L isc.'L )oid ain *)oid+ M lcd1;x6Ninit*+ O lcd1;x6Nclear*+ O initNti er0*+ O initNpcaNp# Ncex0*+ O -$ 1 1 O stepper9 ,0 :1 0x<0 O lcd1;x6Ncursor*0x80+ O print" *L7tepper Dri)eL+ O lcd1;x6Ncursor *0x@0+ O #'ile *1+ M stepno 1 0 O keyNrelease 1 0 O #'ile *keyNrelease S1 1+ M i" *'al"Nstep 11 0+ ,0 1 stepperNse2/stepno0 O else ,0 1 'stepperNse2/stepno0 O gpti eout 1 stepNdelay O gpti eoutNdone 1 0 O #'ile *gpti eoutNdone S1 1+ O stepno Q1 direction O i" *'al"Nstep 11 0+ stepno :1 0x0B O else stepno :1 0x0% O print" *L7tep UuL!*unsigned int+stepno+ O

lcd1;x6Ncursor*0x@0+ O P i" *key 11 7T-,NTOFF5-+'al"Nstep Y1 1 O i" *key 11 DI.-@TIO8+direction Y1 0x"e O i" **key 11 @<$7T+RR*key 11 <<$7T++ i" *key 11 <<$7T+ i" *stepNdelay K 60+ stepNdelay -1 10 O P else M i" *stepNdelay K 600+ stepNdelay -1 50 O PP i" **key 11 <75O&+RR*key 11 @75O&++ M i" *7H?< 11 <75O&+ M i" *stepNdelay J 6000+ stepNdelay Q1 10 O P else M i" *stepNdelay J 1500+ stepNdelay Q1 50 O P P i" *key 11 D@7T-,,-.+ M ,0 :1 0x<0 O goto dcN otorNrun O P P dcN otorNrun9 lcd1;x6Nclear*+ O lcd1;x6Ncursor*0x80+ O print" *LD@ Dri)eL+ O lcd1;x6Ncursor *0x@0+ O print"N"astN" *LU"L!100.0-*"loat+p# Nduty T 100.0/65;+ O D@<O.&$.D 1 0 O D@.-D-.7- 1 1 O #'ile *1+ M keyNrelease 1 0 O #'ile *keyNrelease S1 1+ O i" *key 11 DI.-@TIO8+ M

D@<O.&$.D 1 1 O D@.-D-.7- 1 1 O i" *dcNdirection 11 0+ D@.-D-.7- 1 0 O else D@<O.&$.D 1 0 O dcNdirection Y1 1 O P i" **key 11 @<$7T+RR*key 11 <<$7T++ M i" *key 11 <<$7T+ M i" *p# Nduty K 0+p# Nduty-- O P else M i" *p# Nduty K 10+p# Nduty -1 10 O P @@$,0C 1 p# Nduty O lcd1;x6Ncursor *0x@0+ O print"N"astN" *LU"L!*"loat+*65;- p# Nduty+ T 100.0/65;+ O P i" **key 11 <75O&+RR*key 11 @75O&++ M i" *key 11 <75O&+ M i" *p# Nduty J 04<<+p# NdutyQQ O P else M i" *p# Nduty J 04<5+p# Nduty Q1 10 O P @@$,0C 1 p# Nduty O lcd1;x6Ncursor *0x@0+ O print"N"astN" *LU"L!*"loat+*65; - p# Nduty+ T 100.0/65;+ O P i" *key 11 D@7T-,,-.+ M D@.-D-.7- 1 1 O D@<O.&$.D 1 1 O lcd1;x6Nclear*+ O goto stepper O PPP

E+perime t */ Aim: &rite a progra to generate Tra""ic lig't se2uence. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: MOD ,6!I0 C MOD ,1!I0 C MOD ,B!I0 C MOD ,0!I0 C 7T.T9 MOD $!,0 MOD ,1!$ 7WM, 7T.T

E+perime t *1 Aim: &rite a progra to operate H@D se)en seg ent display. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: @,?L8051.TH5L CO<LI8T8L ,09 -V? 80C ,19 -V? A0C ,69 -V? 0$0C ,B9 -V? 0H0C .09 -V? 00C .19 -V? 01C .69 -V? 06C .B9 -V? 0BC .=9 -V? 0=C .59 -V? 05C .;9 -V? 0;C .%9 -V? 0%C D,59 -V? 86C D,C9 -V? 8BC O.F 0000C 7T.T9 MOD ,6!I%<C MOD ,1!I0<<C MOD ,B!I0<<C MOD ,0!I0<<C MOD ,0!I88C MOD ,B!I0<-C $@$55 D5E MOD ,0!I0$HC MOD ,B!I0<DC $@$55 D5E MOD ,0!IA6C MOD ,B!I0<HC $@$55 D5E MOD ,0!I8AC MOD ,B!I0<%C $@$55 D5E MOD ,0!I0@1C MOD ,B!I0-<C $@$55 D5E MOD ,0!I0$$C MOD ,B!I0D<C

$@$55 D5E MOD ,0!I88C MOD ,B!I0H<C $@$55 D5E MOD ,0!I0$HC MOD ,B!I0%<C $@$55 D5E 7WM, 7T.T D5E9 MOD .6!I0<<C ?,69 MOD .B!I0<<C ?,19 MOD .=!I05C C-.-9 DW8X .6!C-.DW8X .B!?,1 DW8X .6!?,6 .-T -8D

E+perime t *( Aim: &rite a progra to operate bot' se)en seg ent and group o" leds using keys. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: Iinclude J,8A@51.D6.'K Iinclude Jstdio.'K Iinclude L"unde".'L Iinclude Lde"ines.'L Iinclude L)ars.'L Iinclude Llcd1;x6.'L Iinclude L isc.'L Iinclude Lisr.'L )oid ain *)oid+ M initNti er0*+ O lcd1;x6Ninit*+ O lcd1;x6Nclear*+ O lcd1;x6Ncursor*0x80+ O lcd1;x6N#riteNstring *LGeyL+ O lcd1;x6Ncursor*0x@0+ O -$ 1 1 O outNde) 1 0 O keyscande o 1 1 O #'ile *1+ M DI7,D$T$% 1 0x<< O kbd"lus'*+ O #'ile *keyNpress S1 1+ O -$ 1 0 O lcd1;x6Ncursor*0x@0+ O print" *L L+ O lcd1;x6Ncursor*0x@0+ O print" *L Uc L!key! *unsigned int+keycol!*unsigned int+keyro#+ O -$ 1 1 O i" *key 11 (<(+ M gpti eout 1 =000 O gpti eoutNdone 1 0 O #'ile *gpti eoutNdone S1 1+ O break O P P outNde) 1 1 O keyscande o 1 6 O

key 1 0 O #'ile *key S1 5+ M -$ 1 0 O DI7,M?4% 1 0x<% O dispselect 1 0 O dispNpointer 1 0 O print" *L7C?HC$ML+ O -$ 1 1 O displayNupdate 1 1 O #'ile *displayNupdate S1 0+ O gpti eout 1 B500 O gpti eoutNdone 1 0 O #'ile *gpti eoutNdone S1 1+ O keyQQ O P keyscande o 1 B O key 1 0 O #'ile *1+ M "or *dispNpointer 1 0 OdispNpointer J 8OdispNpointerQQ+ dispNbu""/dispNpointer0 1 dispN atrix/dispNpointer0 O displayNupdate 1 1 O #'ile *displayNupdate S1 0+ O P P

E+perime t *2 Aim: &rite a progra to display letter Z$[. So9t:are u!ed: Geil u)ision 6.1= and <las' Magic =.18.166= ,ro;ram: @,?L8051.TH5L CO<LI8T8L ,09 -V? 80C ,19 -V? A0C ,69 -V? 0$0C ,B9 -V? 0H0C .09 -V? 00C .19 -V? 01C .69 -V? 06C .B9 -V? 0BC .=9 -V? 0=C .59 -V? 05C .;9 -V? 0;C .%9 -V? 0%C D,59 -V? 86C D,C9 -V? 8BC O.F 0000C 7T.T9 MOD ,6!I%<C MOD ,1!I0<<C MOD ,B!I0<<C MOD ,0!I0<<C MOD ,0!I%-C MOD ,B!I0<-C $@$55 D5E MOD ,0!I%-C MOD ,B!I0<DC $@$55 D5E MOD ,0!I%-C MOD ,B!I0<HC $@$55 D5E MOD ,0!I0C MOD ,B!I0<%C $@$55 D5E MOD ,0!I%-C MOD ,B!I0-<C $@$55 D5E MOD ,0!I0%-C MOD ,B!I0D<C $@$55 D5E

MOD ,0!I0HDC MOD ,B!I0H<C $@$55 D5E MOD ,0!I0@BC MOD ,B!I0%<C $@$55 D5E 7WM, 7T.T D5E9 MOD .6!I0<<C ?,69 MOD .B!I0<<C ?,19 MOD .=!I05C C-.-9 DW8X .6!C-.DW8X .B!?,1 DW8X .6!?,6 .-T -8D

You might also like