⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text1.c

📁 单片机快速入门原程序
💻 C
字号:
#include <reg51.h>
#include<stdio.h>
Uart_Init();
int nKeyNumber;
char nRxByte;
char Interrupt_Flag;
sbit P10=0x90;
sbit P32=0xB2;
sbit P33=0xB3;
void GetKeyFromRxByte();
main()
{ 	nKeyNumber=0xFF;
	Uart_Init();	
	EX0=1;
	EX1=1;
	ES=1;
	EA=1;
	Uart_Init();
	while(1)
	{
		if(nKeyNumber==0xFF) ;
			//printf("No key pressed\n");
		else 
			{	printf("key %d  Pressed\n",nKeyNumber);
				nKeyNumber=0xFF;
				}
	}
}
void int0() interrupt 0 using 0
{		P10=1;
		P10=0;
Interrupt_Flag=0;
}
void int1() interrupt 2 using 0
{		P10=1;
		P10=0;
Interrupt_Flag=1;
}
void Serial_Port() interrupt 4 using 0
{	if(RI==1)
	{
	nRxByte=SBUF;
	GetKeyFromRxByte();
	}
	TI=0;
	RI=0;
}
void GetKeyFromRxByte()
{int i,ntemp;
for(i=0;i<8;i++)
	if(((nRxByte>>i)&0x01)==0) 
		{ntemp=i;
		nKeyNumber=ntemp+8*Interrupt_Flag;
		return;
		}
	
}
Uart_Init()
	{SCON = 0x52;    /* 设置串行口控制寄存器SCON*/
	 TMOD = 0x20;    /* 12M时钟时波特率为2400  */
	 TCON = 0x69;    /* TCON */
	 TH1 =  0xf3;    /* TH1 */
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -