
1、2硬件连接图


1、3单片机I/O口工作原理


二、软件代码实现 2、1点亮一个LED方法一 #include<reg52.h> //包含头文件,一般情况不需要改动,
//头文件包含特殊功能寄存器的定义
sbit LED=P1^0; // 用sbit 关键字 定义 LED到P1.0端口,
//LED是自己任意定义且容易记忆的符号
/*------------------------------------------------
主函数
------------------------------------------------*/
void main (void)
{
//此方法使用bit位对单个端口赋值
LED=1; //将P1.0口赋值 1,对外输出高电平
LED=0; //将P1.0口赋值 0,对外输出低电平
while (1) //主循环
{
//主循环中添加其他需要一直工作的程序
}
}