ESI LabS Qstns
-
Upload
sagar-coolkarni -
Category
Documents
-
view
71 -
download
1
Transcript of ESI LabS Qstns
| ,/"
a-
LAB Session 1
Objectives
o 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 in the registers
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 lownibble of R1 in R0
Clear bit 3 of RAM location 22h without affecting any other bitMake the low nibble of R5 the complement of the high nibble of R6
Set the carry flag to l if the number is even set the carryflagto0if thenumberisodd
-'..tr:
-2
-4,-q\6".
MOV A,30H ;A=?MOV A,#30H ;A=?MOV A,R0 ;A=?MOV R0,#31H ;R0=?MOV A,@R0 ;A=?Mov A,d\s ;Doesthis comp-rle
MOV 3OH,#FFH )r:,MOV 31H,#OlHMOV 32H,#O2H
MOV 33H,#O3H
MOV A,30H ;A=?ADD A,32H ;A=?MOV 3OH,A ;A=?MOV A,31h ;A=?ADDC A,33H ;A=?
MOV 3OH,#8DH
MOV 81H,#30H 0y/1PUSH 30H
PUSH 3OH
PUSH 30HPUSH 3OH
MOV SP,#3OH
PUSH R7
PUSH R6 .,!." 1],
POP R7
POP R6
XCH A,R6
XCH A,R7-XCH A,R6
SETBC f*'- - D-',r
MOV 4,#100 /9t!0 x€ r.SUBRA,#1- \ rl o\.6'r
{)tl"
MOV A,R6
CPL A
MOV R6,4
XRL A,#OFFh
cLR ACC.1
SETB ACC.3
MOV RO,A
oRL 28h,#80hANL 28h,#7Fh5ET8 47h ,0cLR 47h ,0
MOV A,9Oh
ORL A,OAOh
MOV DPTR,#O1OOh .
MOVX @DPTR,A
MOV A,R3
RL A
ANL A,#OAAhPUSH ACE-.-MOV A,R3
RRA
ANL A,#055HMOV R3,APOP ACC
bluoyrng mE Ar]'lllelllaus i ru J uurP rlrruullrr,rr
MOV 30 H, #254MOV A,2ADD A,3OHADD A, #3OHMOV R7, + 100ADD A, R]MOVRO, # 31HADD A. GR1
MOV 3 OH, #FFHMOV 31H, +00MOv 32H, +02MOV 3 3H, #00MOV A. 30HADD A,32HMOV A/ 31HADDC A,33H
MOV A, +100SUBB A, +1
SETB C
MOV A, +100SUBB A, +1
MOV A, +3AHDEC AMOV R0/ + 15HMOV 15H. +12HINC ERO
DEC 15HINC RO
MOV 16H, AINC GRO
MOV DPTR/ +12FFHINC DPTRDEC 83H
MOV A, #42HADD A, + 13HDAAADD A, #1]HDAAADDC A, +34HDAAADDC a, # 11HDAA
MOV R0, #08HMOV R1, #2OHMORE :
MOV ,4R1.01HINC R1DJNZ RO, MORE
SJMP LOOP
oRG 0000HBEGIN:SJMP THEREoRG 0050HTHERE:AJMP YONDER
oRG 0400HYONDER iMOV A, +BOHMOV DPTR/ *OFFOOHJMP GA+DPTRORG O FFB OH
LJMP BEGTN
1. Add 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
19h and 1Ah
Lab Session 3
Program for Software delay using 12Mhz crystal
; Using a 12Mhz crys L.t I
Delay equDLYLSB .equDLWSB EqU
orcr 0000h
blink:setb P1.0mov a. * DLYLSB
' mov b. #DLYMSBacall de Iay_rout ineclr pl .0mov a, #DLYLSBmov b, * D]-YMSBacall delay_routinejmp btink
delay_routine:push 07hpush accorl a.bcjne a. #00h, okyvv auusjnp done
ok:pop acc
timer:mov r7l SDelay
Modify debugger crystal frequency to 12Mhz I
by changing in Proiect->Options for Target->Target tab->xtal(Mhzl
del ayt:ime :
nopnopnopnopdjnz 11 , de laytimenopnopdec acjne a, #0f fh, norol ldec b
noroll:cj ne a,#00h,Limercjne a, b, timer
done:pop 07hret
END
1. Write comments for the program.2. What is happening to port pin1.03. What is the software delay we are
Betting calculateHint(calculate the instr cyc taken byeach instr in delay loop)
4. Modifu the program to get 125ms
,200ms,650ms etc5. What does equ mean and why is it used
r)A6HOF4H
r l.db4iobiective:
. Introduction to enbedded Cprograrnming
. fnterfacing to T/O ports *.i'l
Prograrnl :
SincJ udecreg52. h>void main (void){
uns.igned char poxtl value;/^ i4usL set uI) pl fir reacling *.tP1 = 0xFE;while (1)t
/' * Rea.l the value of pi *,/'Portl value = p1;/ * Copi' t,he /a j ue to p2 * /P2: portl_valuei
]l
See the sinulation--\-. Connect PORT2 to LEDS---.-. Connect PORTI to switches----J. What happens if while(1) is removed fo_1. Write the above progran but with t'
i nverted value of p1
Progrram 2#incLude<reg52 . h>void main (void)i
l: Mult ser up F-1 for tea<tipq */P1 = oxFF;wh i-Ie ( I )
{
/* Make p? Hiqh */P2 = oxFF,De]ay_prg ( ) ,P2 = 0x00,Delay_Prg ( ) ;
))void Detay_prg (void )i
unsigned int i;for (i-6.iq56OOO; ir+ ) ;
l
How much defay does Delay_grve lWhat happens when inbteadunsigned int i we use inl
t tn,1 Llni,"6.
. what iGi;;---\- -,
Prograrr 4
*include<reg52 . h>void nain (void){
unsigned char cntr;/'. i*]st :i.i: l.?p tj r--c.rP1 = oxFF;wh j-le ( 1){
,/ ' i{iake !>2 ilig!) *,/P2: cntr++;De1ay_prg ( ) ;
.))void Delay_prg (void){
unsigned int i;for (i:0; iS500O0; i++) ;
l
. Can you make the output morelosi.cal? c,,,^1 up$ i"_^.--. What wifl the - slmbol do?
hsc" 1eU
Progla.m 3
#incl ude<reg52 - h>sbit LEDl=p2^1 ; / / Ied, onsbit SWT 1=p1^ 0; /,/switchvoid rnain (void){
'I ' riJs I s::;-. rp: i'.i . r r'P1 = 0x FF;whlle (1){
.:' i.ta iae a2 ii7i.J.n *,/LED1 = SWT1;
)
)
port2 . 1on port 1.0
t:oa.! irq *,/
1;eed.nq ^/
a,l I
P.g oo'8&9 s"..of
i?
erogram 15
*lnclude<reg52, h>ryoid main (void){
unsigned char i;int j,i-1;while ( 1 )
{p2 = -i.i : i << 1;
' if ri:-^\i = 1;
fntigram ?6#idcfude<req52 . h>deit LEDl=p2^l: / /Ied onsbit SWTL=P1".^0; / / swLtcl-Yoid main (void){
,/* Must set up pi forPl = oxpF; //!take pl aswhile ( L l{
if (swTr -= 0){
LED1 = 0,.)eIse{- LED1 = ltl
))
. What is the output of program?
. Make the progran run.s1ow.
. Make the program run only for 4leds.
//A€56 valwe o-r=ftnt, Z and. pin 3.3i=- (P3>>2)& 0x03; )'.5A=fzti_Pj.n3.-2 is pressed{
P2 ^= 0x01; / /rogqLe LedLl//it Pfn3,3 is pressedale6 ifli
-- ^ r\r -- z ,
{P2 ^- OxO2;
l
\t
l{
i:0x80;P2= -i;for (j-0; j<=32't 65; j++) ;i:i>>1;if (i=:0)i:0x80;
l
Program t fi#include<re95 2 . h>
//Make mi crocont rof le.r doidle tas kvoid Delay (void){
unsigned int j;//Just waste some timefor (j=0; j<=10000;j++) ;
I
void main (void)t
char iiP2 =0xFF; ,/ /rntialisewhile (1) /,/ Inf inite{
noth.ing or an
aII LEDrs OFFLoop
/ /loggIe Led2port2 .Ion porL 1.0
yeadiTtg */input vflhat is. the output with or without
delay? ldr'^{_Is there any problern in behavior ofthe code?If yes Explain it is happeningwhy
Obj ective:1. To learn2. Ao work
Prograe 1
I.,AB 5
to Initialize tinerswith interrupts
#include<reg52 . h>#def ine RELOAD_VAL_LSB*def ine RETOAD_VAL_MSBvoid main (void){
Pl = oxFF;TMOD &= 0xF0; //C]ear TineroTMOD l= 1xOL; //L6 bit Timero modeTLo : RELOAD_VAL_LSB;THO = RELOAD_VAL_MSB,TF0=0, rTRO:1;while (1){
P1 ^: 1xFF;while (TF1 :: 0) ; //wait for overffowTLO = RELOAD_VAL_LSB;THo = REIOAD_VAL_MSB;TF0=0;
]l
1. Calcufate the reload values for50ms For a IL. O592Mhz crystal.
2. Make the LED blink with a 100ns^"^16
Progra! 2
change the above program to norkwith timer 1
Enable the Gate pin and see the
Progran 4
#incfude<reg52. h>
#define RELOAD*VAL_LSB#def ine RELOAD_VAL_MSB
void Timero_I SR (void) interrupl 1 using{
P7 ^: 1xFF;Tl,0 = RELOAD*VAL_LSB;THO : RELOAD_VAL_MSB;
TFO:O;
l
void nain (void )
iP1 : oxFF;TMOD &= 0xFo; ,//C1ear TimeroTMOD l= 0xA7; / /1-6 bit Timer' modeTLO : RELOAD_VAL-LSB'THo - RELOAD_VAL_MSB,TFO = 0;ETO = 1;EA : 1;TRO - 1;while (1 )
{
)
)
1. Calculate the reload values for25ms For a 11.0592Mh2 crystal.
2. Make the LED blink with a 500mscycfe.
3. Change the program to use Timerl4. Write a program to blink feds's
with different rates of100rns. 20Oms. 30Ons, 40Oms (Hint: Usedifferent variables for differenttimings )
1-
3. What happens if you make the catepin low ,/high
Progra.! 3
1. write a program to put both timersin counter mode .
2. Apply pulse using switches on theT0(P3.4) and T1(P3.5) pin anddisplay output on the Leds
I,AB 6
Program 1
# include<reg52 . h>
void SeriaI_Init o{
SMOD = 0x52;TMOD &= 0x0 F,TMoD l= 6129'PCON I =0x8 0;1111 = lunsigned char) (256 - (1"1059200 / (I6L * L2L * 9600) ) ),TI=1;RI=0 t
]
void main (void )
{unsigned char ch,'Serial_Init ( ) ;whife (1)t
if(Rr){
ch=SBUF;while(lTI);SBUF=ch,
)
)
)
1. Conment the above code2. Set the Terminal program to 9600-8-n-l- and see the output t
3. What is the TH1 reload value?4. Change the program to baud rate of 192005. Make SMoD=O and find the baud rate6.
1. Writ.e a program to convert a alphabet from fower case to uppercase and vice versa i,e if you send 'a' 8051 should sent tAt andfor 'A' char transmitted should be 'a'-
2. Write a program to control the led's by using the serial po.rt.Foreg if you send 'f it shoul-d switch one of the leds and if yousend t2' it should switch of the fed
3. Print the numbe.r of button presses by the user. (Hint:Use libraryfunction itoa O )
ExtraHow to work with printf read the manuaf and implement the same.
I.AB 7Interfacing a ? seg BCD and 16 key ket1)ad to gOSl.
# incluale<reg52 . b>.
l: P9l pI, p2 and p3 are predefined port names andare bit actdressable +/
unsigned char SetDisplay (unsigned cha! value) {
unsigned char IrookupTable { 111 = { OxCo, ... };/* check to see if',va1ue" is in bounds,if not return an error */if ( ) {
- /* letuln appropriate value +/,lelse I
/* return error vaLue */i)
l
/* DeLay function */void del.ay ( ) {
int i. ji
for (i=0; i<1OOO; i++)for (j =0; j<1O0; j++)
i = i + 0;)
void main (voLd) {uosigned char count = 0;
Place */ /* value hefd in one's
for (i-0; i<4,- i++) {
/* Set each roi, to O */p1 _ oxff 6 _(1<<i),
- /* Scan each colulnn to seewhich key was pressecl */for (j=4; j<e; j++) (
/i Code to determine
key which $ras
/* return (position) '/)
the position of the
pressecl */
I
void maiD ot
/* you can have akey positlon into a
vafid nulnber olsyrnbols resu.It in
elrors aDd map
conversion table to convert the
fetter. The
into postion 1? of theLookupTable */
unsigned charr, 2, 3,4, 5, 6,'7, A, 9t
11, O, 71,
conv_tabfe [ ] = {10,11,12,13
whj.re (1) {/' determine and display the one,s place *//* determine and dipslay the ten's nfu.. ,)/* update the counter (remenber to keep itwithin bounds ) */
de.layO t)
l
/* main.c */
lichar num;
while {1) t. /*read input ftom user */
/* disp.lay corresponding nurnber */)
Write a program touser lnput number
display theon the dispfay
,/* Reacl from a keypad and disptay/* on an 7-segment displav */#praqma sMAr,L DB OE*include <reg51.b>
unsignecl cbar SetDisp.l ay (unsignedunsigned char LookupTable II7]/* use code from previous Iab
- /. fitl in entries to tabfe toD' E, F */I
the key pressed */
char value) {= I 0xc0, ... l;
bandle A, B, C,
/+ Rout:ine to scan the kevunsigne d char key_scanO '
unsigrned cha! i, j,
while(1)/*keeDpressed * /
pressed */
ternpl, temp2;
!,raiting for a key to be
LAB 8
tCD in nibble nodeP0.0 -->D0P0-1 -->D1P0.2 -->D2P0.3 -->D3P0.4 -->ENP0.5 -->R/SP0.6 -->P0. ? --> *'******** /+include<re951 . h>
sbi-t aN = P0^4tsbit RS = P0"5;
void delay (unsigned char Delval){
for ( ; DeLval l=0; De1val-- ) ;
)void delay ms (unsigned int Delval-ns){
for (i Delval-ms !=0; Delval-ns--){
delay(165),)
)void Lcd_Dat (unsigned{
RS=1,delay(20);
unsiqned char data count ;Lcd_cnd ( cu r_p os n ) tdelay_ms (1) ;
for ( count=0 r count<16; count++ )
{if ( arr Icount] ==0 ){
0coffItand,1data
defay{20);EN=1;delay(20)rEN=otdelay (700 ) ;
P0 &= 0xF0;P0 l= 0x02;delay (20 ) iEN=1;defay(20);EN=o;delay(700)t
Lcd_Cmd(0x28),delay (5000) tLcd_cmd (0x0c) ;delay (5000 ) tLcd_cmd (0x06) ;defay (5000 ) ;
Lcd_Cmd(0x01);delay{1000);
char 1cd char)
)void Dispfay_Lcdcurjosn){
bit ovri
(unsiqned char
ovr=1;brea ki
Dat {arr Icount] ) ;
*arr, unsiqned cha!
P0 e= 0xF0;P0 l- (lcd_cha!>> i e 0x0F;delay(20) t EN=1;defay(20);EN=o;delay(?00)rP0 &= 0xF0;P0 l= (lcd*char) & 0x0Fidelay(20);EN=1tdelay {20 ) tEN=otdelay{700);
Ivoid l,cd-cnd ( unsigned char fcd-char){
RS=0;delay(20);P0 &= 0xf0tP0 l- {fcd_char>>4) e 0x0Eidelay(20);EN=1,delay(20);5N=0tdelay(700)i
detay(20)tP0 e= 0xF0;P0 l= (fcd_char) & 0x0E;delay(10),'EN-1;delay(20);EN-0;delay (700) ;
)
T
)if ( !ovr){
l,cd Cnd (0xc0 ) ;forlcount=16; count<32; count++ )
{i f (alr Icouot ] ==0 )
bteak;Lcd Dat (arr I couot I );
]Lcd
))
ovr=0;)
void Lcd_Char (unsignedcurjosD){
char charvaf, unsigned char
l,cd_cmd (cur_posn) ;delay(700);
],cd_Dat icbaxval ) ;l
void nain (void){
unsigned int i;Lcd_Init ( );Display_Lcd ( I'HI", 0x80) ;white (1)
Lcd_Init ( )
RS=0tP0 &= 0xr0tP0 l= 0x03'defay(100);
delay(20);EN=1;defay(20)iEN=o;delay (700) ;
defay(20)rEN=1tdefay (20) ;EN=0,delayi700) t
{
pin LOGIC used
here)
l
p0 ^= oxFF; /./Toggle the PORT2
is 0 XOR 1=1 or 1 xOR 1=0forri=0;i<25000,'i-+) r//waste Time
use the proglarn from LAB 7 and l,AIlB to create a s irnpJ.e calculator.
_\
LAB 9 Temperature Sensor Acquisition Modules
Specification
1, Your device will sample the temperature every second, storing it as a8-bit unsigned value in the EEPROM.
2. You must use the 8051 timer interrupt to indicate when a sampleshould be taken.
3. The vafue stored should be encoded as the binary representatj.on ofthe temperatue measured in degrees Fahrenheit without the fractionalvafue (i.e. 98.7 - > 98).
4. While sampling, your device shoufd output on a 15-character LCD thefollowing:
I Tenp: 54F 128 I
Where 54E is the current temperature measured by the sensor and l-28is the current number of samples stored in the EEPROM.
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 programusing the protocol- described befow.
7. Communication ProtocoL1. 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 beentransmitted.
1 . lvotes:2. Your device shoufd be abfe to continuously sample the
temperature every second while also monitoring the seria.Iport lo detect the initiation control word from thetemperature downfoad program.
3. While communication with the temperature download programis in progress, your device should not sample thetemperature, as this will disrupt the serial cornmunication,
6. If any error in the conrnunication occurs, your device shouldtemporarily display a message indicating what the error was.
8. Use programs from previous fabs and the I2C.c program given.
LAB4-9fornat
Introduction:- What is the purpose of the LAB
Components used
Schematic of the Hardware if
Theory about working of the
P rocedure
attenpt and understand the
any
peripheral or hardware
Student Observations
This wiJ.l vary f,ron student to student -' Please
pt"g";t-tii"-" g""at wil} depend upon this