📄 key.c
字号:
#include <mega128.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "typedef.h"
#include "app.h"
#include "attention.h"
#include "Flash.h"
#include "g20modem.h"
#include "g20serialdrv.h"
#include "ombro.h"
#include "rtc.h"
#include "serialdrv.h"
#include "timer.h"
#include "UDP.h"
#include "protocol.h"
#include "key.h"
#include "lcdzk.h"
#include "print.h"
#include "ombrodb.h"
unsigned char keyvalue;
unsigned char num[25];
unsigned char check_key(void)
{
unsigned char i=0;
unsigned char key=0;
KEY_OUT0=0;
nop();
i=~KEY_IN&0xf0;
switch (i)
{
case 16:
key=1;
break;
case 32:
key=2;
break;
case 64:
key=3;
break;
case 128:
key=4;
break;
}
KEY_OUT0=1;
KEY_OUT1=0;
nop();
i=~KEY_IN&0xf0;
switch (i)
{
case 16:
key=5;
break;
case 32:
key=6;
break;
case 64:
key=7;
break;
case 128:
key=8;
break;
}
KEY_OUT1=1;
KEY_OUT2=0;
nop();
i=~KEY_IN&0xf0;
switch (i)
{
case 16:
key=9;
break;
case 32:
key=10;
break;
case 64:
key=11;
break;
case 128:
key=12;
break;
}
KEY_OUT2=1;
KEY_OUT3=0;
nop();
i=~KEY_IN&0xf0;
switch (i)
{
case 16:
key=13;
break;
case 32:
key=14;
break;
case 64:
key=15;
break;
case 128:
key=16;
break;
}
KEY_OUT3=1;
wdr();
return(key);
}
unsigned char read_key(void)
{
unsigned char key;
key=0;
while (key==0)
{
while (check_key()==0);
timer_delay(25);
key=check_key();
while (check_key()!=0);
}
return(key);
}
unsigned char input_num(unsigned char si,unsigned char addoff)
{
unsigned char i=0,point=0;
unsigned char key_value;
cursor(7);
while(i==0)
{
if (check_key())
{
key_value=read_key();
switch(key_value)
{
case ZERO:
key_value=0;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case ONE:
key_value=1;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case TWO:
key_value=2;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case THREE:
key_value=3;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case FOUR:
key_value=4;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case FIVE:
key_value=5;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case SIX:
key_value=6;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case SEVEN:
key_value=7;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case EIGHT:
key_value=8;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case NINE:
key_value=9;
if (point<si-1)
{
sprintf(&num[point],"%u",key_value);
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case OK:
cursor(2);
return(1);
break;
case CANCEL:
cursor(2);
return(0);
break;
case UP:
if (point>0)
{
point--;
cleft();
}
break;
case SETUP:
if (point<si-1)
{
sprintf(&num[point]," ");
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
case DOWN:
if (point<si-1)
{
sprintf(&num[point],"-");
disp_string(_cx,((_cy-1)*8-addoff),&num[point]);
cright();
point++;
}
break;
default:
break;
}
}
}
}
unsigned int set_rain(void)
{
unsigned char i;
unsigned int rain;
memset(num, 0x00, 25);
i=input_num(4,0);
if (i)
{
if (num[0]>0x39 || num[0]<0x30)
{
num[0]=0x31;
num[1]=0x20;
}
rain=atoi(num);
return rain;
}
return 1;
}
void set_mobilephone(void)
{
unsigned char i;
unsigned char key_value;
unsigned char strdata[15];
disp_title(7);
cursor(2);
cursor_on;
gotoxy(14,4);
timer_delay(1000);
while(1)
{
wdr();
if (check_key())
{
key_value=read_key();
switch(key_value)
{
case UP:
gotoxy(14,4);
break;
case DOWN:
gotoxy(16,9);
break;
case CANCEL:
cursor(2);
cursor_off;
return;
// break;
case OK:
switch (_cy)
{
case 4:
memset(num, 0x00, 25);
i=input_num(12,0);
if (i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -