Professional Documents
Culture Documents
#Include Void Main (Void) (P0 0x64 P1 0x14 P2 P0 & P1 )
#Include Void Main (Void) (P0 0x64 P1 0x14 P2 P0 & P1 )
#Include Void Main (Void) (P0 0x64 P1 0x14 P2 P0 & P1 )
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;
}
P0 = 0x79;
}
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++;
}
}