EMBEDDED FOR US
Would you like to react to this message? Create an account in a few clicks or log in to continue.

8051 read write port

Go down

8051 read write  port Empty 8051 read write port

Post  Admin 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 */
 }
}


Admin
Admin
Admin

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

http://embeddedforus.com

Back to top Go down

Back to top

- Similar topics

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