Professional Documents
Culture Documents
ESI LabS Qstns
ESI LabS Qstns
ESI LabS Qstns
,/"
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:,
R6 .,!."
1],
;Does
A,32H
this comp-rle
XCH A,R6
SETBC
f*'- -
D-',r
MOV A,R6
CPL A
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
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
A,2
#FFH
MOV A. 30H
ADD A,32H
MOV A/ 31H ADDC A,33H
31H
ADD A.
GR1
SETB
DAA
ADD A, #1]H
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:
MOV ,4R1.01H
INC
DJNZ
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
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
del ayt:ime
nop
Delay
DLYLSB
equ
.equ
EqU
DLWSB
orcr 0000h
djnz
a
11
de
laytime
blink: '
setb
dec
noroll:
done:
dec b
cjne
cjne ret
cj ne a,#00h,Limer a, b, timer
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
r
iobiective: . .
prograrnming
l.db4
Progla.m
C
Introduction to enbedded
sbit LEDl=p2^1 ; / / Ied, on port2 . 1 sbit SWT 1=p1^ 0; /,/switch on port 1.0 void rnain (void)
{
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
-,
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
*include<reg52 . h>
l.?p
tj
r--c.r
1;eed.nq ^/
value of
p1
Progrram
i
*,/
a,l
#incLude<reg52 . h>
)
.)
F-1
De1ay_prg ( ) ;
for
tea<tipq
*/
i-Ie ( I
/*
Make
p? Hiqh */
. .
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
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
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;
//Make
mi
t
l
i:0x80;
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
fntigram ?6 #idcfude<req52 . h> deit LEDl=p2^l: / /Ied on port2 .I sbit SWTL=P1".^0; / / swLtcl- on porL 1.0
P2
l
^-
OxO2;
/loggIe
Led2
while
{
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>
RELOAD*VAL_LSB
RELOAD_VAL_MSB
SR
Prograe
#def
void Timero_I :
#include<reg52 . h>
*def ine
ine
RELOAD_VAL_LSB
RETOAD_VAL_MSB
TFO:O;
&= 0xF0; //C]ear Tinero TMOD l= 1xOL; //L6 bit Timero TLo : RELOAD_VAL_LSB;
TMOD
Pl =
oxFF;
l
mode
THO
RELOAD_VAL_MSB,
for overffow
while
{ )
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
(Hint:
Use
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
{
TMOD
1111
TI=1;
]
(1"1059200
/ (I6L * L2L *
9600) ) ),
RI=0 t
void
{
main (void
(
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
same.
I.AB
#
7
ket1)ad
to
gOSl.
p1
names and
*/
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
void
t
maiD
to convert the vafid nulnber ol fetter. The syrnbols resu.It in elrors aDd map into postion 1? of the LookupTable */
key positlon
/*
into
conversion table
i = i + 0;
li
/* value hefd in one's
r, 2,
3,
] =
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)
/* main.c */
,/* Reacl from a keypad and /* on an 7-segment displavdisptay the key pressed */ */
#praqma
*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
*/
pressed
while(1)/*keeD */
key to
be
LAB
P0 l= 0x02; delay(700)t
-->D3
-->EN
-->R/S
0coffItand,1data
*'******** /
+include<re951 . h>
Lcd_Cmd(0x01);
delay{1000);
) void Dispfay_Lcd (unsiqned char *arr, unsiqned cha! curjosn) {
for
bit ovri
unsiqned
delay(165),
void
{
Lcd_Dat (unsigned
RS=1,
delay(20);
P0 e= 0xF0;
ovr=1;
P0 l- (lcd_cha!>> i e 0x0F; if
{ )
delay(?00)r
!ovr)
P0 &= 0xF0;
delay{700);
void
{
ovr=0;
)
delay(700)i detay(20)t
l,cd_cmd (cur_posn) ;
delay(700);
& 0x0E;
P0 e= 0xF0;
P0
l= (fcd_char)
],cd_Dat icbaxval ) ;
delay(20);EN-0;
unsigned int i;
Lcd_Init
RS=0t
()
Lcd_Init ( );
{
defay(100);
delay(20);EN=1; defay(20)iEN=o; delay (700) ; defay(20)rEN=1t
defay (20) ;EN=0, delayi700) t
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
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:
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
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