📄 zlg7290.h
字号:
#include "i2c.h"#include "stdio.h"#include "config.h"void I2C_Init(int fd);uint8 GetKey(int fd);uint8 KeyTest(int fd);uint8 InputNumber(int fd,char *num);uint8 temp[2];uint8 GetKey(int fd){ uint16 key_value; uint8 key_map[17]={0,1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16}; temp[0]=1; temp[1]=0; write(fd, temp, 1); read(fd, temp, 2); key_value = (temp[0] + (temp[1] * 256)); return key_map[key_value];}uint8 KeyTest(int fd){ uint16 key_flag; temp[0]=0; temp[1]=0; write(fd, temp, 1); //访问系统状态寄存器0x00 read(fd, temp, 2); key_flag = (temp[0] + (temp[1] * 256)); if(key_flag&0x0001) //有键按下 { return 1; } else { return 0; }} void I2C_Init(int fd){ ioctl (fd , I2C_SET_CLH , ((11059200/30000)+1)/2); ioctl (fd , I2C_SET_CLL , (11059200/30000)/2);}uint8 InputNumber(int fd,char *num) { uint8 key; int flag=1,i=0; printf("Please input the number:\n"); while(flag) { if ( KeyTest(fd) ) { key = GetKey(fd); switch(key) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: if (i<19) { num[i++]=(char) (key+48); break; } else { i=0; printf("Input the right number! \n"); break; } case 11: /* if(*num) { Remove( &i,num); break; } else { printf("w\n"); break; } */ break; case 12: if (*num) return i; else return 0; flag=0; break; default: break; } } }} void Remove(int *n,uint8 *num){ int i,j; i = *n; *n=--i; for(j=0;j<i;j++) printf("%d",num[j]);}void delay(int n){ int i,j; for(i=0;i<n;i++) for(j=0;j<5000;j++);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -