0% found this document useful (0 votes)
98 views28 pages

MIcro Controller Programming

Notes on Micro Controller programming

Uploaded by

Akhil Palle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
98 views28 pages

MIcro Controller Programming

Notes on Micro Controller programming

Uploaded by

Akhil Palle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 28
| ner 2 2 go8 | Micro Contaller Prog ramanting The direckiy forthe Msenbles.’ - She dinecReer ome the pure Vass © Oe Macabre cdo Avan ackors Aud ar 1) whys ple te repo Mou mory Bm Re meaty aclu Matd be warous Contes be plaudt uk. Yio diveutvés oma nok cpnuplid Js saguhine Langeuge, ad try do nok oCupy edge aolcbumnes ORL, Cav, 08 ad ENO me MH avorlebe haba, OR, ( oxiage a-sut ths slr, acdinea . he ORG pele ie Seen Ce “ie be 2 KH on wd ott wie Tr im minty pln Laugh vee Gs ment 1 aoe | a ote # eal Ue met (hm oF lar 0 g nanan of 20@o H Moy A, Peo lt pees H Mo 6 test 20 0rH pty, 3090H put, Te may & 1, AOE gosoH [MR ae oH Moy Ms, Rete SCHEME AND SOLUTION [ —) School af Computing &IT ‘Academic year: 2018-2019 | CAPVEASL)'Y | Course Name: Computer. Networks, Concepts and Prootocols. | | | Course Code : BTCS1SF5500° Semester: 05 a | a —t Marks jae fj — — - 4 Eavs (2 guste) - — + ; _ a Cut ithout OCs | lms wd be pe KOO. ja aay Lol = a aie Wwifh a_| | Se telb be odnbla gnats - | | Qo tm te enbiw ALP wrtoheuor (abe the Velie that be | vd & | jako | ae N tey 05H | | Mov A, deN | poo A, aN ok fl Define Bye) qu be Aeplaced by wold 6. pe dowckna of the mat videly wud dae |pospanstoce . lie chee in tee aevenetler. 1 ear & dye oe e bit dale. when ae [rr Le ee deanhea), Brag, | J 1 ase wo 2 24 - eth wee chorale ba qyastation ane Jon dhe Cole | |en- 0&5 Food | petal: 08 28 5 Peamol Cie va hx) lyere as pB 00(00010 + Binamy (22 index ) | DATR 3s 28 384 2 Hex | 7 oe G00H | Deve 4 9a © 250L7 ALL nay | i. TEA oud + oe a Dar ss 08 REV VALE aca eZ bs 60\ 4 |—rs—} boa Pa ont 502 u}—3e_f vara > Soi 4 [3a] oma > soot ic |oarat ENO! Taaols Dt avenbla, te ed of he AO fie the END hirethre Bo the [oak bmn f aw o5| propa maa ng “tok PA thee = Kowmeode angi rg ogee ey genio duechre b ignond by the aster f&- — ORL, HOO mov A, at20 Hoot Mov 8, A158 Aooth gow A, ae enon Mov RL, AOL 5 Bile be ign GD, big eri ptm ber Format ‘Tes, Racombly (ang uege CGomuoude ad Commcals 3 Columms Lotoek MasaLow © Heee 4 move conlenls 4 Ri & A setae oe genalt i Yok’ column » aph oral Ye i ued be deb fg a Command vL aw adds . SCHEME AND SOLUTION | School of Computing iT ‘Academic year: 2018 -2019 Course Name: Computer Networks, Concepts and Prootocols. Course Code: BTCS15F5500~ —__ Semester: 05 4 fa] ok. = = No | ot f column : B dturded (nbs live ae ron | Magaront va Subs column Cex: Mov) Apeuifees the Conan) han te be excel | ae 2 | Subcoluma (a= 8) Se a dale on which bem ° chase hh ophonal . HMellcessie ay Modeo .~ Ceu Caw accor Jala fn wanious Waifs oe an tamebale jhe varour ways ae ane modes | ; adds fe Varios : le | O dsroue? int te dergedd A Shea le J by the Propane a Ga 4 be ax lous . 4 | Gmmaediale |) Regs || Direkst (| Trdireet | Tnche xed 1 Gignature of the paper setter with Date: Fe dota Could be ina segeley of 9 | ded os hiss, a or ke prev! auewnrs balk au oud piles 4 am Locoule x. nol- she gos! | Provides dlnknet adding modo Theny re Teaiials Adland na — © Sn thir adduesing mode te Aoure opaand i or ComBnt . gle immediale dat» must k prececded by Be Pound Sign Ae” Cah Number mgr) | Shi, addauna — onede tank wd G bad (operation into any d the Rogriler facladar DPTR gageslr b 805 | pub Mnemonic © 2 eens, n Penal Mov Qs, at 5 5 Copy We S-bit nanther fal the degasler CR) f Current bank repalic Mov &, ARN 5 2 Copy Cu e-bik nuwbher nm fale Ge Ccumlaly reas le MON DPTR, shan Copy The I6-biE number 9 ine Ce > DPTR segs hy He wae RA, aor 5 pub Ua Pom@iale abit nusbe or Hin Raps le aa. Mov A, =t OAA K 5 pak he famediale ARK ty tegrte A Mov OFTR, Hi234H | B-bie number pak De mmedrale 1234 in lo- wk args, OPTRA Nutbe Mo A, se 1254H 5 Tavalid , sour we Kye Gow noe mattle 4 desk nobey mev Pi, #4554 5 mov me hexa ne Saw & Peet Jhb tenposstbe © move Immediate date asa det. ~haken BO Fo ey fast exeudhen, dirady:- por very flexible *< - SCHEME AND SOLUTION © | niet | Schoo! of Computing aT Academie year: 2018-2019] | E | Course Name: Computer Networks, Concepts and Prootacols. | Course code arcsisrssoo Semester: 06 eae ar ee eel No. | | Peseta | Addressing Mode \- — VT eer adwnind ode redom ts Uf Ipelps tc i ‘hotd data Ie be pros tpulaley [She rept A, DeTR KRoGRA Mog k ured aa lite on well a daknalsen | $0 | Minemoar ¢ O perakon | | ov &, Rr copy dak peom Be fess A Mol Be, a » Copy bala ftom A daestn Ry | = G Ro & A exit Mov A, Ro 5 Copy %e datz sr Reps 2gsln 5, = eepala Rs R50; Copy Bo date to agin * E Mo — fon one Nb data bfx | OPTR, HeOusH 3 {| | Mov onan & te PTR lov @7, OeL | | mov e6, OPH | “tov oprR, A 5 RAD, nce ta oie Pan FE and te dohraber bw [owe Reg ‘sees iin belie [Nore - We Caw Move R1) bok aa dala Q- RoE RI ae pact blouse d } | | pe (Mov Ruy toch vi Ynuekd | | Setar ofthe paper seer with Oates I | D jreck Addvesving Mode | . Gn divest addiurnd mode, te da & ina Raw ‘ques Locabor whe addin » bnown and Hn as a part ot te Pothuth ere | addin in Gen ep (28 byl 4 jalernel @AM (00-45H) and FR 's (ge-Fr ay may be added §— antl wying Oe | Aregle~ by Addins eriigned © exch &8mM lowbion and cach Aperal fundren segslin . Aabernoh gam lotaben Ont ov RE tn Regsln bx adding mode Can be uns. oR 2 A ov 060 Cam UKe. Mprcuonte opaatien data pom dawut addres Mov A, addr > Copy addr & rgsla A. Moi asd, * copy dala ftom rept & & Mov Rr, add 5 Coty date pom dick addua & huapsla Re [Mov addr, & 4 copy dala ftom Rogrla Py te dace odd anes [Mov oddn, HO 5 Copy t z addi addr Mor 5 © olirert addi adda 4 Bur @ mov Ae Boh 5 Copy dal farm tin PRED pins - A bya oe a4te Mine oan me A<20h A <—35h (creneano soxsron ©. d School of Computing &IT Academic year: 2018 -2019 ~ | Course Name: Computer Networks, Concepts and Prootocols, | Course C Semester: 06 | {Q i jon T: | i d/Mov ain, a; copy dolk fom vagal AG) ta | RAM locate 31h Rages. | AS 35H | a Bh < 35h. 334 | | 34m | ap%e a | | 30h aah | fecal ‘aah © Mov Ro, Dh 4% Cory dala flan RAM loiter | x RO | beg Mele ; | Qo <[irh] po < 38h copy dota .fom repaley 21 G | 0 @® mov #Ch, RT, | | f Baer high. byte -| || k3Khs Copy Immadials dole bye a & | +e | ca ad PAM kycahen 34h | a! (© Moe CABAL TTH y Lopy ake OM RAM Wcatay | | (TTh Gere gegsle | @ Mov 2 + copy date yom Re tepalr Ram - bbutm ~@ RT wml pam Ceopdien halk 2 inthnuichen | | | Smo @ARe & fnvekd | Signature ofthe paper aptor with Date? a Toa ask ak a Gai, tatercat eam—— ong fer ible aux gor Gachirect Addreesing Mode: - OO @ Yrer ag veg G held he aUiSol aclu thar wt opaally be und @r Te data Mou the cease Fenty B&B not te adlduy but relic Te Aumbesr fa te AmgeGs will be te addun ftom wher dole wil be Ghen Mov opcodin, MEXlG RO OV RI CRE data Poiali) For hued hot tee adder of Ue dal focatoon fq eam fom oh TF. the ROAR ane ured as poraly RAM Lotabons fe Whegy they hd Te addin they must be preceeded by Oe (@" sygnbol PU nenoare opaabon MoVORP, tha s Gpy Be famabiate ble 1 & he oddun in Rp mov @ee, ode Copy ta conlittr of addr & he oddusn Re. mow @er, A . copy tee dota fo A Me actin ta RP mov adda, @FP , Copy the Codmbenls of aotdus in Re 6 wo Mow A, @RE + copy Conlauls of the addins fa ep & A &° Moy & @Ro % Cry tu cocloits of adds ¢ RO ae A Mgsls . A << [L&I] sth = \ <—25h Bl ° ooh [30 Ro ® @ Mv @RLA +, copy tu Contats ef A W te adduy rR} AL25 4 Ss A Ced<— onl zea | #1 Oth Ro GQ mv @ei, H3sh 5 cory Tu rider 3shb the adda in RY ah Lasr} ol 60 Ee @ mov @eo, Son Copy tu contin of RAM lacatsen addin Goh t tw adds tA, | [rel <— [sot] son Rt oil aeh rRo © mov HW, @LO% Copy Oe confide sf ta in gam looker adds 60H wh PVs 80 [20 Exlescol Data Movee™- - @) ExGrwl RAM Heo Can be onredid & Qos] ad fe tam be as age as OH KB of both Roma AM For addauing, exbvaat rumdy always indie audhuneg 1 wd Apeurgny, ex bina manrdig » For fcueseng @ninal RAM regal RO, RI yOPre cate bee wd g¢ htd Ge addun f ariirad PAM memthige cuddles fo Ri 3 tau pa BAM addins rouge of ooh “AFH eu tt va Sot nop lt pPTe = oooh FFFF A (SH ha b-bd vegas ley) Nore All ex teak dala moves must mootie te A vepaler , pddwang Satruthon [ @ee foo, b atteusnd MoV % Snatauhon fund watch. tll that tt txtereol RAM memeodye MA nanronie opaaken move A, @Rp 5 copy Conkiuls of the ex nal addus ta Vp @ & . bar » @f RAM be Mon% A @ heen, * h< (LPo] | Ae 25 , o\ I a Bott Qo Deve &, @ oPTR + copy, hu eoalanlr f ¢x veal at | fo DPTR Ww x KAM | Mov OPTR, aRRFFEHR FEFE TF; mMovK A, @ DPTR | A 20. . mx @ er ay Lopy date 4Rorm A the ex 6mol | addus in Re IRAN X RAM Eas Movx @Ri, @ A fia | eel oo |_ AN <20 : | rol | Mev x @orre,& 5 py dala fom A & te tx fen f a DPTR @orre,& DeTA <— 8100 (baie Movx | a & <30 8100 Py | Read oaly Date Mover (Gudbexed ident) daw thves ree Preebe 15 howe hae Code Memory | Usiab Aesenbler CO on doz form code munrty PC or PTE Bud 1a Cogundion with kegs A Here PC or DETR > Potating vegelet $y bot caw, be number im gs le Ah addeacl tr the Potokrap Gugsle fe form the addon jr ROM whore tt, dered dae (a be found , | | (Geet move m @hsorns J ; ' |} CRERA} tc A) Bha he 1 ' ’ Bose _! MOVC Sahruten V5e of Me qeody for moviak data ftom Acura adds in the code Rom & the Mgula A tn fe Posy Move A, @Ax OOTR » copy toda byl » ford at | the Ror odds formed bg odidivy f and HDPTR le A reps. fe mow DPTR, AHIZB4H MoV A, 56 W eom move: Ay @R*OPTR xr A 56 | sete (134 | 129A & | son Ay peve > 66 41934 — Rom addin \ TERA toda y Rom Pinably eoutk fe sou © Move 7,@A+PC 3 Cepy Be Cocke we joud af wa Fone pornrasl by auddiny A and Ba PCB As Ex PC —> 4000 A> 58 (a) mom Rom adds = 405TH Aosqa A NT TO Ele Lhe th inward by One Conleenks of tats 0% lotalion aco Aled pus ott s 8 qaueond bY Ore x oateds of Ri ser tte 04 locaken posh ooh 4 se sauese? by Om § Conan peste | tats Of locahen | ae Condos ror he dee 8 = wpa | Menthe aye. HHO on ent | 08 = oe & 0. of ; 5 4 & oe z ° 3 | Sl os Seen Speor sero ‘gor cet wtp $0 led Reebrreue— | To reteere date pom 0G t 7 Tee eae pte oem a f. Cone 9 | pop go> Conk ak OAT look Cap) will & Copest | go. then Chace Powe dérwaad byt Coreen) | Por 31h: contr ak o9nlooten CP) with — be Copred We | gun then Se demtamdby 4 pop Bens Conint a 08 F lpder ph & Copte? | Han Se Geoinad ts pyle fo" 30 nda tore} nye COP Se ex 08 is vt a 93 te o r oS os "ee of Sl Seno genet ply 32H (Rr fo © #9) Gx horge gyhs pre A ad P39 th «ch AY Ra > Bye Exeuren - becnber e 29-50 pe se ~~ eae 40 - a) yey Ay adds Exdenge aux bye bth bkly A and RAM tee vou 6, oFoHy exubong 7 “ locaton ‘cou’ CSF 3B segs & ) Bagere _teusteabsery Ayla Exeaulnen |; # 6 [se] , Ge) ¢ Gel. (oro) a XCH A _ », @kes, & => adobe — bye bey hand , xen A, @R1 5 tx dange bys bilo A and KAM loc" wher addin 6 fa BI. Bria Exauton ME er hen 30 A Gd i a oF ae 4 (EF) DU Fo | o) od Ro @ xctio A, @ee 1 Exdange lower atub_in Ah an? aus & RP wLHO KF a Apeaol tole ft RCo frutoettren , whut guste lovey mipba We exch ty eno hy GEIS Extange bee eqabe iw A od aden | Bese txceuheo ae « ee) ot el 60 & ne P| — Gestation Se gor, Srrudren cows bs [byl pn ees sf opcone ad 0 2by 4 opaonds , de a Q Data bamyr © Lope! © | SECTION A.1: THE 8051 INSTRUCTION SET ACALL target address Function: Absolute Call Flags: None ACALL stands for “absolute call.” It calls subroutines with a target address within 2K bytes from the curren program counter (PC). See LCALL for more discussion on this. on ©) ADD A,source byte Function: ADD Flags: OV, AC,CY ‘This adds the source byte to the accumulator (A), and places the result in A. Since register A is one byte in size the source operands must also be one byte. ‘The ADD instruction is used for both signed and unsigned numbers. Each one is discussed separately. Unsigned addition q In the addition of unsigned numbers, the status of CY, AC, and OV may change. The most important of these fags is CY. It becomes 1 when there isa carry from D7 out in 8-bit (DQ - D7) operations. Example: Mov A, #45H sA45H ADD A, #4FH iA=94H (4SH+4PH94H) i€¥=0,ACe1 461 454 Example: 474 MOV A, ROFEH jAsPEH . 470 MOY R3,#75H | jRI-75H 46 | ADD A,R3 JA=PE7527311 iC¥=1,AC=1 > Example: Mov A, #25H jRe25H ADD A, #42H GA=67H (25H+42H=67H) #C¥=0,AC=0 Addressing modes ‘The following addressing modes are supported for the ADD instruction: 1. Immediate: ADD A, data Example: ADD A, #25H 2. Register: ADD A,Rn Example: ADD A, R3 3. Direct ‘ADD A, direct Example: ADD A,30H ;add to A data in RAM loc. 30% 4, Register-indirect: ADD A,@Ri where i=0 or i-1 only Examples; ADD A,@RO add to A data pointed to by RO | ADD A,@R1 ;add to A data pointed to by R1 In the following example, the contents of RAM locations 50H to SEH are added together, and the sum is saved it RAM locations 70H and 71H. s 454 APPENDIX A CLR OA =0 MOV RO,#50H source pointer Mov R2,#16 jcounter Mov R3,#0 jelear RB Ad: ADD A,@RO ;ADD to A from source ac Bt jIP C¥=0 go to next byte INC RB jotherwise keep carries Bal: INC RO jnext location DoNz R2,A_1 jvepeat for all bytes Mov. 70H,A isave low byte of sum Mov 71H, R3 jeave high byte of sum Notice in all the above examples that we ignored the status of the OV flag. Although ADD instructions do affect OV, it isin the context of signed numbers that the OV flag has any significance. This is discussed newt. ai21 4 Signed addition and negative numbers ~\led © In the addition of signed numbers, special attention should be given to the overflow flag (OV) since this indicates if there is an error in the result of the addition. There are two rules for setting OV in signed number operation. The overflow flag is set to 1: “1. Ifthere is a carry from D6 to D7 and no carry from D7 out. 2. If there is a carry from D7 out and no carry from D6 to D7. Notice that if there is a carry both from D7 out and from Dé to D7, OV =0, Example: WOU A, #8 iA=0000 1000 voy RL, Hes 7R1=0000 0100 ADD A,RI jR=0000 1100 OV=0,C¥=0 Notice that D7 = 0 since the result is positive and OV =00 since there is neither a carry from D6 to D7 nor any carry beyond D7. Since OV = 0, the result is correct {(+8) + (+4) = (+12)] Example: T ayrye OFlnoel MOY A, #466 yA=0100 0010 ) MOV R4,#+69 7R4=0100 0101 : ADD A,R4 ;Re1000 0111 = -121 ; (INCORRECT) C¥=0, D7=1, OV=1 T In the above example, the correct result is +135 [(+66) + (+69) = (+135)], but the result was -121, OV = 1 is an indica tion of this error. Notice that D7 = 1 since the result is negative; OV = 1 since there is a carry from D6 to D7 and CY =0. Example ; Avo 1108 + p00 Mov A,#-12 jAe1111 0100 nt en MOV R3,#418 — ;R3=0001 0010 gon! ADD A,R3 ;A=0000 0110 (+6) correct ;D7=0,0V=0, and C¥=1 Notice above that the result is correct (OV | since there is a carry from D6 to D7 and a carry from D7 out. Example: MOV A, #-30 jAs1110 0010 § MOV RO, #+14 +RO=0000 1110 ADD A,RO jRe1111 0000 (-16, CORRECT) ;D7=1,0V=0, CY=0 OV =0 since there is no carry from D7 out nor any carry from D6 to D7. ee | APPENDIX A 455 Example: \ 9090001 MOV A, #-126 7A=1000 0010 ® 4 MOV R7,8-127 ;R7=1000 0001 9010 ADD A,R7 A=0000 0011 (+3, WRONG) ;D7=0, Ov=1 CY =1 since there is a carry from D7 out but no carry from Dé to D7, Wi 1401 ») ADDC A,source byte Function: Add with carry Flags: OV, AC,CY ‘This willadd the source byte to A in addition to the CY fag (A= A+ byte + CY).1FCY = 1 prior to this instruction, Iso added to A. If CY = 0 prior tothe instruction, source is added to destination plus 0. This is used in multibyte additions. Inthe addition of 25F2H to 3189H, for example, we use the ADDC instruction as shown below, Example: cuR ¢ icveo NOV A, #e9H iA=89H DDC A, HOFZH MOV R3,A Mov a, 431K ADC A, #258 pA31N25H1<57H MOV WA Therefore the result is: 25F2H + 31898 . S77BH 2423 5S1B ‘The addressing modes for ADDC are the same as for “ADD A.byte", ») AMP target address Function: Absolute jump Flag None _ ANL dest-byte.source-byte Function: Logical AND for byte variables Flamigs: None affected ‘This performs a logical AND on the operands, bt by bit storing the result in te A B_AANDB destination. Notice that both the source and destination values are byte-size only. fe oa ° B le: i a 9 o MOV A.#39H jA=39H » if = ANL A, #098 jA=39H ANDed with 09 A 456 APPENDIX A 39 0011 1002 99 0000 1002 080000 1001 Example: Ho A, #32H sR32H 32011 0010 WOU Rs,#50% — ; RaaSON 50__ 0101 0000 AN A,R4 ; (Be10H) 100001 0000 For the ANL instruction there are a total of six addressing modes. In four of them, the accumulator must be the destination. They are as follows: 1 2 3 4 wl 5 — Immediate: ANLA,fdata Example: ANE, A, #25% Register: ANLARn Example: aNL A,R3 Direct: ANLAdirect Example: ANL A, 20H ;AND A with data in RAM location 20% Register-indirect Example: ANL A,@RQ AND A with data pointed to by Ro in the next two addressing modes the destination isa direct address (a RAM location or one ofthe SFR registers) hile the source is either A or immediate data, ANL direct#data Example: Assume that RAM location 32H has the value 67H, Find its content after execution ofthe following code ANL 32H, #443 44H 0100 0100 67H 0110 0112 44H 0100 0101 Therefore, it has 44H. Or look at these examples: ANL PL, #121111108 smask P1.0(D0 of Port 1) ANL P1,#01111111B smask P1.7(D7 of Port 1) ANL P21, #111101118 smask P1.3(D3 of Port 1) ANL P1,#11111100B smask P1.0 and P1.1 The above instructions clear (mask) certain bits of the output port of P1 ANL direct, Example: Find the contents of register B after the following: Mov B,#eaH MOV A,#67H ANL OFOH,A yA AND B(B is located at RAM FOH) safter the operation BesaH "Note: We cannot use this to mask bits of input ports! For example, “ANL_ A, P1 is incorrect! Srvat d | ANL Csource-bit Function: Logical AND for bit variable Flag: yy In this instruction the carry flag bit is ANDed with a source bit and the results placed in carry. Therefore, if source t= 0, CY is cleared; otherwise, the CY flag remains unchanged. PPENDIX A. 457 / Example: Write code to clear the accumulator if bits P2.1 and P2.2 are both high; otherwise, make A = FFH MOV A,#ORFH = ;AsFFH WOV C,P2.1 reopy bit P2.1 to carry flag BNL C,P2.2 jand then anc BA sfump if one of them is low cue A Ba: Another variation of this instruction involves the ANDing of the CY flag bit with the complement ofthe source bit, lis format is “ANL C,/bit”, See the following example Example: Clear A if P2.1 is high and P2.2 is low; otherwise, make A = FFH. NOV A, #0FFH Nov C,P2.1 iget a copy of P2.1 bit ANL ¢, /P2.2 ;AND P2.1 with complement of P2.2 ONC BAL cLR A Ba: ( a) CINE dest-byte,source-byte,target Function: Compare and jump if not equal Flag) CY ‘The magnitudes of the source byte and destination byte are compared. If they are not equal, i address, jumps to the target Example: Keep monitoring P1 indefinitely forthe value of 99H. Get out only when PI has the value 99H, MOV P1,OFFH jmake Pi an input port BACK: © MOV. A,PL jread Pl * CONE A, #99, BACK jkeep monitoring Notice that C}NE jumps only for the not-equal value. To find out if itis greater or less after the comparison, we must check the CY flag. Notice also thatthe CJNE instruction affects the CY flag only, and after the jump tothe target address the carry lag indicates which value is greater, as shown here. In the following example, Pl is read and compared with value 65. Then: Dest piv ab) Function: Divide Flags: = CYand OV This instruction divides a byte accumulator by the byte in register B. It is assumed that both registers A and B con- tain an unsigned byte. After the division, the quotient will bein register A and the remainder in register B. If you divide hy zero (that is, set register B = 0 before the execution of “DIV AB"), the values in register A and B are undefined ang ,/ the OV flag is set to high to indicate an invalid result: Notice that CY is always 0 in this instruction, Example: NOV A, 435 Nov B,#10 DIV AB :As3 and B=S Example: Mov A, #97H MOV B, #128 DIV AB jA=B and Be7 Notice this instruction that the carry and OV flags are both cleared, unless we divide A by 0, in which case the result is invalid and OV = | to indicate the invalid condition. DJNZ byte, target Function: Decrement and jump if not zero Flags: None In this instruction a byte is decremented, and ifthe result is not zero it will jump to the target address. Example: Count from 1 to 20 and send the count to PL. CLR OA iRe0 Mov R2, #20 7R2=20 counter BACK: INC A NOV PLA DUNZ R2,BACK repeat if R2 not = zero The following two formats are supported by this instruction, Register: DJNZ Rntarget (where n=0 to 7) Example: DgNZ R3, HERE 2. Direct: DJNZ direct,target Notice that the target address can be no more than 128 bytes backward or 127 bytes forward, since it is a 2-byte instruction. For more on this see SJMP. iC byte Function: Increment Flags: None ‘This instruction adds 1 to the register or memory location specified by the operand. Note that CY is not affected even if value FF is incremented to 00. Ths instruction supports four addressing modes. Accumulator: INCA Example: INC A Register INCRn Example: INC RL or INC R5 i INC direct INC 30H vincr. byte in RAM loc. 30H 4 INC @Ri(i=00r1) INC GRO yiner. byte pointed to by RO 462, APPENDIX A. INCDPTR Function: Increment data pointer Flags: None This instruction increments the 16-bit register DPTR (data pointer) by 1. Notice that DPTR is the only 16-bit register that can be incremented. Also notice that there is no decrement version of this instruction, Example: MOV DPTR,#ISFFH ©; DPTR=16FFH INC DPTR snow DPTR=1700H JB bit,target also: JNB bit,target Function: Jump ifbit set Jump ifbit not set Flags: None These instructions are used to monitor a given bit and jump toa target address if a given bit is high or low. In the case of JB ifthe bitis high it will jump, while for JNB ifthe bit is low it wil jump. The given bit can be any ofthe bit. addressable bits of RAM, ports, or registers of the 8051. Example: Monitor bit P15 continously. When it becotnes low, send 55H to P2. SBTB P1.5 make P1.S an input bit HERE: JB P1.5,HERE istay here as long as P1.S=1 MOV 2, #55H psince P1.5=0 send 55H to P2 Example: See if register A has an even number. Iso, make it odd. JB ACC. 0,NEXT jump if it is odd oe A@+ mvc A jit is even, make it odd NEXT: 2. Example: Monitor bit P14 continously. When it becomes high, send 55H to P2. SETB PL.4 rmake Pl.4 an input bit HERE: NB P1.4,HERE rstay here as long as P1.4=0 MOV 2, #55H isince Pl.4=1 send 55H to P2 Example: See if register A has an even number, If not, make it even. NB ACC.0,NEXT ijump if DO is 0 (even) me A :D=1, make it even NEXT: \JBC bit target Function: Jump if bt is st and clear bit Flags’ None If the desired bit is high it will jump to the target address; at the same time the bit is cleared to zero Example: The following instruction will jump to label NEXT if D7 of register A is high; at the same time D7 is cleared to zero. JBC ACC.7,NEXT NOV P1,A APPENDIX A 463, Notice that the target address can be no more than 128 bytes backward or 127 bytes forward since it is a 2-byte instruction, For more on this see SMP. (Cd) JC target Function: Jump if CY =1. None ‘This instruction examines the CY flag; if itis high, it will jump to the target address. JMP @A+DPTR Function: Jump indirect ‘None The JMP instruction isan unconditional jump toa target address. The target address is provided by the total sum of register A and the DPTR register. ince this is not a widely used instruction we will bypass further discussion of it ) INBbittarget See JB and JNB. “D) INC target L Function: Jump if no carry (CY = 0) ) JNZ target Function: Jump if accumulator is not zero None This instruction examines the CY flag, and ifit is zero it will jump to the target address. Example: Find the total sum of the bytes F6H, 98H, and 8AH. Save the caries in register R3, cuR Nov ADD ox INC ADD ane INC ADD onc INC Notice that this is a 2-byte instruction and the target address cannot be farther than -128 to +127 bytes from the program counter. See J condition for more on this. None This instruction jumps if register A has a value other than zero.

You might also like