8051 read write port

View previous topic View next topic Go down

8051 read write port

Post  Admin on Wed Jul 31, 2013 2:08 am

This example shows how to read 8-bit port 1 and copy the same value to port 3





/* 8051 header file*/
#include<reg51.h>


sfr P1 = 0x90;          /* SFR definition for Port 1 */
sfr P3 = 0xB0;          /* SFR definition for Port 3 */

/*------------------------------------------------
MAIN C Function
------------------------------------------------*/
void main (void)
{
unsigned char pval;     /* temp variable for port values */

P1 = 0xFF;              /* Setup P1 for Input */

/*--------------------------------------
Use the Toolbox buttons in the debugger
to change the value of P1.  Open the
Port 1 and Port 3 dialogs from the
Peripherals Menu to view their status.
--------------------------------------*/
while (1)
 {
 pval = P1;            /* Read P1 into pval */
 P3 = pval;            /* Write pval to P3 */
 }
}


avatar
Admin
Admin

Posts : 49
Join date : 2012-08-15
Location : Mumbai,INDIA

View user profile http://embeddedforus.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum