Sei sulla pagina 1di 80

1. Program to toggle all the bits of PORT P1 continuously with 250ms delay. AI !

The basic program on a microcontroller is to operate the input and output functionality of the pins. AT89S51 is the controller having the 8051 architecture. In this pro ect !e are programming to control the output devices li"e #$%s such that& ma"e all pins of '()T '1 high at once and off at once. A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus ....

Theory!

Here we are using AT89S51 to glow an LED. For this simple project we ha e to !now the power "#$ %& o' an LED as to suppl( 'orm the controller. %n e er( project 'irst o' all we ha e to !now the operation o' each )e ice in)i i)uall( an) then em*e) them accor)ingl(. Working of an LED: A light+emitting )io)e "LED& is a semicon)uctor light source. LEDs are use) as in)icator lamps in man( )e ices an) are increasingl( use) 'or other lighting. ,hen a light+emitting )io)e is 'orwar)+*iase) "switche) on&$ electrons are a*le to recom*ine with electron holes within the )e ice$ releasing energ( in the 'orm o' photons. This e''ect is calle) electroluminescence an) the color o' the light "correspon)ing to the energ( o' the photon& is )etermine) *( the energ( gap o' the semicon)uctor. LEDs present man( a) antages o er incan)escent light sources inclu)ing lower energ( consumption$ longer li'etime$ impro e) ph(sical ro*ustness$ smaller si-e$ an) 'aster switching. Light+emitting )io)es are use) in applications as )i erse as a iation lighting$ automoti e lighting$ a) ertising$ general lighting$ an) tra''ic signals. LEDs ha e allowe) new te.t$ i)eo )ispla(s$ an) sensors to *e )e elope)$ while their high switching rates are also use'ul in a) ance) communications technolog(. %n'rare) LEDs are also use) in the remote control units o' man( commercial pro)ucts inclu)ing tele isions$ D#D pla(ers$ an) other )omestic appliances.LEDs wor! 'or a oltage greater than 1./# an) )epen) on the color$ 'or ma.imum *rightness we nee) 0.0# suppl(. Hence$ we nee) to suppl( more than 0.0# 'rom a controller. s*it+ This is the !e(wor) to assign an( pin to a aria*le. Working of AT89S51:

AT89S51 re1uires a oltage o' 5.2# an) 13# when programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller an) the consumption o' LED. The controller wor!s on 11.2593 4H- 're1uenc(. 5ote6 %t is suggeste) to use 522mA an) 13# D7 power suppl(.
Algorithm! 1. In this pro ect !e need to toggle all the bits of port1 of at89c51. -. To provide output& first !e need to clear the storage or available data in port register. /. To get output at port '1 assign logic 1 i.e.& 00ff to the '1 register as it is 8 bit register. ,. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle. 5. As to get toggling assign 0000 to '1 register. 6. 1o! apply the delay again to stabili7e logic 0 state of port. .. )epeat the steps / to 6 !hole in a continuous loop.

#ircuit $iagram!

Start

8lear the available data in reg '1& 2'1403.

Assigning #ogic 1 state to port '1 i.e.&2'1400ff3 %low chart!

If2cycl e:-50 ms3 ;alse Increment cycle i.e.& 8ycle4cycle91

True

Assigning #ogic 0 state to port '1 i.e.& 2'1400003

If2cycl e:-50 ms3

True

;alse Increment cycle i.e.& 8ycle4cycle91

Program! && ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' && Pro(ect! led interfacing to AT)*s51 && odule descri"tion! led interfacing

&& ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +include,reg51.h.oid clear/01 .oid delay/unsigned int01 .oid main/0 2

clear/01 while/10 2 P1304ff1 delay/560001 P2304001 delay/560001 7 7 .oid clear/0 2 P1304001 7 &&250msec && end of while loo" && end of main &&clearing all "orts &&250msec && infinite loo"

.oid delay/unsigned int c0 &&ma8ing c cycles delay 2 unsigned int d1 for/d3c1d9301d::01 7

2. Program to toggle only the bit P1.5 continuously with some delay. Use Timer 0, mode 1 to create delay. Aim!
In this article !e are dealing ho! to use a timer of controller in order to perform delay. A""aratus! 1. I%$ * +iel uvision ,.0&

-. Simulator* 'rofessional 'roteus ....

Theory!

Difference between software and hardware timer dela : First let us !now what the )i''erence *etween so'tware an) har)ware timer )ela(s. As so'tware timer is that$ a program which ma!es the controller not to )o an( tas!. 8ut 'irst o' all to run that )ela( program the processor ta!es some c(cles to e.ecute that )ela("& 'unction an) not sure completes the e.act )ela( we nee). Thus har)ware )ela( came into the picture.Here we are using in*uilt har)ware timers as we ha) two 1/ *it T%4E92$ T%4E91 timer to generate e.act )ela(. This concept o' har)ware timers were use) mostl( in satellite launching$ 5uclear reactors monitoring$ etc. !sing T"#E$% in AT89S51: %n or)er to ma!e wor!ing o' Timers we nee) two registers6 1& T7:5 "Timer count& 6

TF1 Timer 1 o er 'low 'lag which sets *( har)ware on Timer 1 o er'low an) is cleare) *( har)ware i' processor ectors to interrupt routine. TR1 Timer 1 run control *it which sets; cleare) *( so'tware to turn Timer 1 either <:5= or <:FF=. TF0 Timer 2 o er 'low 'lag which sets *( har)ware on Timer 2 o er'low an) is cleare) *( har)ware i' processor ectors to interrupt routine.& TR0 Timer 2 run control *it which sets ; cleare) *( so'tware to turn Timer 2 either <:5= or <:FF=. T4:D "timer mo)e&6

Gate: ,hen set$ timer;counter <.= is ena*le) onl( while <%5T .= pin is high an) <T9.= control *it is set. ,hen cleare) timer <.= is ena*le) whene er <T9.= control *it is set. C/T: 7ounter or timer select *it which sets 'or counter operation "input 'rom <T.= input pin&. 7leare) 'or timer operation "input 'rom internal s(stem cloc!&. M1 and M0: These *its are use) 'or selecting mo)e o' timer i.e.$ 8+*it timer or 1/+*it timer. 41>2$42>1+ acts as a 1/ *it manual reloa) timer$ 41>1$42>2+ acts as a 8 *it auto reloa) timer$ Difference &or 8'bit and 1('bit: %' 8+*it6 Here the timer counter starts at 2?22 an) en)s at 2.''.

%' 1/+*it6 Here the timer counter starts at 2?2222 an) en)s at 2.''''.

Algorithm!

1. In this article !e are dealing ho! to use a timer of controller in order to perform delay. -. To provide output& first !e need to clear the storage or available data in port register. /. 1o! !e need to design our firm!are such as our AT89c51 to initiali7e the internal ,. If user made a re<uest provide logic 1 through pin register'1=1to enable bu77er. 5. If user made a non re<uest provide logic 0 through pin register'1=1to disable bu77er. 6. )epeat the steps / to 5 !hole in a continuous loop.

%low chart! Start

8lear the available data in reg '1& 2'1403.

True TI>$)0?init23@

;alse

;lag4 0

#$%?lo!23

#$%?high23

$nd

#include<reg51.h> // Out Pin sbit Out = P1^0; //Functi n declarati ns ! id cct"init#! id$; ! id %nit&imer0#! id$; unsigned int c unt=0; int main#! id$ ' cct"init#$; Out=0; %nit&imer0#$; -hile#1$ ' / / ! id cct"init#! id$ ' P0 = 0000; P1 = 0000; P2 = 0000; P1 = 0000; / ! id %nit&imer0#! id$ '

// Pin P2.0 is named as Out

// (a)e all * rts +er // ,tart &imer0 // .est is d ne in &imer0 interru*t

&(O2 3= 00F0; &(O2 7= 0002; &80 = 0000; &90 = 0005; :&0 = 1; :; = 1; &.0 = 1;

// // // // // // //

4lear 5bit 6ield 6 r timer0 ,et timer0 in m de 2 250 usec rel ading time First time !alue :nable &imer0 interru*ts <l bal interru*t enable ,tart &imer 0

! id &imer0"%,. #! id$ interru*t 1 // %t is called a6ter e!er= 250usec ' c unt=c unt>1; i6#c unt==5000$ ' Out = ?Out; // & ggle Out *in c unt=0; / &F0 = 0; // 4lear the interru*t 6lag /

%low chart!

3). Program to interface a switch and a bu er to two different !ins of a Port such that the bu er should sound as long as the switch is !ressed.
Aim! The basic program on a microcontroller is to operate the input and output functionality of the pins. AT89S51 is the controller having the 8051 architecture. In this pro ect !e program to use

controller using input device as s!itch. If controller obtains an input it should sho! an output !ith the help of a pin i.e.& bu77er attaching to a particular pin. A""aratus! /. I%$ * +iel uvision ,.0& ,. Simulator* 'rofessional 'roteus ....

Theory!

Here we are using AT89S51as a controller which is controlle) *( a toggle switch "which gi es either *inar( 2 or1& an) respecti e output accor)ing to the input. For this simple project we ha e to !now the power "#$ %& o' an *u--er as to suppl( 'orm the controller an) power to suppl( 'rom the switch to the controller i.e.$ ,hat is # 'or logic high. %n e er( project 'irst o' all we ha e to !now the operation o' each )e ice in)i i)uall( an) then em*e) them accor)ingl(. Working of a switch: %nput 'or a controller using switches can *e )one in two wa(s. a&. @ull up$ *&. @ull )own. Working of )*ll Down: From the a*o e circuit we consi)er LED as our controller pin. ,hen the switch is presse)$ controller gets logic 1+which means 5,-. an) i' release) pin gets logic %+which means /0D thro*gh 11%ohms-2Thus @ull )own is nothing$ that the output will *e pull )own using a resistor i' no e.ternal e''ect. Working of )*ll Down: From the a*o e circuit we consi)er LED as our controller pin. ,hen the switch is presse)$ controller gets logic %+which means /0D-. an) i' release) pin gets logic 1+which means 35, thro*gh 11%ohms-2Thus @ull up is nothing$ that the output will *e pulle) up using a resistor i' no e.ternal e''ect. Working of AT89451: AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(.

Working of 5*66er: 5ote6 %t is suggeste) to use 522mA an) 13# D7 power suppl(.

Algorithm!

.. In this pro ect !e need to s!itch (1 bu77er !hen user enters re<uest using s!itch
provided to '1.0 of AT89c51.

8. To provide output& first !e need to clear the storage or available data in port register. 9. 1o! !e need to design our firm!are such as our AT89c51 has to verify !hether re<uest
provided by user or not.

10. If user made a re<uest provide logic 1 through pin register'1=1to enable bu77er. 11. If user made a non re<uest provide logic 0 through pin register'1=1to disable bu77er. 1-. )epeat the steps / to 5 !hole in a continuous loop.

Flowchart:
Start

8lear the available data in reg '1& 2'1403.

If2s!it ch441 3

True

Au77er40

;alse

;alse If2s!it ch440 3 True Au77er41

Program!
&& ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' && Pro(ect !;witch and bu<<er interfacing to AT)*s51 && ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +include,reg51.h.oid clear/01

sbit switch3P1=01

sbit bu<<er3P1=11 .oid main/0 2 clear/01 while/10 2 if/switch3310 2 bu<<er311 7 else if/switch3300 2 bu<<er301 7 7 7 .oid clear/0 2 P1304001 7 && end of while loo" && end of main &&clearing all "orts &&switch bu<<er O%% &&.erify switch condition &&switch bu<<er O> &&.erify switch condition && infinite loo"

". Program to interface #$% data !ins to !ort P1 and dis!lay a message on it.
AI ! In this pro ect !e !ill be dealing !ith 16B- #8% display 2#> 016#3& and embedding it to our AT89S51. ;or !hich !e consider an application as to display a name on #8%. A""aratus! 1. I%$ * +iel uvision ,.0&

-. Simulator* 'rofessional 'roteus ....

Theory!

Here we are using AT89S51 to control the L4 21/L. For our application$ 'irst we want to !now a*out the L421/L which wor!s on the principle o' pi.el matri. that can *e controlle) using internal comman)s o' particular L7D. Working of a L4D: L7D "Li1ui) 7r(stal Displa(& screen is an electronic )ispla( mo)ule an) 'in) a wi)e range o' applications. A 1/?3 L7D )ispla( is er( *asic mo)ule an) is er( commonl( use) in arious )e ices an) circuits. These mo)ules are pre'erre) o er se en segments an) other multi segment LEDs. The reasons *eing6 L7Ds are economical$ easil( programma*le$ ha e no limitation o' )ispla(ing special A e en custom characters "unli!e in se en segments&$ animations an) so on. A 162 LCD means it can )ispla( 1/ characters per line an) there are 3 such lines. %n this L7D each character is )ispla(e) in 5?B )ot matri.. This L7D has two registers$ namel($ 7omman) an) Data. The comman) register stores the comman) instructions gi en to the L7D. A comman) is an instruction gi en to L7D to )o a pre)e'ine) tas! li!e initiali-ing it$ clearing its screen$ setting the cursor position$ controlling )ispla( etc. The )ata register stores the )ata to *e )ispla(e) on the L7D. The )ata is the AS7%% alue o' the character to *e )ispla(e) on the L7D.

As$ )ot matri. ha ing negati e rows an) positi e columns$ here in the a*o e 5?B )ot matri. we supplie) C5# to select 0r) column an) Dn) to 1st$ 0r)$ Eth$ 5th $/th an) Bth rows. %n the same pattern L4 21/L ha) 03 5?8 )ot matrices *( which we can iew 03 characters at a time. All the characters are pre)e'ine) in the 9A4 memor( o' the L4 21/L. Working of AT89451:

AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(.
Algorithm! 1. In this pro ect !e need to display a message on #8%2#>016>3 using port '1 of AT89c51 as data port and port '- as configuration port . -. To provide output& first !e need to clear the storage or available data in port '1&'register. /. ;rom the datasheet provided !ith #>016> to configure and display data on #8% !e need to use configuration& data pins to get desired output on #8% according to cloc" signals provided in datasheet. ,. According to #>016> datasheet of #8% to get display !e need to use $nable2$13& readC!rite2)CD3& status register2)S3 and %0E%82data pins3. 5. As #8% !or"s on parallel communication !e are using !hole port '1 for data sharing to #8%.

;chematic!

Start

8lear the available data in reg '1& 2'1403.

1
%low chart! ;alse

True

#cdinit23@

!ritedata2F1F3@ CC!rite !ritedata2F)F3@ !ritedata2FIF3@ CC!rite )eturn23@

$nd

Program:
CC 55555555555555555555555555555555555555555555555555555555555 CC 'ro ect* #8% 8bit CC Author* sudheer

CC >odule description* (perate #8% in 8bit mode CC 55555555555555555555555555555555555555555555555555555555555

GincludeHreg51.h:

CC;unction declarations void cct?init2void3@ void delay2int3@ void lcdinit2void3@

void !ritecmd2int3@ void !ritedata2char3@ void )eturnIome2void3@

CC5555555555555555555 CC'in description C5 '1 is data bus '-.0 is )S '-.1 is $ 5C CC55555555555555555555

CC %efines 'ins sbit )S 4 '-=0@ sbit $ 4 '-=1@ sbit r! 4 '-=-@ CC 55555555555555555555555555555555555555555555555555555555555 CC >ain program CC void main2void3 J r!40@ cct?init23@ CC>a"e all ports 7ero

lcdinit23@

CCInitili7e #8%

!ritedata2FiF3@ !ritedata2F F3@ !ritedata2FbF3@ !ritedata2FlF3@ !ritedata2FoF3@ !ritedata2FcF3@ !ritedata2F"F3@ !ritedata2FKF3@ !ritedata2FsF3@

CC!rite

CC!rite

CC!rite CC!rite

CC!rite

)eturnIome23@

CC)eturn to 0 position

!hile213 J L

L void cct?init2void3 J '0 4 0000@ CCnot used '1 4 0000@ CCnot used '- 4 0000@ CCused as data port '/ 4 0000@ CCused for generating $ and )S L void delay2int a3 J

int i@ for2i40@iHa@i993@ CCnull statement L

void !ritedata2char t3 J )S 4 1@ '1 4 t@ $ 4 1@ delay21503@ $ 4 0@ delay21503@ L CC 4: $ 4 0 CC 4: )S 4 1 CC%ata transfer CC 4: $ 4 1

void !ritecmd2int 73 J )S 4 0@ '1 4 7@ $ 4 1@ delay21503@ $ 4 0@ delay21503@ L CC 4: $ 4 0 CC 4: )S 4 0 CC%ata transfer CC 4: $ 4 1

void lcdinit2void3

J CCCCCCCCCCCCC )eset process from datasheet CCCCCCCCC delay2150003@ !ritecmd200/03@ delay2,5003@ !ritecmd200/03@ delay2/003@ !ritecmd200/03@ delay26503@ CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC !ritecmd200/83@ !ritecmd2000c3@ !ritecmd200013@ !ritecmd200063@ L CCfunction set CCdisplay on&cursor off&blin" off CCclear display CCentry mode& set increment

void )eturnIome2void3 J !ritecmd2000-3@ delay215003@ L

CC)eturn to 0 location

5 Program to !nter"ace #e$%ad &hene'er a #e$ !( %re((ed) !t (ho*ld +e d!(%la$ed on LCD

AI ! In this pro ect !e !ill be dealing !ith 44 keypad& and embedding it to our AT89S51. Mou are developing an embedded application using one or more members of the 8051 family of microcontrollers. The application has a timeEtriggered architecture& constructed using a scheduler. De are creating the user interface for your application. ;or !hich !e consider an application as to display the input "ey in the #8%. A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus ....

Theory!

Here we are using AT89S51 to control the 787 ke 9ad. For our application$ 'irst we want to !now a*out the 787 ke 9ad which wor!s on the principle o' switching concept. Working of a :e 9ad:

,e are concerne) here with !e(pa)s ma)e up o' a matri. o' switches$ in an arrangement similar to that illustrate). The matri. arrangement is use) to sa e port pins. %' we ha e 9 rows an) 7 columns o' !e(s$ we nee) 9 C 7 pins i' we use a matri. arrangement an) 9 ? 7 pins i' we use in)i i)ual switches. %' (ou nee) si. or more !e(s$ then the matri. arrangement re1uires 'ewer pins. 4an( !e(pa)s ha e 13 !e(s "<2=F<9= plus two 'unction !e(s F t(picall( <G= an) <H=&. Ising a matri. arrangement$ this re1uires se en port pins. The !e(s ma( *ounce$ when presse) an)

release). The )uration o' the !e( press will generall( *e at least 522 ms. The !e(s will not generall( *e allowe) to <auto repeat=6 this can *e er( con'using 'or users. ,e ma( wish the user to *e a*le to press one or more <'unction !e(s= in com*ination with other !e(s. Suppose$ we wish to see i' the !e( <1= is presse). ,e can procee) as 'ollows6 H ,e set the correspon)ing output pin "in this case$ @in /& to a Logic 2 alue an) the remaining output pins to a Logic 1 alue. H ,e rea) the re1uire) input pin "in this case$ @in 2&. %' this pin is a Logic 1$ then the !e( <1= is not presse)6 the Logic 1 alue is$ instea)$ o*taine) ia the pull+up resistor on the port pin. %' this pin is at Logic 2$ then the !e( is *eing presse) "su*ject to )e *ounce consi)erations&6 the Logic 2 oltage rea)ing results 'rom the Logic 2 oltage output on @in /.,e must repeat the rea)ing "sa(& 322 ms later$ to allow 'or switch *ounce. ,e nee) to repeat this process 'or e er( !e(. Listing 32.1 illustrates one wa( o' per'orming this scanning 'or the whole !e(pa). ,e$%ad (cann!ng:

At the heart o' an( !e(pa) co)e is a scanning 'unction6 this will t(picall( go through each column in turn an) i)enti'( i' an( !e( in that column has *een presse). %n a*o e 'igure$ the num*ers a)jacent to the rows an) column in)icate the port pins to which the !e(pa) shoul) *e connecte). @ins 2$ 1 an) 3 "the columns& will *e re'erre) to here as the output pins6 these are written to )uring the scanning process. @ins 0$ E$ 5 an) / will *e re'erre) to as the input pins6 these are rea) )uring the scanning process. Working of AT89S51:

AT89S51 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(.
Algorithm! 1. In this pro ect !e need to interface "eypad to the 8051 and produce scanned "ey on #8%. -. ;irst !e need to clear the storage or available data in port register. /. To get scan !e need to use ro! of "eypad as input and column of "eypad as output. ,. Scan each ro! by interchanging output data of column and store the "ey in memory. 5. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle. 6. 1o! initiali7e the #8% and push the data in memory to #8% to display. .. )epeat the steps , to 6 !hole in a continuous loop.

-chemat!c:

Start

Flow chart:
8lear the available data in reg '1& 2'1403.

True

#cdinit23@

NA)Tinitialise23@ ;alse >emory4read23@

#cddata2memory3@

$nd

Program! GincludeHreg51.h: Ginclude Klcd.hK sbit c,4 '1=,@ sbit c/4 '1=5@ sbit c-4 '1=6@ sbit c14 '1=.@ sbit r14 '1=0@ sbit r-4 '1=1@ sbit r/4 '1=-@ sbit r,4 '1=/@ void delay2int3@

void main23 J lcdinit23@ !hile213 CC infinite loop J c,41@ c/41@ c-40@ c141@ if2r14403 J !ritecmd200013@ !ritedata2F/F3@CC L else if2r-4403 J !ritecmd200013@ !ritedata2F.F3@ L

else if2r/4403 J !ritecmd200013@ !ritedata2F1F3@

!ritedata2F1F3@ L

else if2r,4403 J !ritecmd200013@ !ritedata2F1F3@

!ritedata2F5F3@ L

c,41@ c/40@ c-41@ c141@ if2r14403 J !ritecmd200013@ !ritedata2F-F3@ CC L else if2r-4403 J !ritecmd200013@

!ritedata2F6F3@ L

else if2r/4403 J !ritecmd200013@ !ritedata2F1F3@

!ritedata2F0F3@

else if2r,4403 J !ritecmd200013@ !ritedata2F1F3@

!ritedata2F,F3@ L

c,40@ c/41@ c-41@ c141@ if2r14403 J !ritecmd200013@ !ritedata2F1F3@CC L else if2r-4403 J !ritecmd200013@ !ritedata2F5F3@ L

else if2r/4403 J!ritecmd200013@ !ritedata2F9F3@ L

else if2r,4403 J!ritecmd200013@ !ritedata2F1F3@ !ritedata2F/F3@ L c,41@ c/41@ c-41@ c140@ if2r14403 J !ritecmd200013@ !ritedata2F,F3@CC L else if2r-4403 J !ritecmd200013@ !ritedata2F8F3@ L

else if2r/4403 J !ritecmd200013@

!ritedata2F1F3@

!ritedata2F-F3@ L

else if2r,4403 J !ritecmd200013@ !ritedata2F1F3@

!ritedata2F6F3@ L LCC end of !hile loop

L CC end of main

void delay2int i3 J for2@i:0@iEE3@ L

&. Program to interface se'en segment dis!lay unit.


Aim! A seven segment display is the most basic electronic display device that can display digits from 0E9. They find !ide application in devices that display numeric information li"e digital cloc"s& radio& micro!ave ovens& electronic meters etc. The most common configuration has an array of eight #$%s arranged in a special pattern to display these digits. They are laid out as a s<uaredEoff figure O8P. $very #$% is assigned a name from OaP to OhP and is identified by its name. Seven #$%s OaP to OgP are used to display the numerals !hile eighth #$% OhP is used to display the dotCdecimal. A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus ....

Theor$:

Here we are using AT89S51 to control the B+segment )ispla(. For our application 'irst we nee) to !now a*out the B+segment )ispla( wor!ing. Working of a ;segment dis9la : Bsegment is generall( a aila*le in ten pin pac!age. ,hile eight pins correspon) to the eight LEDs$ the remaining two pins "at mi))le& are common an) internall( shorte). These segments come in two con'igurations$ namel($ 7ommon catho)e "77& an) 7ommon ano)e "7A&. %n 77 con'iguration$ the negati e terminals o' all LEDs are connecte) to the common pins. The common is connecte) to groun) an) a particular LED glows when its correspon)ing pin is gi en high. %n 7A arrangement$ the common pin is gi en a high logic an) the LED pins are gi en low to )ispla( a num*er. Working of AT89451: AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(. The current supplie) to the B segment is also to *e consi)ere) as it is )ri en *( the controller. %' su''icient current is not supplie) it e''ects *( the fano*t2

Working of ;Segment: a-24ommon 4athode:

As shown in the a*o e circuit B segment ha ing a$ *$ c$ )$ e$ '$ g pins can *e ena*le) using C5# high so that respecti e regions will *e acti ate). As this is a 77 "7ommon 7atho)e&$ the common pin is groun)e)$ an) to operate it we nee) to suppl( positi e oltage. b-24ommon Anode:

As shown in the a*o e circuit B segment ha ing a$ *$ c$ )$ e$ '$ g pins can *e ena*le) using Dn) i.e.$ logic % so that respecti e regions will *e acti ate). As this is a 7A "7ommon Ano)e&$ the common pin is gi en a positi e oltage C5#$ an) to operate it we nee) to suppl( Dn) or logic %. "nterfacing With AT89S51: %n the a*o e circuit we are using a 7ommon 7atho)e t(pe 'our B segment )ispla(. To operate this )ispla( here we are using @ort3 pins 'rom which we pro i)e C5# to the )ispla(. As our application is to )ispla( )ecimal )igits we 'irst ha e to ma!e a co)e o' each )ecimal )igit. For e.ample$ in or)er to )ispla( <1= we want to acti ate b. c segments placing all to *e inacti e. %n this wa($ we can )ispla( our )esire) character *( acti ating respecti e segments. Here in our application we are co)ing respecti e segments to )ispla( all )ecimal )igits one a'ter other with certain )ela(. Here as we are inter'acing 'our Bse en segment )ispla(s using a single port$ we nee) to use ill*sion techni1ue. The project can *e )one *( these steps6 1. First connect 'our Bsegment )ispla(s to a single port an) selection pins to other port. 3. ,hen (ou want to )ispla( )ata on one segment switch the correspon)ing selection pin. 0. A'ter some )ela( switch the other segment. 8( placing er( less )ela( we 'eel that *oth the segment to *e )ispla(e).

Program:
#include<reg51.h> // Functi n declarati ns ! id clear#! id$; ! id dela=#int$; int ,egment#char$; sbit s1=P1^0; // Pin descri*ti n /@ P2 is used 6 r A segment P2.0 is attached -ith B;B segment P2.1 is attached -ith BCB segment P2.2 is attached -ith B4B segment P2.1 is attached -ith B2B segment P2.5 is attached -ith B:B segment P2.5 is attached -ith BFB segment P2.D is attached -ith B<B segment @/ // (ain 6uncti n int main#! id$ ' char h; clear#$; -hile#1$ '

// 4haracter t be dis*la=ed // (a)e all * rts +er

n Aseg

/ /

6 r#h=0000;h<000E;h>>$ ' dela=#20000$; s1=0; ,egment#h$; dela=#20000$; /

! id clear#! id$ ' P0 = 0000; P1 = 0000; P2 = 0000; P1 = 0000; / ! id dela=#int a$ ' int i; 6 r#i=0;i<a;i>>$; /

//null statement BFB nl=

int ,egment#char ch$ // ch can ha!e a !alue 6r m B0B t ' s-itch#ch$ ' case 0F P1 = ?0016; brea); case 1F P1 = ?000D; brea);

case 2F P1 = ?005C; brea); case 1F P1 = ?005F; brea); case 5F P1 = ?00DD; brea); case 5F P1 = ?00D2; brea); case DF P1 = ?00A2; brea); case AF P1 = ?000A; brea); case GF P1 = ?00AF; brea); case EF P1 = ?00DF; brea); /@case 000aF P2 = 00AA; brea); case 000bF P2 = 00A4; brea); case 000cF P2 = 001E; brea); case 000dF P2 = 005:; brea); case 000eF P2 = 00AE; brea); case 0006F P2 = 00A1; brea); @/ de6aultF P1 = 0016; brea); / return#0$; /

Schematic:

Flowchart:

Start

8lear the available data in reg '1& 2'1403.

True Seven segment init23@

;alse %isplay segment23@

$nd

Algorithm! 1. In this pro ect !e need to interface seven segment display to at89c51.

-. ;irst !e need to clear the storage or available data in port register. /. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle. ,. As NA)T !or"s !ith some properties as baudrate& datalength& parity& stop and start bits& no! !e need to provide all. 5. To get baudrate !e use internal TI>$)1& and remaining properties using respected registers. 6. 'ush the data to NA)T data register !hich !ill send data to '8. .. )epeat the steps 6 in a continuous loop.

. Program to tran(m!t a me((age "rom M!crocontroller to PC (er!all$ *(!ng R-2/2

AI ! In this part& !e !ill consider some "ey patterns suitable for assisting in the creation of user interfaces for a !ide range of embedded applications. De present P# ?I>@ /R;:2520.This pattern considers ho!& using the universal O)SE-/-P standard& !e can transfer data bet!een an embedded device and a des"top& noteboo" or similar '8. In addition to being a useful pattern in its o!n right& this pattern illustrates many of the features re<uired in soft!are developed for a cooperatively scheduled environment. A""aratus! /. I%$ * +iel uvision ,.0& ,. Simulator* 'rofessional 'roteus .... Theory!

Here we are inter'acing our AT89S51 to a @7 in or)er to trans'er the )ata *etween them. %n man( applications li!e D@S trac!ing$ ,ireless communication )ata trans'er$ etc$ we can use this technolog( to trans'er the )ata. Working conce9t of !A$T and $S<1<:

%n 199B the Telecommunications %n)ustr( Association release) what is 'ormall( !nown as T%A+ 303 #ersion F$ a serial communication protocol which has *een 0/3 THE ISE9 %5TE9FA7E. This 'ile ma( *e 'reel( re)istri*ute) pro i)e) onl( that this 'ooter remains intact. uni ersall( re'erre) to as <9S+303= since its 'irst <9ecommen)e) Stan)ar)= appeare) in the 19/2s. Similar stan)ar)s "#.38& are pu*lishe) *( the %nternational Telecommunications Inion "%TI& an) *( 77%TT "7onsultati e 7ommittee %nternational Telegraph an) Telephone&. The <9S+303= stan)ar) inclu)es )etails o'6

The protocol to *e use) 'or )ata transmission. The oltages to *e use) on the signal lines. The connectors to *e use) to lin! e1uipment together.

: erall$ the stan)ar) is comprehensi e an) wi)el( use)$ at )ata trans'er rates o' up to aroun) 115 or 002 !*its ; secon) "115 ; 002 ! *au)&. Data trans'er can *e o er )istances o' 15 metres or more. 5ote that 9S+303 is a peer+to+peer communication stan)ar). 9S+303 is inten)e) to lin! onl( two )e ices together un)er )uple. technolog(. 0a(!c R-12/2 %rotocol:1 9S+303 is a character+oriente) protocol. That is$ it is inten)e) to *e use) to sen) single 8+*it *loc!s o' )ata. To transmit a *(te o' )ata o er an 9S+303 lin!$ we generall( enco)e the in'ormation as 'ollows6

,e sen) a <Start= *it. ,e sen) the )ata "8 *its&. ,e sen) a <Stop= *it "or *its&. For securit( we a)) parit( *its.

R-12/2 'oltage le'el(:1 The threshol) le els use) *( the recei er are C0# an) +0# an) the lines are in erte). The ma.imum oltage allowe) is C;+ 15#. 5ote that these oltages cannot *e o*taine) )irectl( 'rom the na!e) microcontroller port pins$ some 'orm o' inter'ace har)ware is re1uire). For e.ample$ the 4a.im 4a.303 an) 4a.300 are popular an) wi)el( use) line )ri er chipsJ we consi)er how to use such chips in <Solution=. Although har)ware han)sha!ing can *e use)$ this re1uires e.tra signal lines. The most common 'low control techni1ue is <Kon ; Ko''= control. This re1uires a hal'+ or 'ull+)uple. communication lin!$ an) can operate as 'ollows6 12 Transmitter sen)s a *(te o' )ata.

22 The recei er is a*le to recei e more )ata6 it )oes nothing. /2 The transmitter sen)s another *(te o' )ata. 32 Steps 1F0 continue until the recei er cannot accept an( more )ata6 it then sen)s a <7ontrol s= "Ko''& character *ac! to the transmitter. 52 The transmitter recei es the <Ko''= comman) an) pauses the )ata transmission. 62 ,hen the recei er no)e is rea)( 'or more )ata$ it sen)s a <7ontrol 1= "Kon& character to the transmitter. .2 The transmitter resumes the )ata transmission. 42 The process continues 'rom Step "1&. 8elow is the circuit )iagram 'or connecting controller to @7 using 9S303. The *au) rate is )etermine) *( the Timer 1 o er'low rate an) the alue o' S4:D 'ollows6 This is the calculation o' AT89S51 'or 9/22 *au) rate$ 'rom where we coul) get TH1 which is use) in programming 'or Timer1. Working of AT89451: AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(.
Algorithm! 8. In this pro ect !e need to interface '8 to 8051 using NA)T protocol. 9. ;irst !e need to clear the storage or available data in port register. 10. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle. 11. As NA)T !or"s !ith some properties as baudrate& datalength& parity& stop and start bits& no! !e need to provide all. 1-. To get baudrate !e use internal TI>$)1& and remaining properties using respected registers.

1/. 'ush the data to NA)T data register !hich !ill send data to '8. 1,. )epeat the steps 6 in a continuous loop.

-chemat!c:

Start

8lear the available data in reg '1& 2'1403.

True

#cdinit23@

NA)Tinitialise23@ ;alse Tranmit2memory3

$nd

Program! CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCC CC 'ro ect* Internet to serial port 8ontrol CC

CC Author* )aghava )eddy CC %ate* 1,C11C-010 CC

CC

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

Ginclude Hreg51.h:

CC%$;I1$ 8(1STA1T Gdefine Aaud?rate 00;d CC AAN% )AT$ 9600

CC%$;I1$ ')(T(TM'$S void NSA)T?Init2void3@ void NSA)T?Transmit2unsigned char3@ void cct?init2void3@ void delay2unsigned int t3@

void main23 J cct?init23@ NSA)T?Init23@ $A 4 1@ $S 4 1@ !hile213 J NSA)T?Transmit2F1F3@

delay21003@ NSA)T?Transmit2F)F3@ delay21003@ NSA)T?Transmit2FIF3@ delay21003@ NSA)T?Transmit2F F3@ delay21003@ L L

void delay2unsigned int t3 J unsigned int i& @ for2i40@iHt@i993 J for2 40@ H50@ 993@ L L

void cct?init2void3 CCinitiali7e cct J '0 4 0000@ CCnot used '1 4 0000@ CCNsed for Appliances '- 4 0000@ CCnot used '/ 4 000/@ CCused for serial

void NSA)T?Init2void3 J T>(% 4 000-@ AAN% )AT$ S8(1 4 0050@ AIT& )$1 $1AA#$% TI0 4 Aaud?rate@ T)0 4 1@ L

CC I1ITIA#IQ$ S$)IA# '()T

CC Timer 1 I1 >(%$ - EANT( )$#(A% T( R$1$)AT$ CC S$)IA# >(%$ 1& 8E%ATA AIT 1ESTA)T AIT& 1EST(' CC #(A% AAN%)AT$ T( TI>$) )$RIST$) CC STA)T TI>$)

void NSA)T?Transmit2unsigned char serialdata3 J SAN; 4 serialdata@ )$RIST$) !hile2TI 44 03@ 8(>'#$T$ TI 4 0@ ;#AR L CC #(A% %ATA T( S$)IA# AN;;$) CC DAIT N1TI# T)A1S>ISSI(1 T( CC 8#$A) T)A1S>ISSI(1 I1T$))N'T

4 Program to rece!'e a me((age "rom PC (er!all$ *(!ng R-2/2

5!m: %n this part$ we will consi)er some !e( patterns suita*le 'or assisting in the creation o' user inter'aces 'or a wi)e range o' em*e))e) applications. ,e present PC L67, 8R-12/22.This pattern consi)ers how$ using the uni ersal <9S+303= stan)ar)$ we can trans'er )ata *etween an em*e))e) )e ice an) a )es!top$ note*oo! or similar @7. %n a))ition to *eing a use'ul pattern in its own right$ this pattern illustrates man( o' the 'eatures re1uire) in so'tware )e elope) 'or a cooperati el( sche)ule) en ironment. %n this project to eri'( the )ata recei e) we use % *loc!=s L7D to show the respecte) output.
A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus ....

Theor$: Here we are inter'acing our AT89S51 to a @7 in or)er to trans'er the )ata *etween them. %n man( applications li!e D@S trac!ing$ ,ireless communication )ata trans'er$ etc$ we can use this technolog( to trans'er the )ata. Working conce9t of !A$T and $S<1<: %n 199B the Telecommunications %n)ustr( Association release) what is 'ormall( !nown as T%A+ 303 #ersion F$ a serial communication protocol which has *een 0/3 THE ISE9 %5TE9FA7E. This 'ile ma( *e 'reel( re)istri*ute) pro i)e) onl( that this 'ooter remains intact. uni ersall( re'erre) to as <9S+303= since its 'irst <9ecommen)e) Stan)ar)= appeare) in the 19/2s. Similar stan)ar)s "#.38& are pu*lishe) *( the %nternational Telecommunications Inion "%TI& an) *( 77%TT "7onsultati e 7ommittee %nternational Telegraph an) Telephone&. The <9S+303= stan)ar) inclu)es )etails o'6

The protocol to *e use) 'or )ata transmission. The oltages to *e use) on the signal lines. The connectors to *e use) to lin! e1uipment together.

: erall$ the stan)ar) is comprehensi e an) wi)el( use)$ at )ata trans'er rates o' up to aroun) 115 or 002 !*its ; secon) "115 ; 002 ! *au)&. Data trans'er can *e o er )istances o' 15 metres or more. 5ote that 9S+303 is a peer+to+peer communication stan)ar). 9S+303 is inten)e) to lin! onl( two )e ices together un)er )uple. technolog(.L 0a(!c R-12/2 %rotocol:1 9S+303 is a character+oriente) protocol. That is$ it is inten)e) to *e use) to sen)

single 8+*it *loc!s o' )ata. To transmit a *(te o' )ata o er an 9S+303 lin!$ we generall( enco)e the in'ormation as 'ollows6

,e sen) a <Start= *it. ,e sen) the )ata "8 *its&. ,e sen) a <Stop= *it "or *its&. For securit( we a)) parit( *its.

R-12/2 'oltage le'el(:1 The threshol) le els use) *( the recei er are C0# an) +0# an) the lines are in erte). The ma.imum oltage allowe) is C;+ 15#. 5ote that these oltages cannot *e o*taine) )irectl( 'rom the na!e) microcontroller port pins$ some 'orm o' inter'ace har)ware is re1uire). For e.ample$ the 4a.im 4a.303 an) 4a.300 are popular an) wi)el( use) line )ri er chipsJ we consi)er how to use such chips in <Solution=. Although har)ware han)sha!ing can *e use)$ this re1uires e.tra signal lines. The most common 'low control techni1ue is <Kon ; Ko''= control. This re1uires a hal'+ or 'ull+)uple. communication lin!$ an) can operate as 'ollows6 12 Transmitter sen)s a *(te o' )ata. 22 The recei er is a*le to recei e more )ata6 it )oes nothing. /2 The transmitter sen)s another *(te o' )ata. 32 Steps 1F0 continue until the recei er cannot accept an( more )ata6 it then sen)s a <7ontrol s= "Ko''& character *ac! to the transmitter. 52 The transmitter recei es the <Ko''= comman) an) pauses the )ata transmission. 62 ,hen the recei er no)e is rea)( 'or more )ata$ it sen)s a <7ontrol 1= "Kon& character to the transmitter. .2 The transmitter resumes the )ata transmission. 42 The process continues 'rom Step "1&. 8elow is the circuit )iagram 'or connecting controller to @7 using 9S303.

The *au) rate is )etermine) *( the Timer 1 o er'low rate an) the alue o' S4:D 'ollows6

This is the calculation o' AT89S51 'or 9/22 *au) rate$ 'rom where we coul) get TH1 which is use) in programming 'or Timer1.

Working of AT89451: AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(.

5lgor!thm:
1. In this pro ect !e need to interface '8 to 8051 using NA)T protocol. -. ;irst !e need to clear the storage or available data in port register. /. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle. ,. As NA)T !or"s !ith some properties as baudrate& datalength& parity& stop and start bits& no! !e need to provide all. 5. To set baudrate !e use internal TI>$)1& and remaining properties using respected registers. 6. 1o! read the data from '8 using NA)T data register and store in a memory. .. 1o! initiali7e the #8% and push the data in memory to #8% to display. 8. )epeat the steps 6E. in a continuous loop.

-chemat!c:

Start

8lear the available data in reg '1& 2'1403.

True

#cdinit23@

NA)Tinitialise23@ ;alse >emory4read23@

#cddata2memory3@

$nd

Program:
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCC CC 'ro ect* Internet to serial port 8ontrol CC CC Author* )aghava )eddy CC %ate* 1,C11C-010 CC CC

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

Ginclude Hreg5-.h: G include Klcd.hK CC%$;I1$ 8(1STA1T Gdefine Aaud?rate 00;% CC AAN% )AT$ 9600 void NSA)T?Init2void3@

void t02unsigned char3@ unsigned char r023@ unsigned char aS1-T@ void clear2void3@

int main2void3 J unsigned char &i40@ clear23@ NSA)T?Init23@ lcdinit23@ CC$A 4 1@ CC$S 4 1@ CC !ritedata2F?F3 @ !hile213 J i4r023@ !ritedata2i3@ L L

void clear2void3 CCinitiali7e cct J '0 4 0000@ CCnot used '1 4 0000@ CCNsed for Appliances

'- 4 0000@ CCnot used '/ 4 000/@ CCused for serial L

void NSA)T?Init2void3 J T>(% 4 00-0@ AAN% )AT$ S8(1 4 0050@ 1EST(' AIT TI1 4 Aaud?rate@ T)1 4 1@ L

CC I1ITIA#IQ$ S$)IA# '()T

CC Timer 1 I1 >(%$ - EANT( )$#(A% T( R$1$)AT$ CC S$)IA# >(%$ 1& 8E%ATA AIT 1ESTA)T AIT& CC #(A% AAN%)AT$ T( TI>$) )$RIST$) CC STA)T TI>$)

void t02unsigned char serialdata3 J SAN; 4 serialdata@ )$RIST$) !hile2TI 44 03@ 8(>'#$T$ TI 4 0@ ;#AR L CC #(A% %ATA T( S$)IA# AN;;$) CC DAIT N1TI# T)A1S>ISSI(1 T( CC 8#$A) T)A1S>ISSI(1 I1T$))N'T

unsigned char r023 J !hile2)I4403@ )I40@

return2SAN;3@ L

*.A$#!

AT89s51 micrrocontroller doesnt have inbuilt A%8. So !e need to interface an I8 called A%8 080, in order to perform A%8 !ith AT89S5.This pro ect deals !ith A%8 080, by !hich !e can interface all electronic transducers& that acts as sensors.

Working of AD4%8%7: Di''erential analog oltage inputs allow increasing the common+mo)e rejection an) o''setting the analog -ero input oltage alue. %n a))ition$ the oltage re'erence input can *ea)juste) to allow enco)ing an( smaller analog oltage span to the 'ull 8 *its o' resolution. Feat*re(:

logic nee)e) F access time F 105 ns Eas( inter'ace to all microprocessors$ or operates Mstan)aloneN Di''erential analog oltage inputs Logic inputs an) outputs meet *oth 4:S an) TTL oltage le el speci'ications ,or!s with 3.5# "L400/& oltage re'erence :n+chip cloc! generator 2# to 5# analog input oltage range with single 5# suppl( 5o -ero a)just re1uire) 2.0O stan)ar) wi)th 32+pin D%@ pac!age 32+pin mol)e) chip carrier or small outline pac!age :perates ratio metricall( or with 5 #D7$ 3.5 #D7$ or analog span a)juste) oltage re'erence.

From a*o e timing )iagram we can anal(-e the 'low o' the AD7 con ersion.

For rea)ing the )ata 'rom AD7 we 'irst nee) to ena*le the AD7 to ac1uire )ata 'rom trans)ucer so that we nee) to )isa*le connection it to 9EAD$ then ,9%TE the instruction to ac1uire )ata$ a'ter some time ena*le 9EAD comman) so that controller rea)s the con erte) )ata. 5ow ena*le it to interrupt to )isconnect controller )ata communication.

Thus the programming woul) *e$ r)>2J wr>1J )ela(J ;;ma!es controller to rea) ;; ma!e AD7 to write into its *u''er a'ter certain )ela( ;;pro i)e some )ela(

wr>2J 'irst )ata

;;)isa*les the connection with trans)ucer in or)er not to o erwrite

while"intr>>1&J ;;waits till whole *u''er to 'ill using interrupt r)>1J )ela(J intr>1J ;;rea)s )ata to the controller ;; pro i)e some )ela( ;;ma!e interrupt high to )isconnect

Working of AT89451: AT89751 re1uires a oltage o' 5.2# e en programming the microcontroller. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller .The controller wor!s on 11.2593 4H- 're1uenc(. Here we are inter'acing AD7282E which rea)s )ata temperature 'rom L405 with AT89S51 an) )ispla(ing respecti e )ata using L7D "L4 21/L& programming which we !nown inter'acing it earlier.

,e can implement the same technolog( 'or inter'acing trans)ucers li!e LD9$ A@E131B/2 "'ire sensor&$ SE5+103B "gas sensor& 7ote:

@lease )on=t connect motors an) A7 loa)s )irectl( to controllers as the( operates at highwatt power. Don=t connect D7 5# motor )irectl( to controller as motors pro)uce back emf while running.

Flow Chart:

Start

8lear the available data in reg '1& 2'1403.

True #cdinit23@

Adc?init23@ ;alse >emory4)ead ?adc23@

#8%?data2memory3

$nd

Program:
#include<reg51.h> #de6ine * rt P1 #de6ine adc"in*ut P1 #de6ine data* rt P0 #de6ine sec 100 sbit rs = * rt^0; sbit r- = * rt^1; sbit e = * rt^2; sbit -r= * rt^5; sbit rd= * rt^1; sbit intr= * rt^5; int test"intermediate1=0H test"6inal=0Htest"intermediate1I10JHtest"intermediate2I1J='0H0H0/; ! id dela=#unsigned int msec $ ' int i HK ; 6 r#i=0;i<msec;i>>$ 6 r#K=0; K<12A5; K>>$; / ! id lcd"cmd#unsigned char item$ //Functi n t send c mmand t 942 ' data* rt = item; rs= 0; r-=0; e=1; dela=#1$; e=0; return; / ! id lcd"data#unsigned char item$ //Functi n t send data t 942 ' data* rt = item; rs= 1; r-=0; e=1; dela=#1$; e=0;

//dela=#100$; return; / ! id lcd"data"string#unsigned char @str$ // Functi n t send string t 942 ' int i=0; -hile#strIiJL=BM0B$ ' lcd"data#strIiJ$; i>>; dela=#10$; / return; / ! id sha*e#$ // Functi n t create the sha*e 6 degree ' lcd"cmd#D5$; lcd"data#2$; lcd"data#5$; lcd"data#2$; lcd"data#0$; lcd"data#0$; lcd"data#0$; lcd"data#0$; lcd"data#0$; / ! id c n!ert#$ // Functi n t c n!ert the !alues 6 ;24 int numeric !alue t be sent t 942 ' int s; test"6inal=test"intermediate1; lcd"cmd#00c1$; dela=#2$; lcd"data"string#N&:(PFN$; s=test"6inal/100; test"6inal=test"6inalO100; lcd"cmd#00cG$; i6#sL=0$ lcd"data#s>5G$; else lcd"cmd#000D$; s=test"6inal/10; test"6inal=test"6inalO10; lcd"data#s>5G$; lcd"data#test"6inal>5G$; lcd"data#0$; lcd"data#BcB$; lcd"data#B B$; dela=#2$; / ! id main#$ ' int iHK; adc"in*ut=0066; lcd"cmd#001G$; lcd"cmd#000c$; //2is*la= OnH 4urs r Clin)ing dela=#2$;

lcd"cmd#0001$; // 4lear ,creen dela=#2$; -hile#1$ ' 6 r#K=0;K<1;K>>$ ' 6 r#i=0;i<10;i>>$ ' dela=#1$; rd=1; -r=0; dela=#1$; -r=1; -hile#intr==1$; rd=0; lcd"cmd#00GG$; test"intermediate1IiJ=adc"in*ut/10; dela=#1$; intr=1; / 6 r#i=0;i<10;i>>$ test"intermediate2IKJ=test"intermediate1IiJ >test"intermediate2IKJ; / test"intermediate2I0J=test"intermediate2I0J/1; test"intermediate2I1J=test"intermediate2I1J/1; test"intermediate2I2J=test"intermediate2I2J/1; test"intermediate1=test"intermediate2I0J>test"intermediate2I1J>test"intermedi ate2I2J; sha*e#$; c n!ert#$; /

10 Program to !nter"ace -te%%er Motor to rotate the motor !n cloc#w!(e and ant!cloc#w!(e d!rect!on(
AI ! In this part !e are interfacing a stepper motor to our AT89S51. As the electro mechanical devices emit bac" $>; !hile running and controller canPt provide high po!er to run& !e canPt drive them directly for !hich !e use $> 2electro mechanical3 drivers. In this application !e are moving a stepper motor step by step for!ard. A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus ....

Theory!

Here in this part we are controlling a D7 motor with AT89S51 using )ri er li!e L390D. Working of ste99er motor: -te%%er Motor or a (te% motor is a *rushless$ s(nchronous motor which )i i)es a 'ull rotation into a num*er o' steps. Inli!e a *rushless D7 motor which rotates continuousl( when a 'i.e) D7 oltage is applie) to it$ a step motor rotates in )iscrete step angles. The -te%%er Motor( there'ore are manu'acture) with steps per re olution o' 13$ 3E$ B3$ 1EE$ 182$ an) 322$ resulting in stepping angles o' 02$ 15$ 5$ 3.5$ 3$ an) 1.8 )egrees per step. The stepper motor can *e controlle) with or without 'ee)*ac!. Working of an L<91D: The L390D is a 1ua)ruple high+current hal'+H )ri er )esigne) to pro i)e *i)irectional )ri e currents o' up to /22+mA at oltages 'rom E.5 # to 0/ #. %t is )esigne) to )ri e in)ucti e loa)s such as rela(s$ solenoi)s$ )c an) *ipolar stepping motors$ as well as other high+ current;high+ oltage loa)s in positi e+suppl( applications. All inputs are TTL+compati*le. Each output is a complete totem+pole )ri e circuit with a Darlington transistor sin! an) a pseu)o+Darlington source. Dri ers are ena*le) in pairs with )ri ers 1 an) 3 ena*le) *( 1$3E5 an) )ri ers 0 an) E ena*le) *( 0$EE5. ,hen an ena*le input is high$ the associate) )ri ers are ena*le)$ an) their outputs are acti e an) in phase with their inputs. E.ternal high+spee) output clamp )io)es shoul) *e use) 'or in)ucti e transient suppression. ,hen the ena*le input is low$ those )ri ers are )isa*le)$ an) their outputs are o'' an) in a high+impe)ance state. ,ith the proper )ata inputs$ each pair o' )ri ers 'orm a 'ull+H "or *ri)ge& re ersi*le )ri e suita*le 'or solenoi) or motor applications. A #771 terminal$ separate 'rom #773$ is pro i)e) 'or the logic inputs to minimi-e )e ice power )issipation. The L390D is )esigne) 'or operation 'rom 27 to B27. Working of AT89S51: AT89S51 re1uires a oltage o' 5.2#. The current rating o' the total circuit )epen)s on the wor!ing o' the microcontroller an) the consumption o' )ri ing the L390D. The controller wor!s on 11.2593 4H- 're1uenc(. %n this application we are controlling the D7 motor which is )ri en using the E4 )ri er as L390D using port pins o' the controller. 5ote6 %t is suggeste) to use 522mA an) 5# D7 power suppl(.
Algorithm! 1. In this pro ect !e need to interface a stepper motor to at89c51. -. To provide output& first !e need to clear the storage or available data in port register. /. As !e "no! the stepper motor !or"s by changing of northEsouth coils in !indings by varying voltages& hence !e need to toggle the voltage provided for four coils. ,. 'rovide logic 1 for first coil and logic 0 to rest& then shift logic 1 to second and logic 0 to rest !hich means shifting north pole& !hich ma"es stepper rotor to rotate. 5. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle& for energi7ing coil time for every step. 6. )epeat the steps , to 5 !hole in a continuous loop.

;chematic!

Start

8lear the available data in reg '1& 2'1403.

Assigning #ogic 1 state to port '1 i.e.&2'1400ff3

Flow chart:

True

Stepper23@

;alse

%elay23@

$nd

Program:

9!ncl*de:reg51 h;

'o!d clear82< 'o!d dela$8!nt a2< 'o!d (te%%er82< 'o!d ma!n82 = clear82< wh!le812 // !n"!n!te loo%

= P1>0?01< dela$815002< P1>0?02< dela$815002< P1>0?03< dela$815002< P1>0?04< dela$815002< @// end o" wh!le loo% @ // end o" ma!n 'o!d (te%%er82 = P1>0?01< dela$815002< P1>0?02< dela$815002< P1>0?03< dela$815002< P1>0?04< dela$815002< @

'o!d clear82 = P0>0?00< P1>0?00< P2>0?00< P/>0?00< @ 'o!d dela$8!nt a2 = !nt $< "or8$>0<$:a<$AA2< @

12. Program to interface (le'ator.


5!m:
In this part !e are creating an application based on our AT89S51. This application re<uires a stepper motor to operate& a s!itch board to !or"& #8% to display current status of the elevator. A""aratus! 1. I%$ * +iel uvision ,.0& -. Simulator* 'rofessional 'roteus .... Algorithm! 1. In this pro ect !e need to interface a stepper motor& s!itch and #8% to at89c51. -. To provide output& first !e need to clear the storage or available data in port register.

/. As !e "no! the stepper motor !or"s by changing of northEsouth coils in !indings by varying voltages& hence !e need to toggle the voltage provided for four coils. ,. 'rovide logic 1 for first coil and logic 0 to rest& then shift logic 1 to second and logic 0 to rest !hich means shifting north pole& !hich ma"es stepper rotor to rotate. 5. 1o! !e need to generate -50ms delay by looping time period T 2delay time34cycles5cloc" cycle& for energi7ing coil time for every step. 6. 1o! initiali7e the #8% based on the commands to be provided. .. 1o! scan the s!itches and rotate the stepper accordingly bac" or forth to obtain particular floor. 8. )epeat the steps , to 5 !hole in a continuous loop.

$escri"tion!

Working of a L4D: L7D "Li1ui) 7r(stal Displa(& screen is an electronic )ispla( mo)ule an) 'in) a wi)e range o' applications. A 1/?3 L7D )ispla( is er( *asic mo)ule an) is er( commonl( use) in arious )e ices an) circuits. These mo)ules are pre'erre) o er se en segments an) other multi segment LEDs. The reasons *eing6 L7Ds are economical$ easil( programma*le$ ha e no limitation o' )ispla(ing special A e en custom characters "unli!e in se en segments&$ animations an) so on. A 162 LCD means it can )ispla( 1/ characters per line an) there are 3 such lines. %n this L7D each character is )ispla(e) in 5?B )ot matri.. This L7D has two registers$ namel($ 7omman) an) Data. The comman) register stores the comman) instructions gi en to the L7D. A comman) is an instruction gi en to L7D to )o a pre)e'ine) tas! li!e initiali-ing it$ clearing its screen$ setting the cursor position$ controlling )ispla( etc. The )ata register stores the )ata to *e )ispla(e) on the L7D. The )ata is the AS7%% alue o' the character to *e )ispla(e) on the L7D.

As$ )ot matri. ha ing negati e rows an) positi e columns$ here in the a*o e 5?B )ot matri. we supplie) C5# to select 0r) column an) Dn) to 1st$ 0r)$ Eth$ 5th $/th an) Bth rows. %n the same pattern L4 21/L ha) 03 5?8 )ot matrices *( which we can iew 03 characters at a time. All the characters are pre)e'ine) in the 9A4 memor( o' the L4 21/L. Working of ste99er motor: -te%%er Motor or a (te% motor is a *rushless$ s(nchronous motor which )i i)es a 'ull rotation into a num*er o' steps. Inli!e a *rushless D7 motor which rotates continuousl( when a 'i.e) D7 oltage is applie) to it$ a step motor rotates in )iscrete step angles. The -te%%er Motor( there'ore are manu'acture) with steps per re olution o' 13$ 3E$ B3$ 1EE$ 182$ an) 322$ resulting in stepping angles o' 02$ 15$ 5$ 3.5$ 3$ an) 1.8 )egrees per step. The stepper motor can *e controlle) with or without 'ee)*ac!. Working of an L<91D: The L390D is a 1ua)ruple high+current hal'+H )ri er )esigne) to pro i)e *i)irectional )ri e currents o' up to /22+mA at oltages 'rom E.5 # to 0/ #. %t is )esigne) to )ri e in)ucti e loa)s such as rela(s$ solenoi)s$ )c an) *ipolar stepping motors$ as well as other high+ current;high+ oltage loa)s in positi e+suppl( applications. All inputs are TTL+compati*le. Each output is a complete totem+pole )ri e circuit with a Darlington transistor sin! an) a pseu)o+Darlington source. Dri ers are ena*le) in pairs with )ri ers 1 an) 3 ena*le) *( 1$3E5 an) )ri ers 0 an) E ena*le) *( 0$EE5. ,hen an ena*le input is high$ the associate) )ri ers are ena*le)$ an) their outputs are acti e an) in phase with their inputs. E.ternal high+spee) output clamp )io)es shoul) *e use) 'or in)ucti e transient suppression. ,hen the ena*le input is low$ those )ri ers are )isa*le)$ an) their outputs are o'' an) in a high+impe)ance state. ,ith the proper )ata inputs$ each pair o' )ri ers 'orm a 'ull+H "or *ri)ge& re ersi*le )ri e suita*le 'or solenoi) or motor applications. A #771 terminal$ separate 'rom #773$ is pro i)e) 'or the logic inputs to minimi-e )e ice power )issipation. The L390D is )esigne) 'or operation 'rom 27 to B27.

%low chart

start

8lear the available data in reg '1& 2'1403.


floor0 441

Stepper?f!d23

True

;alse

;loor1 441

$nd
present44 1

Stepper?r!s 23

Stepper?r!s23

;chematic!

Program:

;; HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH ;; @roject6 L7D 8*it ;; Author6 9agha a 9e))( ;; 4o)ule )escription6 :perate L7D in 8*it mo)e ;; HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH Ginclu)ePreg51.hQ s*it 'loor2>@2R2J s*it 'loor1>@2R1J

s*it 'loor3>@2R3J s*it 'loor0>@2R0J unsigne) char )J ;;Function )eclarations oi) cctSinit" oi)&J oi) )ela("int&J oi) lc)init" oi)&J oi) writecm)"int&J oi) write)ata"char&J oi) stepperSrws"&J oi) stepperS'w)"&J oi) lc)string"unsigne) char Hp&J oi) 9eturnHome" oi)&J

;;HHHHHHHHHHHHHHHHHHH ;;@in )escription ;H @3 is )ata *us @1.2 is 9S @1.1 is E H; ;;HHHHHHHHHHHHHHHHHHHH ;; De'ines @ins

s*it 9S > @3R2J s*it E > @3R1J ;; HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH ;; 4ain program ;; oi) main" oi)& T char j>2$rotate>2$present>2J cctSinit"&J lc)init"&J lc)string"Uinitialising....U&J )ela("12222&J while"1& T i'"'loor2>>1& T rotate>2+presentJ i'"rotateQ2& T 'or"j>2JjProtateJjCC& T stepperS'w)"&J V ;;%nitili-e L7D ;;4a!e all ports -ero

V i'"rotateP2& T 'or"j>presentJjQ>2Jj++& T stepperSrws"&J V V writecm)"2.21&J lc)string"Uli't at 'loor2U&J present>2J V

i'"'loor1>>1& T rotate>1+presentJ i'"rotateQ2& T 'or"j>2JjProtateJjCC& T stepperS'w)"&J V V

i'"rotateP2& T writecm)"2.21&J write)ata"presentCE8&J 'or"j>presentJjQ>1Jj++& T stepperSrws"&J V V present>1J ;;writecm)"2.21&J ;;lc)string"Uli't at 'loor1U&J V

i'"'loor3>>1& T rotate>3+presentJ i'"rotateQ2& T 'or"j>2JjProtateJjCC& T stepperS'w)"&J V

V i'"rotateP2& T 'or"j>presentJjQ>3Jj++& T stepperSrws"&J V V present>3J writecm)"2.21&J lc)string"Uli't at 'loor3U&J V

i'"'loor0>>1& T rotate>0+presentJ i'"rotateQ2& T 'or"j>2JjProtateJjCC& T stepperS'w)"&J V V

i'"rotateP2& T 'or"j>presentJjQ>0Jj++& T stepperSrws"&J V V present>0J writecm)"2.21&J lc)string"Uli't at 'loor0U&J V

oi) lc)string"unsigne) char Hp& T while"Hp& T write)ata"Hp&J HpCCJ V

oi) cctSinit" oi)& T @2 > 2.22J ;;not use) @1 > 2.22J ;;not use) @3 > 2.22J ;;use) as )ata port @0 > 2.22J ;;use) 'or generating E an) 9S V

oi) )ela("int a& T int iJ 'or"i>2JiPaJiCC&J ;;null statement V

oi) write)ata"char t& T 9S > 1J @1 > tJ E > 1J )ela("152&J E > 2J ;; >Q E > 2 ;; >Q 9S > 1 ;;Data trans'er ;; >Q E > 1 B

)ela("152&J V

oi) writecm)"int -& T 9S > 2J @1 > -J E > 1J )ela("152&J E > 2J )ela("152&J V ;; >Q E > 2 ;; >Q 9S > 2 ;;Data trans'er ;; >Q E > 1

oi) stepperS'w)"& T @0>2.21J )ela("B522&J @0>2.23J )ela("B522&J @0>2.2EJ )ela("B522&J @0>2.28J )ela("B522&J

oi) stepperSrws"& T @0>2.28J )ela("B522&J @0>2.2EJ )ela("B522&J @0>2.23J )ela("B522&J @0>2.21J )ela("B522&J V

oi) lc)init" oi)& T ;;;;;;;;;;;;; 9eset process 'rom )atasheet ;;;;;;;;; )ela("15222&J writecm)"2.02&J )ela("E522&J writecm)"2.02&J )ela("022&J writecm)"2.02&J

)ela("/52&J ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; writecm)"2.08&J writecm)"2.2c&J writecm)"2.21&J writecm)"2.2/&J V ;;'unction set ;;)ispla( on$cursor o''$*lin! o'' ;;clear )ispla( ;;entr( mo)e$ set increment

Potrebbero piacerti anche