8051 read write port
Page 1 of 1
8051 read write port
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 */
}
}
/* 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 */
}
}
Similar topics
» 8051: External interrupt on IO pins
» 8051 : 8 bit Timer0 overflow using Interrupt
» 8051: 16 bit timer0 overflow using Interrupt service routine.
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
» 8051 : 8 bit Timer0 overflow using Interrupt
» 8051: 16 bit timer0 overflow using Interrupt service routine.
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
» interfacing 8051 with JHD12864 and samsung ks0108b glcd 128x64
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum