📄 panel.c
字号:
#include <panel.h>
#include <1621.h>
#include<stdlib.h>
// extern unsigned char kkk[10];
void InitSystem ()
{
VOICE3=0;
VOICE4=0;
WDT_CONTR = 0x00;//关掉看门狗电路
ES = 0;//禁止串口中断
//配置串口
SCON = 0x50; //8位数据位,无奇偶校验
T2CON = 0x34;//由T2作为波特率发生器
if(SW1 == 1)
{
RCAP2H = 0xfe; //时钟11.0592M 1200波特率
RCAP2L = 0xe0;
}
if(SW1==0)
{
RCAP2H = 0xff; //时钟11.0592M 9600波特率
RCAP2L = 0xdb;
}
//配置T1,count=909090,TI:16位工作模式
//
ES = 1;//允许串口中断
}
unsigned char Receive_Byte(void)
{
unsigned char DReceive;
RI = 0;
while(RI == 0);
DReceive = SBUF;
RI = 0;
return DReceive;
}
void Send_Byte(unsigned char DSend)
{
TI = 0;
SBUF = DSend;
while(TI == 0);
TI = 0;
}
/*
unsigned char down_package(void)
{
int i;
//unsigned char down[10];
unsigned char down;
//for(i=0;i<6;i++)
//down[i] = Receive_Byte();
down = Receive_Byte();
if( down==0x1b)
{
return 1;
}
return 0;
}
*/
/*
void up_package(void)
{
int i;
unsigned char up[15];
unsigned char temp1,temp2;
unsigned char temp;
up[0]= 0x02;
up[1]= 0x06;
up[14]= 0x03;
for(i=2;i<13; )
{
temp1=sbuf[i];
temp2=temp1;
temp1 &=0xf0;
temp1 >>=4;
temp1 |=0x30;
temp2 &=0x0f;
temp2 |=0x30;
up[i++] = temp1;
up[i++] = temp2;
}
for(i=0;i<15;i++)
Send_Byte(up[i]);
}
*/
void ReadSwStatus()
{
unsigned char sw,sw_copy;
sw = P2;
sw_copy = sw;
if( sw && 0x01)
{
#define baurate_1200;
}
else {
#define baurate_9600;
}
sw = sw_copy;
if(sw && 0x02)
{
#define command2;
}
else{
#define command1;
}
}
void delay_ms(unsigned int i)//delay_ms(200)=1s
{
unsigned int j;
unsigned int n;
for(j=0;j<i;j++)
{
for(n=0;n<255;n++);
}
}
/*
unsigned char JudgeKey(void)//comment by liuyuan@07.04.02.14.09
{
P2 =0x1f;//初始化行列控制端口
delay_ms(150);
//if any key is pressed ,key will pull low
while(PIN1 && PIN2 && PIN3 && PIN4 && PIN5);
delay_ms(150);
if(!(PIN1 && PIN2 && PIN3 && PIN4 && PIN5))
return 1;
else
return 0;
}
*/
unsigned char JudgeKey(void)//comment by liuyuan@07.04.02.14.09
{
P2 =0xf8;//初始化行列控制端口
delay_ms(20);
//if any key is pressed ,key will pull low
//while((PIN1 && PIN2 && PIN3 && PIN4 && PIN5));
//delay_ms(10);
if(!(PIN1 && PIN2 && PIN3 && PIN4 && PIN5))
return 1;
else
return 0;
}
void LightPanel_on(void)
{
LIGHT_PANEL=1;
SendCmd_1621(LCD_on);
}
void LightPanel_off(void)
{
LIGHT_PANEL=0;
SendCmd_1621(LCD_off);
}
void Tone()
{
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
delay_ms(100);
SendCmd_1621(TUNE_on);
delay_ms(100);
SendCmd_1621(TUNE_off);
}
/*
void random()
{
int i,j;
int num[]={0,1,2,3,4,5,6,7,8,9};
//SMG10 SMG1 SMG2 SMG3 SMG4 SMG5 SMG6 SMG7 SMG8 SMG9
int rn[10];
srand((unsigned)t++);//time(&t));
for(i=0;i<10;i++)
{
rn[i]=rand()%10;
for(j=0;j<i;j++)
{
if(rn[i]==rn[j]){i--;j=i;}
}
}
for(i=0;i<10;i++)
{key_num[i] = num[rn[i]];}
}
*/
/*
unsigned char * DisplayNum(void)
{
unsigned char ADDr[]={0x06,0x04,0x02,0x00,0x0e,
0x10,0x12,0x08,0x0a,0x0c};
unsigned char seg[]={0xdf,0x86,0xbd,0xaf,0xe6,0xeb,0xfb,0x8e,0xff,0xee};//数码管1,2,3,4,5,6,7,8,9,10对应数字显示
//0 1 2 3 4 5 6 7 8 9
unsigned char i,j;
unsigned char key_num[10];
//Init_1621();
//LCDon();
//random();
int num[]={0,1,2,3,4,5,6,7,8,9};
//SMG10 SMG1 SMG2 SMG3 SMG4 SMG5 SMG6 SMG7 SMG8 SMG9
int rn[10];
srand((unsigned)t++);//time(&t));
for(i=0;i<10;i++)
{
rn[i]=rand()%10;
for(j=0;j<i;j++)
{
if(rn[i]==rn[j]){i--;j=i;}
}
}
for(i=0;i<10;i++)
{key_num[i] = num[rn[i]];}
//for(i=0;i<10;i++)
//key_num[i] = i;
//Write_1621(ADDr[0],0X06);
//Write_1621(ADDr[2],0X06);
//for(i=0;i<10;i++)//for debug
// Send_Byte(key_num[i]);//for debug
for(i=0;i<10;i++)
{
Write_1621(ADDr[i],seg[key_num[i]]);
}
//if(key_num[4]==9);
// SendCmd_1621(TUNE_on);
for(i=0;i<10;i++)
kkk[i] = key_num[i];
return key_num;
}
*/
/*
unsigned char * DisplayNum_sequence(void)
{
int i;
unsigned char key_num[10];
unsigned char ADDr[]={0x06,0x04,0x02,0x00,0x0e,
0x10,0x12,0x08,0x0a,0x0c};
unsigned char seg[]={0xdf,0x86,0xbd,0xaf,0xe6,0xeb,0xfb,0x8e,0xff,0xee};//数码管1,2,3,4,5,6,7,8,9,10对应数字显示
//0 1 2 3 4 5 6 7 8 9
for(i=0;i<10;i++)
key_num[i] = i;
for(i=0;i<10;i++)
Write_1621(ADDr[i],seg[key_num[i]]);
return key_num;
}
*/
/*1 P27 -----10--------11 10:正序键 11:乱序键
| | |
2 P26 -----1----2----3
| | |
3 P25 -----4----5----6
| | |
4 P24 -----7----8----9
| | |
5 P23 -----12---0----13 12:更正键 13:确认键
| | |
6 P22 ----- | |
| |
7 P21 ---------- |
|
8 P20 -------------- */
//unsigned char key_code[]={0x50,0x22,0x42,0x82,0x24,0x44,0x84,0x28,0x48,0x88,0x21,0x81,0x03,0x09};
//对应键值 0 1 2 3 4 5 6 7 8 9 10 11 12 13
//unsigned char ksp[]={0x01,0x02,0x04,0x08,0x10};
//unsigned char cnt=0;
unsigned char keypad_scan(void) //return the number of keyboard
{
unsigned char key,i,j,line_temp1,line_temp2,row_temp1,row_temp2,keynum;
unsigned char line[5] = {0x80,0x40,0x20,0x10,0x08};
unsigned char row[3] = {0x04,0x02,0x01};
P2=0xf8;
delay_ms(10);
while ((line_temp1=P2)==0xf8);
for(i=0;i<5;i++)
{
line_temp2 = line_temp1;
if(!(line_temp2 & line[i]))
break;
}
P2 = 0x07;
delay_ms(10);
while((row_temp1=P2)==0x07);
for(j=0;j<3;j++)
{
row_temp2 = row_temp1;
if(!(row_temp2 & row[j]))
break;
}
key = line[i] | row[j];
switch(key)
{
case 0x84:
keynum = 10;
break;
case 0x81:
keynum = 11;
break;
case 0x44:
keynum = 1;
break;
case 0x42:
keynum=2;
break;
case 0x41:
keynum=3;
break;
case 0x24:
keynum=12;
break;
case 0x22:
keynum=0;
break;
case 0x21:
keynum=13;
break;
case 0x14:
keynum=7;
break;
case 0x12:
keynum=8;
break;
case 0x11:
keynum=9;
break;
case 0x0c:
keynum=4;
break;
case 0x0a:
keynum=5;
break;
case 0x09:
keynum=6;
break;
}
return keynum;
}
// 检查是否有按键按下
/*unsigned char GetKey(void)
{
char temp,i;
temp=keypad_scan();
for (i=0;i<14;i++)
{
if(temp==key_code[i]) return(i);
}
}*/
/*void DisplayToken(void)
{
unsigned char SIGN_copy;
if(GetKey()>=0&&GetKey()<9)
{
if (cnt==0)
{
SIGN=0x80;
SIGN_copy=SIGN;
}
else if(cnt>0&&cnt<4)
{
SIGN>>=1;
SIGN|=SIGN_copy;
SIGN_copy=SIGN;
}
else if (cnt==4)
{
SIGN=0xf1;
SIGN_copy=SIGN;
}
else
{
SIGN<<=1;
SIGN|=SIGN_copy;
SIGN_copy=SIGN;
}
sbuf[cnt]=key_num[GetKey()];
cnt++;
Write_1621(ADDr_SIGN,SIGN);
}
else if(GetKey()==10);
else if(GetKey()==11);
else if(GetKey()==13);
else if(GetKey()==12);
{
cnt--;
if(cnt>=0&&cnt<4)
{
SIGN<<=cnt;
SIGN_copy=SIGN;
}
else if (cnt==4)
{
SIGN^=0x01;
}
else if (cnt==5)
{
SIGN^=0x02;
}
else if (cnt==6)
{
SIGN^=0x04;
}
else if (cnt==7)
{
SIGN^=0x08;
}
Write_1621(ADDr_SIGN,SIGN);
}
}
unsigned char ReEnter(void)
{
if (cnt>8)
{
cnt=0;//清除数组保存过的数据
Write_1621(ADDr_SIGN,0x00);
return 1;
}
else
return 0;
}
void Send_Byte_test(unsigned char byte)
{
TI =0;
SBUF = byte;
while(TI == 0);
TI = 0;
}
void TranReceive(void)
{
unsigned char i;
for(i=0;i<(cnt-1);i++)
{
Send_Byte(sbuf[i]);
}
}*/
void DisplayToken_on(unsigned char token)
{
unsigned char SIGN;//=0; //标志
if (token==0)
{
SIGN=0x00;
}
if (token==1)
{
SIGN=0x80;
}
if(token==2)
{
SIGN=0Xc0;
}
if(token==3)
{
SIGN=0Xe0;
}
if(token==4)
{
SIGN=0Xf0;
}
if (token==5)
{
SIGN=0xf1;
}
if(token==6)
{
SIGN=0Xf3;
}
Write_1621(ADDr_SIGN,SIGN);
delay_ms(100);
}
void input_password(void)
{
VOICE3=0;
VOICE4=0;
delay_ms(5);
VOICE4=1;
VOICE3=1;
}
void re_input_password()
{
VOICE3=0;
VOICE4=1;
delay_ms(5);
//VOICE3=0;
VOICE4=0;
delay_ms(5);
VOICE4=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -