📄 peripheral.c
字号:
#include <c8051f020.h>
#define DELAY 100
sbit BELL=P3^7;
typedef unsigned char uchar;
typedef unsigned int uint;
uchar GetKey()
{
uchar KeyValue,KeyTemp;
uint t;
KeyValue=P0 & 0xf0;
if(KeyValue==0xf0)
return 0;
t=DELAY;
while(t--);
if( (P0 & 0xf0) !=KeyValue)
return 0;
while(1)
{
KeyTemp=P0 & 0xf0;
t=DELAY;
while(t--);
if((P0 & 0xf0)==KeyTemp && 0xf0==KeyTemp)
break;
}
switch(KeyValue)
{
case 0xe0:return 4;
case 0xd0:return 3;
case 0xb0:return 1;
case 0x70:return 2;
default:return 0;
}
}
void Beep(uint delay)
{
unsigned int i;
BELL=1;
for(i=0;i<delay;i++);
BELL=0;
}
void SendUART(unsigned char c)
{
SBUF0=c;
while(!TI0);
TI0=0;
}
void SendStrUART(char *c,int length)
{
int i=0;
while(i<length)
{
SBUF0=*c;
c++;i++;
while(!TI0){};
TI0=0;
}
}
void EnableADC()
{
AD0EN=1;
}
void DisableADC()
{
AD0EN=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -