#Include Void Main (Void) (P0 0x64 P1 0x14 P2 P0 & P1 )

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Q1.

C program to AND 8b data of port 0 and port 1 and to send result to


port.
#include<reg51.h>
void main(void)
{
P0 = 0x64;
P1 = 0x14;
P2 = P0 & P1;
}

Q2. C Program to AND P0.0 and P1.3 send result to P2.0.


#include<reg51.h>
sbit MYBIT1 = P0^0;
sbit MYBIT2 = P1^3;
sbit MYBIT3 = P2^0;
void main(void)
{
MYBIT1 = 0;
MYBIT2 = 1;
MYBIT3 = MYBIT1 & MYBIT2;
}
Q3. C Program to read p1 and send data to p2 and p3 based on
condition.
#include<reg51.h>
void main(void)
{
P1 = 0x34;
if(P1==0x02)
{
P2 = P1;
}
else
P3 = P1;
}
Q4. C Program to left shift data at port 1 repetitively
#include<reg51.h>
void main(void)
{
unsigned char z;

P1=0x98;
for(z=0;z<8;z++)
{
P1 = P1<<1;
}

}
Q5. C Program to AND P0.0 and P1.3 send result to P2.
#include<reg51.h>
sbit MYBIT1 = P0^0;
sbit MYBIT2 = P1^3;
void main(void)
{
MYBIT1 = 1;
MYBIT2 = 0;
MYBIT1 = MYBIT1 & MYBIT2;
P2 = P0;
}

Q6. C program to send 0-9 to port 2.


#include<reg51.h>
void main(void)
{
unsigned char z;
unsigned char x;
x = 0x00;
for(z=0;z<10;z++)
{
P2 = x;
x++;
}
}
Q7. C Program to send hex data to port 0.
#include<reg51.h>
void main(void)
{

P0 = 0x79;

Q8. C Program to send ASCII value of the characters.


#include<reg51.h>
void main(void)
{
char z = 'c';
P1 = (int)z;

}
Q9. C Program to toggle LEd's at port 1.
#include<reg51.h>
void main(void)
{
P1 = 0x12;
for(;;)
{
P1 = 0xff - P1;
}
}
Q10. C Program to toggle LSB bit of Port 1.

#include<reg51.h>
sbit MYBIT = P1^0;
void main(void)
{
while(1)
{
MYBIT = 0;
MYBIT = 1;
}
}
Q11. C program to toggle MSB bit of port 1.
#include<reg51.h>
sbit MYBIT = P1^7;
void main(void)
{
while(1)
{
MYBIT = 0;
MYBIT = 1;
}
}
Q12. Toggle P1 from 55 to AA continuously.
#include<reg51.h>
void main(void)
{
for(;;)
{
P1 = 0x55;
P1 = 0xAA;
}
}
Q2. Write an 8051 C program to send values of -4 to +4 to Port
P1.
#include<reg51.h>
void main(void)
{
signed char x = -4;
unsigned char z;
for(z=0;z<9;z++)
{
P1 = x;
x++;
}
}
Q3. Toggle bit 0 of Port P1.
#include<reg51.h>
sbit MYBIT = P1^0;

void main(void)
{
unsignedint z;
for(z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
}
}

Q5. Copy a block of 20 bytes of data available from address 60H to 73H
to the location starting from 40H.
#include<reg51.h>

void main(void)
{
unsigned char *src,*dest;
unsigned char z;
src = 0x60;
dest = 0x40;
for(z=0;z<20;z++)
{
*src = 20;
src++;
}
src = 0x60;
for(z=0;z<20;z++)
{
*dest = *src;
dest++;
src++;
}
}

You might also like