BM Dept., Govt. Engg. College, Gandhinagar Page 11
Program 3: Write program to read switch connected at port pin P1.0, toggle it and send it to
port pin P1.1.
# include <reg51.h>
sbit input = P1^0; /* Define input pin P1.0*/
sbit output=P1^1; /* Define output pin P1.1*/
void main(void)
{
while(1) //Continuous infinite loop
{
output=~input; //Read input pin, toggle it and send to output
}
}
:: WORKSHEET ::
Exercise:
A. Write C language program to continuously toggle pin P1.0 without disturbing other port
pins.
B. Write C language program to perform OR operation between port pin P1.0 and P1.1.
Display result on port pin P1.2.
Comments to this Manuals