Documente Academic
Documente Profesional
Documente Cultură
PUSH 4
POP 3
POP 5
POP 2
END
INC R7
NEXT:INC R0
DJNZ R5,AGAIN
END
We Are Ready, (b) receive any data send by PC and put it on LEDs
connected to P1, and (c) get data on switches connected to P2 and send it
to PC serially. The program should perform part (a) once, but parts (b) and
(c) continuously, use 4800 baud rate.
org 0000h
MOV TMOD,#20H
MOV TH1,#-3
MOV SCON,#50H
SETB TR1
AGAIN: MOV A,#'Y'
ACALL TRANS
MOV A,#'E'
ACALL TRANS
MOV A,#'S'
ACALL TRANS
SJMP AGAIN
TRANS: MOV SBUF,A
CLR TI
RET
End
mov r0,#40H
mov r5,#4H
again:clr a
movc a,@a+dptr
mov r6,a
swap a
anl a,#0fh
add a,#30h
mov @r0,a
inc r0
mov a,r6
anl a,#0fH
add a,#30H
mov @r0,a
inc r0
inc dptr
djnz r5,again
org 300H
mydata: db 76H,87H,98H,43H
end
mydata: db "87675649"
end
Experiment 11: Write an 8051 C program to toggle all the bits of P1
continuously.
#include<reg51.h>
void main(void)
{
for(;;)
{
P1=0x55;
P1=0xAA;
}
}
port P1.
#include<reg51.h>
void main(void)
{
char mynum[] = {1,-1,2,-2,3,-3,4,-4};
unsigned char z;
for(z=0;z<=8;z++)
P1=mynum[z];
}
#include<reg51.h>
sbit mybit=P1^0;
void main(void)
{
unsigned int z;
for(z=0;z<=50000;z++)
{
mybit=0;
mybit=1;
}
}
Experiment 14: Assume that 5 BCD data items are stored in RAM
locations starting at 40H, as shown below. Write a program to find the sum
of all the numbers. The result must be in BCD.
40=(71) 41=(11) 42=(65) 43=(59) 44=(37)
Write program in c.
#include<reg51.h>
void main(void)
{
unsigned char myarray []={71,11,65,59,37};
unsigned z=0;
unsigned s;
for(z=0;z<5;z++)
{
s=s+myarray[z];
}
P1=s;
}
P2=x;
y++;
}
}