The 8051 Microcontroller and Embedded

(lily) #1
Department of Computer Scien

ce and Information Engineering

National Cheng Kung University, TAIWAN

I/O HANEL
PROGRAMMINGUsing bit Data


Type for
Bit-addressable

RAM


Write an 8051 C program to get the status of bit P1.0, save it, and send it to P2.7 continuously.Solution:#include <reg51.h>sbit inbit=P1^0;sbit outbit=P2^7;bit membit; //use bit to declare

//bit- addressable memory

void main(void){

while (1){

membit=inbit; //get a bit from P1.0outbit=membit; //send it to P2.7}
}

We use bit data type to access data in a bit-addressable section of the data RAM space 20 – 2FH
Free download pdf