8051_codes
8051_codes
P0 80h* Port0
P1 90h* Port 1
P2 0A0h* Port 2
P3 0B0h* Port 3
B 0F0h*
• - Bit Addressable
F0h F7 F6 F5 F4 F3 F2 F1 F0
E0h E7 E6 E5 E4 E3 E2 E1 E0
D0h D7 D6 D5 D4 D3 D2 D1 D0
B8h -- -- -- BC BB BA B9 B8
B0h B7 B6 B5 B4 B3 B2 B1 B0
A8h AF -- -- AC AB AA A9 A8
A0h A7 A6 A5 A4 A3 A2 A1 A0
98h 9F 9E 9D 9C 9B 9A 99 98
90h 97 96 95 94 93 92 91 90
88h 8F 8E 8D 8C 8B 8A 89 88
80h 87 86 85 84 83 82 81 80
Table 4
6 -- Not implemented
inc r4 ;increment r4
ajmp end1 ;jump to label end1
inc r4 ;increment r4
here:sjmp here
end
Input Location:9000h,9001h,9002h,9003h
Output Location:900ah
Output : 2222h
2 nd method
here:sjmp here
end
To convert packed BCD to ASCII, it must first be converted to to unpacked BCD. Then the
unpacked BCD is tagged with 30h.
swap a ;Swap a
here:sjmp here
end
Input: 45
Output:34 35
To convert ASCII to packed BCD, it is first converted to unpacked BCD(to mask 3) and
then combined to make packed BCD. For example, for 4 and 5 the keyboard gives 34 and
inc r0 ;Increment R0
here:sjmp here
end
Input:35
Output:
dec r1 ;decrement r1
div ab ;divide a by b
here:sjmp here
end
inc r1 ;increment r1
dec r2 ;decrement r2
here:sjmp here
end
Output:
I block:9000h: 01 02 03 04 05
swap a ;swap a
sjmp here
here:sjmp here
end
Input:99
Output:63
here:sjmp here
end
div ab ;divide a by b
here:sjmp here
end
Input: 05 02
Output:01
here:sjmp here
end
Input:45
Output:34 35
div ab ;divide a by b
div ab ;divide a by b
sjmp end1
sjmp end1
div ab ;divide a by b
here:sjmp here
end1:sjmp end1
end
Input: 0ffh
Output:02 05 05
here:sjmp here
end
div ab ;divide a by b
sjmp here
sjmp l2
here:sjmp here
end
Input: 05 02
Output:0ah
here:sjmp here
end
Input: 1122, 33
Output:369c6h
clr a ;clear a
dec r1 ;decrement r1
sjmp here
here:sjmp here
end
Input:05,
9000h: 01 02 03 04 05 06 07 08 09 0a
Output:0ff
dec r3 ;decrement r3
here:sjmp here
end
inc r0 ;increment r0
div ab ;divide a by b
inc r0 ;increment r0
inc r0 ; increment r0
here:sjmp here
end
inc r0 ;increment r0
here:sjmp here
end
dec r2 ;decrement r2
inc r0 ;increment r0
inc r0 ;increment r0
subb a,@r0 ;subtract content of internal RAM location from a
inc r0 ;increment r0
here:sjmp here
end
if the ASCII code is between 30-39h then 30h is subtracted from the code. If the number
lies between A to F then 37h is subtracted from the code to get its binary equivalent
rep:sjmp rep
end
20. Program to check whether a 4th bit of a byte is 1, Store FFh if 1, else store 00 in
mov dptr,#9000h
last:sjmp last
end
last:sjmp last
end
here:sjmp here
end
;delay routine
ret ;return
end
inc a ;increment a
delay routine
ret ;return
end
delay routine:
ret
end
ret
end
#include <REG51xD2.H>
#include "lcd.h"
main()
while(1)
}
}
P0=0x0ff;
P1=0x0ff;
scanline */
t = ~t;
t >>=1;
t = k>>4;
t +=0x30;
t = k & 0x0f;
if(t > 9)
t+=0x37;
else
t+=0x30;
for(;x>0;x--);
2.Elevator Interface
#include <REG51F.H>
main()
P0 = 0x00;
P0 = 0x0f0;
while(1)
{
P1 = 0x0f;
ReqFlr = P1 | 0x0f0;
while(ReqFlr == 0x0ff)
ReqFlr = ~ReqFlr;
j = Flr[CurFlr];
P0 = 0x0f0|j;
j--;
delay(25000);
j = Flr[CurFlr];
P0 = 0x0f0 | j;
j++;
delay(25000);
for(;x>0;x--);
#include <REG51xD2.H>
for(;x>0;x--);
ClrLcd();
if(Dir)
delay(32000);
else
delay(32000);
main()
EX0=0x1;
ES=0x1;
P0=0x00; /*since the monitor is using the serial interrupt it has to be enabled*/
while(1)
Val = 0x88;
for(i=0;i<4;i++)
Val = Val>>1;
delay(575);
Val = 0x11;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for anticlock wise direction*/
Val = Val<<1;
delay(575);
#include<stdio.h>
#include <REG51.H>
0xc6,0x86,0xc7,0x86,
0xbf,0xc0,0xde,0x87,
0xbf,0x92,0x91,0x92,
0x92,0xc8,0x86,0x87},i;
void main(){
int d,b,j,k,s;
while(1){
i=0;
for(d=0;d<5;d++)
for(b=0;b<4;b++)
k=port[i++];
for(j=0;j<8;j++){
s=k;
s=s&0x80;
if(s==0x00)
P1= 0x00;
else
P1=0x1;
P2 = 0x1;
P2=0x00;
s=k;
s=s<<1;
k=s;
delay(10000);
delay(10000);
void delay(int g)
int h;
for(h=0;h<=g;g++)
#include <REG51xD2.H>
#include "lcd.h"
for(;x>0;x--);
main()
while(1)
fre = 100;
}
P0=on; /* write amplitude to port */
P1=on;
delay(fre);
P1 = off;
delay(fre);
#include <REG51xD2.H>
#include "lcd.h"
main()
while(1)
P1 = i;
P0 = i; }
{P0 = i;
P1 = i;}
}
8. Dual DAC, RAMP wave
#include <REG51xD2.H>
main()
while(1)
for(i=0;i<0xff;i++)
P1 = i;
P0 = i;
P0 = 0;
P1 =0;