ESI LabS Qstns

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

|

,/"

LAB Session
Objectives

o .
a-

Getting acquainted with the development environment for 805 I Study the data transfer and logical instructions

Please type in this assembly programs and find the change MOV A,30H MOV A,#30H MOV MOV R0,#31H MOV A,@R0
;A=? ;A=? ;A=? ;R0=? ;A=?

in the registers

A,R0

Mov

A,d\s

MOV 3OH,#FFH MOV 31H,#OlH MOV 32H,#O2H MOV 33H,#O3H MOV A,30H ;A=?
;A=? MOV 3OH,A ;A=? MOV A,31h ;A=? ADDC A,33H ;A=? ADD

)r:,

MOV 3OH,#8DH MOV SP,#3OH MOV 81H,#30H 0y/1 PUSH R7


PUSH 30H PUSH 3OH PUSH 30H PUSH 3OH PUSH POP R7 POP R6

R6 .,!."

1],

;Does

A,32H

this comp-rle

XCH A,R6

SETBC

f*'- -

D-',r

MOV A,R6
CPL A

XCH A,R7XCH A,R6

/9t!0 x r. SUBRA,#1- \ rl o\.6'r


MOV 4,#100

cLR ACC.1
SETB ACC.3

MOV R6,4
XRL A,#OFFh

{)tl"
oRL 28h,#80h ANL 28h,#7Fh

MOV RO,A

MOV A,9Oh
ORL A,OAOh

MOV A,R3
.

,0 cLR 47h ,0
5ET8 47h

MOV DPTR,#O1OOh MOVX @DPTR,A

RL A ANL A,#OAAh
PUSH

ACE-.-

MOV A,R3
RRA ANL A,#055H

MOV R3,A
POP ACC

-'..tr:

-2
-4,

Copy the data at internal RAM location 70h to R0 and R3 Rotate the bytes in registers R0 to R3;copy the data in R0 to R1,R1 to R2,R2 to R3 and R3 to R0. Exchange both the low nibbles of registers R0 and R1 put the low nibble of R0 in R1 and the low nibble of R1 in R0

-q \6".

Clear bit 3 of RAM location 22h without affecting any other bit Make the low nibble of R5 the complement of the high nibble of R6 Set the carry flag to if the number is even set the carryflagto0if thenumberisodd

bluoyrng mE Ar]'lllelllaus i ru J uurP rlrruullrr,rr


MOV 30 H, #254
MOV

A,2

ADD A,3OH ADD A, #3OH MOV R7, + 100 ADD A, R]


MOVRO,
#

MOV 3 OH, MOV 31H, MOv 32H, MOV 3 3H,

#FFH

+00 +02 #00

MOV A. 30H

ADD A,32H
MOV A/ 31H ADDC A,33H

31H

ADD A.

GR1

MOV A, +100 SUBB A, +1 MOV A, +3AH DEC A MOV R0/ + 15H

SETB

MOV A, +100 SUBB A, +1 MOV A, #42H ADD A, + 13H

DAA
ADD A, #1]H

MOV 15H. +12H

INC INC INC INC

ERO RO GRO

DAA
ADDC A, +34H

DEC 15H
MOV 16H, A
MOV DPTR/ +12FFH
DPTR

DAA
ADDC a,
#

11H

DAA

DEC 83H

oRG 0000H
MOV R0, #08H MOV R1, #2OH
MORE :

BEGIN:

SJMP THERE oRG 0050H


THERE:

MOV ,4R1.01H

INC

DJNZ

R1 RO, MORE SJMP LOOP

AJMP YONDER oRG 0400H


YONDER

MOV A, +BOH MOV DPTR/ *OFFOOH

JMP GA+DPTR
ORG
O

FFB OH

LJMP BEGTN the number 84h to the contents in RAM location 17h and 18h 2. Subtract the contents of R1 from r0 and put it in 17 3. lncrement and decrement the value in RAM location 13,14,15 using indirect addressing 4. Multiply the data in ram location 22h by the data in RAM location 15h put the result in RAM location
1. Add

19h and 1Ah

Lab Session 3
Program for Software delay using 12Mhz crystal

Modify debugger crystal frequency to 12Mhz by changing in Proiect->Options for Target>Target tab->xtal(Mhzl

Using

12Mhz crys L.t I


r)A6H OF4H

del ayt:ime
nop

Delay
DLYLSB

equ
.equ
EqU

DLWSB

nop nop nop nop nop

orcr 0000h

djnz
a

11

de

laytime

blink: '

P1.0 mov a. * DLYLSB mov b. #DLYMSB

setb

dec

acall de Iay_rout ine clr pl .0


mov a, mov b,
#DLYLSB
* D]-YMSB

noroll:
done:

dec b

cjne

a, #0f fh, norol

cjne ret

cj ne a,#00h,Limer a, b, timer

acall delay_routine jmp btink


END

pop 07h

delay_routine:
push 07h push acc orl a.b

cjne sjnp

a. #00h, ok
done

1. Write comments for the program. 2. What is happening to port pin1.0 3. What is the software delay we are
Betting calculate

yvv

auu

ok:

timer:

pop acc
mov r7l SDelay

4. 5.

Hint(calculate the instr cyc taken by each instr in delay loop) Modifu the program to get 125ms
,200ms,650ms etc

What does equ mean and why is it used

r
iobiective: . .
prograrnming

l.db4
Progla.m
C

Introduction to enbedded

fnterfacing to T/O ports *. i'l Prograrnl : void main (void)


{

sbit LEDl=p2^1 ; / / Ied, on port2 . 1 sbit SWT 1=p1^ 0; /,/switch on port 1.0 void rnain (void)
{

#incl ude<reg52 - h>

SincJ udecreg52. h>

whlle (1)
{

P1 =

'I

'

riJs

s::;-. rp:

i'.i

0x FF;

. r r' t:oa.!

irq *,/

.:'
) )

i.ta

iae

while (1)
t

uns.igned char poxtl value; /^ i4usL set uI) pl fir reacling *.t P1 = 0xFE;

LED1

a2

ii7i.J.n *,/

SWT1;

* Rea.l the value of pi *,/' Portl value = p1; / * Copi' t,he /a j ue to p2 * / P2: portl_valuei
/'

. what iGi;;--\Prograrr
4

-,

--\-. ---.-. ----J. .

See the sinulation Connect PORT2 to LEDS Connect PORTI to switches What happens if while(1) is removed fo_1 t' Write the above progran but with
i nverted
2

void nain (void)


{

*include<reg52 . h>

unsigned char cntr;


P1 = oxFF; wh j-le ( 1)
{

/'. i*]st :i.i:

l.?p

tj

r--c.r

1;eed.nq ^/

value of

p1

Progrram
i

' i{iake !>2 ilig!) P2: cntr++;


,/

*,/
a,l

void main (void)

#incLude<reg52 . h>
)

.)
F-1

De1ay_prg ( ) ;

l: Mult ser up P1 = oxFF;


wh {

for

tea<tipq

*/

void Delay_prg (void)


{

i-Ie ( I

P2 = oxFF, De]ay_prg ( ) , P2 = 0x00, Delay_Prg ( ) ;


) )

/*

Make

p? Hiqh */

unsigned int i; for (i:0; iS500O0; i++)

. .

Can you make the output more losi.cal? c,,,^1 up$ What wifl the - slmbol do?

i"_^.--

hsc" 1e U
)

void
i l

Detay_prg (void

unsigned

for (i-6.iq56OOO; ir+

int i;

);

How much defay does Delay_ P.g o grve l o'8&9 What happens when inbtead of unsigned int i we use inl i?

s"..

tn,1

Llni,"6.

erogram

15

*lnclude<reg52, h> ryoid main (void)


{

while
{

int j, i-1;

unsigned char
(1 )

i;
Program t

#include<re95

fi

2 . h>

'

= -i. i : i << 1;
if

p2

i
l
{

ri:-^\ = 1;

idle tas k void Delay (void)


{

//Make

mi

crocont rof le.r do noth.ing or an

t
l

-i; for (j-0; j<=32't 65; j++) ; i:i>>1; if (i=:0) i:0x80;


P2= What Make Make

i:0x80;

unsigned int j; //Just waste some time for (j=0; j<=10000;j++) ;

void main (void)


t

P2 =0xFF; ,/ /rntialise aII LEDrs while (1) /,/ Inf inite Loop

char ii
{

OFF

. . .

leds.

is the output of program? the progran run.s1ow. the program run only for 4

//A56 valwe o-r=ftnt, Z and. pin 3.3 i=- (P3>>2)& 0x03; )'.

5A=fzti_Pj.n3.-2 { l//it
ale6 ifli

is

pressed

Yoid main (void)


{

fntigram ?6 #idcfude<req52 . h> deit LEDl=p2^l: / /Ied on port2 .I sbit SWTL=P1".^0; / / swLtcl- on porL 1.0

P2 ^= 0x01; / /rogqLe LedL Pfn3,3 is pressed


\r --z r, ^

P2
l

^-

OxO2;

/loggIe

Led2

while
{

,/* Must set up pi for yeadiTtg */ Pl = oxpF; //!take pl as input


(L

if
{ )

(swTr
LED1

-=
0,.

0)

is. the output with or without delay? ldr'^{_ Is there any problern in behavior of the code? If yes Explain why it is happening
vflhat

eIse

) )

LED1

= lt

I.,AB 5
Obj

Progran 4 #incfude<reg52.

h>

ective: 1. To learn to Initialize tiners 2. Ao work with interrupts


1

#define #def ine


{

RELOAD*VAL_LSB
RELOAD_VAL_MSB
SR

Prograe
#def

void Timero_I :

(void) interrupl 1 using

#include<reg52 . h>

void main (void)


{

*def ine

ine

RELOAD_VAL_LSB
RETOAD_VAL_MSB

P7 ^: 1xFF; Tl,0 = RELOAD*VAL_LSB;


THO
RELOAD_VAL_MSB;

TFO:O;

&= 0xF0; //C]ear Tinero TMOD l= 1xOL; //L6 bit Timero TLo : RELOAD_VAL_LSB;
TMOD

Pl =

oxFF;

l
mode

void nain (void


i

THO

TF0=0, r TRO:1; while (1)


{

RELOAD_VAL_MSB,

0) ; //wait TLO = RELOAD_VAL_LSB; THo = REIOAD_VAL_MSB; TF0=0; ]

P1 ^: 1xFF; while (TF1 ::

for overffow

while
{ )

: RELOAD_VAL-LSB' - RELOAD_VAL_MSB, = 0; = 1; EA : 1; TRO - 1;


TLO THo TFO ETO
(1
)

P1 : oxFF; TMOD &= 0xFo; ,//C1ear Timero TMOD l= 0xA7; / /1-6 bit Timer'

mode

1. Calcufate the reload values for 50ms For a IL. O592Mhz crystal. 2. Make the LED blink with a 100ns
^"^16

1. Calculate the reload values for 25ms For a 11.0592Mh2 crystal. 2. Make the LED blink with a 500ms 3. Change the program to use Timerl 4. Write a program to blink feds's with different rates of different variables for different
timings
)

Progra!

cycfe.

1- change

the above program to nork with timer 1 Enable the Gate pin and see the

100rns. 20Oms. 30Ons, 40Oms

(Hint:

Use

3. What happens if you make the cate pin low ,/high


Progra.!
3

1. write a program to put both timers in counter mode . 2. Apply pulse using switches on the T0(P3.4) and T1(P3.5) pin and display output on the Leds

I,AB

Program
#

include<reg52 . h>

void SeriaI_Init o
{

0x52; &= 0x0 F, TMoD l= 6129' PCON I =0x8 0;


SMOD

TMOD

1111

TI=1;
]

= lunsigned char) (256 -

(1"1059200

/ (I6L * L2L *

9600) ) ),

RI=0 t

void
{

main (void
(

unsigned char ch,' whife


t
{

Serial_Init
(1)

);

if(Rr) while(lTI);
SBUF=ch,
)

ch=SBUF;

1. Conment the above code 2. Set the Terminal program to 9600-8-n-l- and see the output 3. What is the TH1 reload value? 4. Change the program to baud rate of 19200 5. Make SMoD=O and find the baud rate
6.

1. Writ.e a program to convert a alphabet from fower case to upper case and vice versa i,e if you send 'a' 8051 should sent tAt and for 'A' char transmitted should be 'a'2. Write a program to control the led's by using the serial po.rt.For eg if you send 'f it shoul-d switch one of the leds and if you send t2' it should switch of the fed 3. Print the numbe.r of button presses by the user. (Hint:Use library function itoa O )
Extra
How

to work with printf read the manuaf and implement the

same.

I.AB
#

7
ket1)ad

for (i-0; i<4,- i++)

Interfacing a ? seg BCD and 16 key


incluale<reg52 . b>.

to

gOSl.

p1

/* Set each roi, to O */ _ oxff 6 _(1<<i),


see

pI, p2 and p3 are predefined port l: P9l are bit actdressable +/

names and

which key was pressecl


the position of the

*/

/* Scan each colulnn to for (j=4; j<e; j++) ( /i


Code

unsigned char SetDisplay (unsigned cha! value) { unsigned char IrookupTable { 111 = { OxCo, ...

to

determine
$ras

};

/* check to see if',va1ue" is in bounds, if not return an error */ if ( ) { /* letuln appropriate value +/, l else I /* return error vaLue */i
l
)

pressecl

*/
)

key which

/* return (position) '/

void
t

maiD

/* DeLay function */ void del.ay ( ) { int i. ji for (i=0;


)

to convert the vafid nulnber ol fetter. The syrnbols resu.It in elrors aDd map into postion 1? of the LookupTable */
key positlon

/*

you can have

into

conversion table

i<1OOO; i++) for (j =0; j<1O0; j++)

unsigned char conv_tabfe

i = i + 0;

void main (voLd) { uosigned char count = 0; Place */


whj.re

li
/* value hefd in one's

4, 5, 6, '7, A, 9t 11, O, 71,


num;

r, 2,

3,

10, 11, 12,


13

] =

char
while

/' determine and display the one,s place */ /* determine and dipslay the ten's nfu.. ,) /* update the counter (remenber to keep it within bounds ) */
de.layO t

(1)

{1) t . /*read input ftom user */ /* disp.lay corresponding nurnber */

/* main.c */
,/* Reacl from a keypad and /* on an 7-segment displavdisptay the key pressed */ */
#praqma

Write a program to display the user lnput number on the dispfay

*include

sMAr,L DB

<reg51.b>

OE

unsignecl cbar SetDisp.l ay (unsigned char value) { unsigned char LookupTable II7] = I 0xc0, ... l; /* use code from previous Iab /. fitl in entries to tabfe to bandle A, B, C, D' E, F */
I

/+ Rout:ine to scan the kev pressed unsigne d char key_scanO '


unsigrned cha! i, j,

*/

ternpl, temp2; !,raiting for


a

pressed

while(1)/*keeD */

key to

be

tCD in nibble node


P0.0 P0-1 P0.2 P0.3 P0.4 P0.5 P0.6
-->D0
-->D1 -->D2

LAB

defay{20);EN=1; delay(20)rEN=ot delay (700 ) ; P0 &= 0xF0;

P0 l= 0x02; delay(700)t

-->D3
-->EN

delay (20 ) iEN=1; defay(20);EN=o;


Lcd_Cmd(0x28), delay (5000) t

--> P0. ? -->

-->R/S

0coffItand,1data

*'******** /

+include<re951 . h>

sbi-t aN = P0^4t sbit RS = P0"5;

Lcd_cmd (0x0c) ; delay (5000 ) t Lcd_cmd (0x06) ; defay (5000 ) ;

Lcd_Cmd(0x01);

void delay (unsigned char Delval)


{

delay{1000);
) void Dispfay_Lcd (unsiqned char *arr, unsiqned cha! curjosn) {

for

DeLval l=0; De1val-- ) ;

void delay ms (unsigned int Delval-ns)


{

bit ovri

for (i Delval-ms !=0; Delval-ns--)


{ )

unsiqned

char data count


os n ) t

delay(165),

Lcd_cnd ( cu r_p delay_ms (1) ;


{

for ( count=0 r count<16; count++ char 1cd char)

void
{

Lcd_Dat (unsigned
RS=1,

if arr Icount] ==0 )


(

delay(20);

P0 e= 0xF0;

brea ki Lcd Dat {arr Icount] ) ;


]

ovr=1;

delay(20) t EN=1; defay(20);EN=o;

P0 l- (lcd_cha!>> i e 0x0F; if
{ )

delay(?00)r

!ovr)

P0 &= 0xF0;

delay(20);EN=1t delay {20 ) tEN=ot

P0 l= (lcd*char) & 0x0Fi

l,cd Cnd (0xc0 ) ; forlcount=16; count<32; count++


{

delay{700);

void
{

l,cd-cnd ( unsigned char fcd-char)


RS=0;
)

i f (alr Icouot ] ==0 ) bteak; Lcd Dat (arr I couot I );

delay(20); P0 &= 0xf0t P0 l- {fcd_char>>4) e 0x0Ei


delay(20);EN=1, delay(20);5N=0t

ovr=0;
)

void Lcd_Char (unsigned char charvaf, unsigned char curjosD)


{

delay(700)i detay(20)t

l,cd_cmd (cur_posn) ;

delay(700);
& 0x0E;

P0 e= 0xF0;

P0

delay(10),'EN-1; delay (700) ;


)
T

l= (fcd_char)

],cd_Dat icbaxval ) ;

delay(20);EN-0;

void nain (void)


{

unsigned int i;

Lcd_Init
RS=0t

()

Lcd_Init ( );
{

Display_Lcd ( I'HI", 0x80) white (1)

defay(100);
delay(20);EN=1; defay(20)iEN=o; delay (700) ; defay(20)rEN=1t
defay (20) ;EN=0, delayi700) t

P0 &= 0xr0t P0 l= 0x03'

pin
here

LOGIC used

p0 ^= oxFF; /./Toggle the PORT2 is 0 XOR 1=1 or 1 xOR 1=0 forri=0;i<25000,'i-+) r//waste Time

use the proglarn from LAB 7 and l,AIl B to create a s irnpJ.e calculator.

_\

LAB

9 Temperature Sensor Acquisition Modules


a

Specification
1, Your device will sample the temperature every second, storing it as 8-bit unsigned value in the EEPROM. 2. You must use the 8051 timer interrupt to indicate when a sample should be taken. 3. The vafue stored should be encoded as the binary representatj.on of the temperatue measured in degrees Fahrenheit without the fractional vafue (i.e. 98.7 - > 98). 4. While sampling, your device shoufd output on a 15-character LCD the

following:

I Tenp: 54F 128


Where 54E

is the current temperature measured by the sensor and is the current number of samples stored in the EEPROM.

l-28

5. The most recent 128 samplings shouJ-d be stored on the EEPROM. 6. A program wiff be provicied to down.Ioad the Lemperatures from your device. You will need to implement' communication with this program using the protocol- described befow. 7. Communication ProtocoL 1. When the temperature downfoad program wishes to downfoad data, it wiff first transmit the initiation controf word of Oxaa. 2. Your device has to provide an acknowl-edge control word of 0x73. 3. You devj-ce wil-L then transmit an 8-bit unsigned value indicating the number of temperature samples it plans to transmit. 4. Your device shoul-d then transmit each of the temperature samples read from the EEPROM. 5. The temperature down]oad prog.ram will respond with an acknowledge control word of 0x49 after all samples have been transmitted. 1 . lvotes: 2. Your device shoufd be abfe to continuously sample the temperature every second while also monitoring the seria.I port lo detect the initiation control word from the
temperature, as this will disrupt the serial cornmunication, 6. If any error in the conrnunication occurs, your device should temporarily display a message indicating what the error was. 8. Use programs from previous fabs and the I2C.c program given.
temperature downfoad program. 3. While communication with the temperature download program is in progress, your device should not sample the

LAB4-9fornat
Introduction:- What is the purpose of the
Components used
LAB

Schematic of the Hardware if any

or hardware Theory about working of the peripheral


P

rocedure

Please attenpt and understand the This wiJ.l vary f,ron student to studentthis -' g""at wil} depend upon pt"g";t-tii"-"

Student Observations

You might also like