VTech Alphabert s Magic Readport User Manual Page 10

  • Download
  • Add to my manuals
  • Print
  • Page
    / 80
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 9
Lab Manual of Microcontroller & Interfacing Page 10
EXPERIMENT NO. 2
AIM: Write a C language programs to…
Read data from port P2 and P3. Add data and display result on port P0. Glow LED
connected at port pinP1.1 if carry flag set after addition.
Read data from port P2 and P3. Multiply data and display result on port P0 and P1.
Write program to read switch connected at port pin P1.0, toggle it and send to port pin
P1.1.
C Language Programs:
Program 1: Read data from port P2 and P3. Add data and display result on port P0. Glow
LED connected at port pinP1.1 if carry flag set after addition.
# include <reg51.h>
void main(void)
{
unsigned char a,b,c;
P2=0xff; //Define port P2 as an input port
P3=0xff; //Define port P3 as an input port
P0=0x00; //Define port P0 as an output port
P1=0x00; //Define port P1 as an output port
P1=0x01; //Make LED off
a=P2; //Read port P2
b=P3; //Read port P3
c=a+b; //Add content of port P2 and P3
P0 = c; //Display result on port P0
if(CY==1)
{
P1=0x00; //Glow LED connected at P1.0 common anode mode
}
}
Program 2: Read data from port P2 and P3. Multiply data and display result on port P0 &
P1.
# include <reg51.h>
void main(void)
{
unsigned char a,b;
unsigned int c;
P2=0xff; //Define port P2 as an input port
P3=0xff; // Define port P3 as an input port
P0=0x00; //Define port P0 as an output port
P1=0x00; //Define port P1 as an output port
a=P2; //Read port P2
b=P3; //Read port P3
c=a*b; //Multiply content of port P2 and P3
P0 = ACC; //Display accumulator content on port P0
P1=B; //Display register B content on port P1
}
Page view 9
1 2 ... 5 6 7 8 9 10 11 12 13 14 15 ... 79 80

Comments to this Manuals

No comments