📄 switch.c
字号:
//unsigned char code key[4][4]={{0xff,0xff,0x33,0xcc},{0xff,0xff,0xcc,0x33},{0xff,0xff,0x66,0x99},{0xff,0xff,0x99,0x66}}
#include<reg767.h>
#include "mydefine.h"
#define UP_KEY _CMPREF
#define DOWN_KEY _CMP1
unsigned char Command=0;
unsigned int Time=65535;
unsigned char Current_ad=0;
unsigned char Light_Ray_ad=0;
unsigned char Receive_State=0;
unsigned char Back_Receive_char;
unsigned char Up_Key_read_count=0;
unsigned char Down_Key_read_count=0;
unsigned char Msec=0;
//**************************************************************************//
// Comm Interrupt
//**************************************************************************//
void Comm(void) interrupt 4 using 1
{
unsigned char Receive_char;
if(RI)
{
Receive_char=SBUF;
RI=0;
switch(Receive_State)
{
case 0:
if(Receive_char==0xff)Receive_State=1;
break;
case 1:
if(Receive_char==0xff)
{
Receive_State=1;
}
else
{
Receive_State=2;
Back_Receive_char=Receive_char;
};
break;
case 2:
if(Receive_char==0xff)
{
Receive_State=1;
}
else if((~Receive_char)==Back_Receive_char)
{
if(Receive_char==0xcc)
{
Command=UP;
}
else if(Receive_char==0x33)
{
Command=DOWN;
}
else if(Receive_char==0x99)
{
Command=LIGHT_ON;
}
else if(Receive_char==0x66)
{
Command=LIGHT_OFF;
};
Receive_State=0;
}
else
{
Receive_State=0;
};
break;
};
}
TI=0;
}
//**************************************************************************//
// Timer0 Interrupt 100ms
//**************************************************************************//
void Timer0(void) interrupt 1 using 2
{
TL0 =0xb0;
TH0 =0x3c;
//_____________________read current____________________
ADCON|=0; //????
ADCS=1;
while(!ADCI);
Current_ad=DAC0;
ADCI=0;
ADCON&=0xfc;
//_____________________read light ray__________________
ADCON|=1;
ADCS=1; //?????
while(!ADCI);
Light_Ray_ad=DAC0;
ADCI=0;
ADCON&=0xfc;
//_____________________read key_______________________
if(UP_KEY==0)
{
if(Up_Key_read_count<KEY_DELAY)Up_Key_read_count++;
}
else
{
if(Up_Key_read_count>KEY_DELAY)
{
Command=UP;
};
Up_Key_read_count=0;
};
if(DOWN_KEY==0)
{
if(Down_Key_read_count<KEY_DELAY)Down_Key_read_count++;
}
else
{
if(Down_Key_read_count>KEY_DELAY)
{
Command=DOWN;;
};
Down_Key_read_count=0;
};
//_____________________timer count________________________
Msec++;
if(Msec>9)
{
Msec=0;
if(Time<LIGHT_DELAY)Time++;
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -