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

📄 c51.h

📁 一个对4X4数字键盘进行行&列扫描,获取扫描码的程序,支持符合键,串键,软件去抖.
💻 H
字号:
#include <reg52.h>
#include <stdio.h>
#include <intrins.h>
#include <string.h>

//#define  DELAY_COUNT    10  // define the delay count number for 10 us
void delay(int t) ;            //delay 10t us


/*   Keyboard control  */

#define  CHAR_BUFFER_LENGTH  (16)
#define  KEY_RINGBUF_LENGTH  (8)
#undef  INCLUDE_CONTROL

#ifdef  INCLUDE_CONTROL 
 #define  KEY_CTRL    (0x00)
 #define  KEY_SHIFT   (0x01)
 #define  CTRL_CODE   (0x01)
 #define  SHIFT_CODE   (0x02)
#endif

#define  KEY_LATENCY  (50)
#define  KEY_DOWN    1
#define  KEY_UP      0


//define the scan code for evry key
#define	      KEY1   5
#define		  KEY2   6 
#define		  KEY3   7
#define		  KEY4	 9
#define		  KEY5	10
#define		  KEY6	11
#define		  KEY7	13
#define		  KEY8	14
#define		  KEY9	15
#define		  KEY0	 3
#define     KEY_ENTER      4
#define     KEY_CANCEL     8
#define     KEY_DOT        2
#define     KEY_BACKSPACE  0
#define     KEY_PAGEUP    12
#define     KEY_SUB        1


struct KeyStatus {
       unsigned char PreStatus;
       unsigned char NowStatus;
       unsigned char Key;
#ifdef INCLUDE_CONTROL
       unsigned char Ctrl;
#endif
	   };                // describe the keyboard status


void keyInit(void)   ;          //initialize key board
int  ScanKey(struct KeyStatus *ks)  ; //scan keyboard to get key code
int  Edln(char *buf);




/*  LCD  control */
#define LCD_CLEAR_SCREEN   0x01
#define LCD_CLEAR_AC       0x02
#define LCD_SET_CURSOR_MODE    0x04
#define LCD_SET_STATUS     0x08
#define LCD_MOVE_CURSOR    0x10
#define LCD_SET_OPTION     0x20
#define LCD_SET_CGRAM      0x40
#define LCD_SET_DDRAM      0x80

#define LCD_SET_EXPANDMODE 0x34
#define LCD_SET_GDRAM_AC   0x80

#define lcdIsBusy()   (lcdStatus() & 0x80 )
#define lcdAC()       (lcdStatus() & 0x7f )
#define prtc(c)       (lcdWrRAM(c))


void   lcdWrRAM(unsigned char dat);
void  lcdInstruction(unsigned char ins);
void  lcdInit();
void  lcdPrts(char *str);
unsigned char   lcdStatus();
unsigned char   lcdRdRAM();


/* tty serial port control*/
#define  TTY_RINGBUF_LENGTH  (8)

void ttyInit(void);
int  Tx(unsigned char c);
int  Rx(unsigned char *c);
int  ttyRead(unsigned char data * buf);
int  ttyWrite(unsigned char * buf);
int  ttyEmpty();



/* define  communication  protocol  */

/*  packet packet head format:  
    0:     sync byte, must be 0xff
    1:     command type, bit7 dictate if it needs reply
    2:     packet  size
    3:     packet  
    */    

⌨️ 快捷键说明

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