📄 main.c
字号:
#include <string.h>
#include <stdio.h>
#include "Target\44b.h"
#include "Target\44blib.h"
const char Keyboard[4][4] = {
{'7','8','9','/'},
{'4','5','6','*'},
{'1','2','3','-'},
{'0','.','+','\n'}};
char ReadKeybd(void)
{
unsigned int PCONFback=0;
unsigned int PUPFback=0;
unsigned char scanvalue[4] ={0xfe,0xfd,0xfb,0xf7};
unsigned char i,j,x,temp;
char keyvalue=0;
PCONFback = rPCONF;
rPCONF = 0x55;//pf0-pf3:output, pf4-pf7:input
PUPFback=rPUPG;
rPUPF=0xff;//disable pull-up
rPDATF=0xf0;//pf0-pf3:0
if((temp=(rPDATF&0xf0))!=0xf0){
for(i=0;i<4;i++){
rPDATF=scanvalue[i];
for(x=0;x<100;x++);
if((temp=(rPDATF&0xf0))!=0xf0){
temp=(~(temp>>4))&0x0f;
for(j=0;j<4;j++){
if(temp==0x01){
keyvalue=Keyboard[j][i];
return keyvalue;
}
else
temp=temp>>1;
}
}
}
}
rPCONF=PCONFback;
rPUPF=PUPFback;
return keyvalue;
}
void Main(void)
{
char aa,ch1=0,ch2=0;
unsigned char keyflg=0;
Port_Init();
Led_Display(0xf);
Beep(0x1);
Uart_Printf("\n*************************************************************************");
Beep(0x0);
Uart_Printf("\n* 立宇泰电子 *");
Uart_Printf("\n* -S3C44B0X功能部件:I/O测试(4*4矩阵键盘)- *");
Uart_Printf("\n* Version 1.21 *");
Uart_Printf("\n* Email:Support@hzlitai.com.cn *");
Uart_Printf("\n* UART Config--COM:115.2kbps,8Bit,NP,UART0 *");
Uart_Printf("\n*------------------Begin to Start IO test,OK? (Y/N)--------------------*");
Led_Display(0x0);
aa= Uart_Getch();
if((aa=='Y')||(aa=='y'))
{
Uart_Printf("\nBegin Keyboard Scan...");
while(1)
{
ch1=ReadKeybd();
if(ch1!=0){
if((keyflg==1)&&(ch1==ch2))//Co
{
Uart_SendByte(ch1);
while((rPDATF&0xf0)!=0xf0);//等待按键释放
}
else{
keyflg=1;
ch2=ch1;
}
}
else{
keyflg=0;
ch2=0;
}
Delay(1000);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -