1.Sending 00H to FFH to Ports
#include <reg51.h>void main(void)
{
unsigned char z;
for (z=0;z<=255;z++)
P1=z;
}
Caution
1. Pay careful attention to
the size of the data.
2. Try to use unsigned char
instead of int if possible.
2.Sending ASCII Characters to Ports
Statement: Write an 8051 C program to send hex values for ASCII characters of
0, 1, 2, 3, 4, 5, A, B, C, and D to port P1.
Program
#include <reg51.h>
void main(void)
{
unsigned char mynum[]=“012345ABCD”;
unsigned char z;
for (z=0;z<=10;z++)
P1=mynum[z];
}
0, 1, 2, 3, 4, 5, A, B, C, and D to port P1.
Program
#include <reg51.h>
void main(void)
{
unsigned char mynum[]=“012345ABCD”;
unsigned char z;
for (z=0;z<=10;z++)
P1=mynum[z];
}
3.Toggle Port Bits
Write an 8051 C program to toggle all the bits of P1 continuously.
Solution:
//Toggle P1 forever
#include <reg51.h>
void main(void)
{
for (;;)
{
p1=0x55;
p1=0xAA;
}
}
4.Sending values to Port
Write an 8051 C program to send values of –4 to +4 to port P1.
Solution:
//Singed numbers #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];
}
5.Toggle Single Bit
Write an 8051 C program to toggle bit D0 of the port P1 (P1.0)
50,000 times.
Solution:
#include <reg51.h>
sbit MYBIT=P1^0;
void main(void)
{
unsigned int z;
for (z=0;z<=50000;z++)
{
MYBIT=0;
MYBIT=1;
}
}
6.Toggle Bits with Delay
Write an 8051 C program to toggle bits of P1 continuously forever
with some delay.
Solution:
//Toggle P1 forever with some delay in between “on” and “off”
#include <reg51.h>
void main(void)
{
unsigned int x;
for (;;) //repeat forever
{
p1=0x55;
for (x=0;x<40000;x++); //delay size
//unknown
p1=0xAA;
for (x=0;x<40000;x++);
}
}
Hello can anyone share the output for this program in keil version 5 please 🥺
ReplyDeleteCool and that i have a swell provide: How Much For House Renovation Uk contractor for home renovation near me
ReplyDeleteThanks and that i have a keen offer: Renovation House Company split level home kitchen remodel
ReplyDelete