BASIC MICROCONTROLLER PROGRAMS
There total 11 microcontroller programs are given one by one also provided text document file for download at the end.
1.move block of data within internal RAM
org 000h
mov r0,#30h
mov r1,#40h
mov r2,#3
start: mov a,@r0
mov@r1,a
inc r0
inc r1
djnz r2,start
here: sjmp here
end
2.packed to unpacked
org 000h
mov r1,#18h
mov a,r1
anl a,#0fh
mov r2,a
mov a,r1
anl a,#0f0h
swap a
mov r3,a
end
3. unpacked to packed
org 000h
mov r1,#1h
mov r2,#8h
mov a,r1
swap a
add a,r2
here:sjmp here
end
4. bcd to ascii code
un_bcd equ 40h
asci equ 41h
org 000h
mov a,#30h
orl a,un_bcd
mov asci,a
here: sjmp here
end
5. ascii to bcd
asci equ 40h
un_bcd equ 41h
org 0h
mov a,asci
anl a,#0fh
mov un_bcd,a
here :sjmp here
6. evaluate simple arthmatic
#include<reg51.h>
void main()
{
unsigned char y;
y=(((5*2)-(4+1))/3)%2;
while(1);
}
7.Addition three 8bit no.
res equ 44h
org 000h
mov r0,#40h
mov r2,#3
clr a
mov r7,a
start:add a,@r0
da a
jnc next
inc r7
next:inc r0
mov res,a
djnz r2,next
here:sjmp here
end
8. even parity
org 000h
mov r0,#40h
mov r1,#05
start:clr a
mov a,@r0
jnb p,next
setb acc.7
next:mov @r0,a
inc r0
djnz r1,next
here:sjmp here
end
9.Rotation operation on data
mov a,40h
rlc a
mov r1,a
mov a,41h
rlc a
mov 40h,r1
mov 41h,a
end
10. triangle wave
#include <reg51xd2.h>
main()
{
unsigned char i=0;
P0=0*100;
while(1)
{
for(i=0;i<0x0ff;i++)
{P1=i;
P0=i;}
for(i=0xfe;i>0x00;i--)
{P0=i;
P1=i;}}}
11. sqaure wave
#include<reg51xd2.h>
sbit amp=P3^3;
sbit fre=P3^2;
void delay(unsigned char x)
{
for(;x>0;x--);
}
main()
{
unsigned char on=0x7f,off=0x00;
unsigned int fre=100;
while(1)
{
if(!amp)
{
while (!amp);
on+=0x08;
}
if(!fre)
{
if(fre>1000)
fre=100;
while(!fre);
fre+=50;
}
P0=on;
P1=on;
delay(fre);
P0=off;
P1=off;
delay(fre);
}
}
Download as txt file
Note : This only for educational purpose to minimize effort and help to students if any content of this post/document owned by any person/organization can contact by email so that i will remove that particular content.
SUBSCRIBE | COMMENT | SHARE
Note : This only for educational purpose to minimize effort and help to students if any content of this post/document owned by any person/organization can contact by email so that i will remove that particular content.
SUBSCRIBE | COMMENT | SHARE
Comments