Reading and writing individual bits NOTE: Both bits on port1 程序将P1端口管脚0读入并写到管脚1. -*------------------------------------------------------------------*/
#include <reg52.h>
void Write_Bit_P1(unsigned char, bit); bit Read_Bit_P1(unsigned char);
bit Read_Bit_Px(unsigned char Pin) { unsigned char p = 1; p <<= Pin; // Left shift
// Write a 1 to the pin (to set up for reading) Write_Bit_Px(Pin, 1); return (P1 & p); // Read the pin }
/*------------------------------------------------------------------*- ---- END OF FILE ------------------------------------------------- -*------------------------------------------------------------------*/