I2c:
#define _HC_EEPROM
#define MAX_ONE_PAGE 0x7f
#define MAX_ADDRESS 0xffff
void I2cPageWrite(unsigned int Address,unsigned int Length,unsigned char *Data_Handle)
{
if((Length-1)>(MAX_ADDRESS-Address))
{
I2c_State=NO_ENOUGH_ROM;
}
else
{
while(Length>0)
{
I2c_State=I2C_WRITTING;
I2cStart();
I2cSend(I2C_WRITE_COMMAND);
#ifdef _HC_EEPROM
I2cSend((unsigned char)(Address/256));
#endif
I2cSend((unsigned char)(Address%256));
do
{
I2cSend(*Data_Handle);
Length--;
Data_Handle++;
Address++;
}while(((Address&MAX_ONE_PAGE)!=0)&&(Length>0));
I2cStop();
I2cDelay();
}
I2c_State=I2C_WRITE_OVER;
}
}
void I2cPageRead(unsigned int Address,unsigned int Length,unsigned char *Data_Handle)
{
if((Length-1)>(MAX_ADDRESS-Address))
{
I2c_State=OVER_MAX_ROM;
}
else
{
while(Length>0)
{
I2c_State=I2C_READING;
I2cStart();
I2cSend(I2C_WRITE_COMMAND);
#ifdef _HC_EEPROM
I2cSend((unsigned char)(Address/256));
#endif
I2cSend((unsigned char)(Address%256));
I2cStart();
I2cSend(I2C_READ_COMMAND);
do
{
*Data_Handle=I2cRead();
Length--;
Data_Handle++;
Address++;
if(Length>0)
I2cAck();
else
I2cNoAck();
}while(Length>0);
I2cStop();
}
I2c_State=I2C_READ_OVER;
}
}
按键处理:
typedef struct Key_Ele
{
unsigned State :1;
unsigned UnPushed :7;
unsigned int Pushed ;
unsigned int Speed ;
}Key_Element;
void KeyScanAndSerV()
{
static unsigned char Key_Ing=0,Key_Over=0,Key_Scan=0;
static Key_Element Key_Scanning[5]=0;
Key_Scanning[0].State=READ_KEY0;
Key_Scanning[1].State=READ_KEY1;
Key_Scanning[2].State=READ_KEY2;
Key_Scanning[3].State=READ_KEY3;
Key_Scanning[4].State=READ_KEY4;
if(Key_Scanning[Key_Scan].State==0)
{
if(Key_Scanning[Key_Scan].Pushed<65535)
Key_Scanning[Key_Scan].Pushed++;
if(Key_Scanning[Key_Scan].Pushed>=NUM_PUSHED_JUDGE)
{
Key_Scanning[Key_Scan].UnPushed=0;
Key_Ing=Key_Scan+1;
}
}
else
{
if(Key_Scanning[Key_Scan].UnPushed<120)
Key_Scanning[Key_Scan].UnPushed++;
if(Key_Scanning[Key_Scan].UnPushed>NUM_RELEASE_JUDGE)
{
if(Key_Scanning[Key_Scan].Pushed>=NUM_PUSHED_JUDGE)
{
Key_Over=Key_Scan+1;
}
Key_Scanning[Key_Scan].Pushed=0;
Key_Scanning[Key_Scan].UnPushed=0;
}
}
Key_Scan++;
if(Key_Scan==5)
Key_Scan=0;
switch(Key_Over)
{
case 1:
if(Key_Scanning[0].Speed==0)
{
//按键1无持续按松手时的操作
CharValAdd(Num_Pointer);
}
{
//按键1松手时的操作
}
Key_Over=0;
Key_Scanning[0].Speed=0;
break;
case 2:
if(Key_Scanning[1].Speed==0)
{
//按键2无持续按松手时的操作
CharValReduce(Num_Pointer);
}
{
//按键2松手时的操作
}
Key_Over=0;
Key_Scanning[1].Speed=0;
break;
case 3:
if(Key_Scanning[2].Speed==0)
{
//按键3无持续按松手时的操作
}
{
//按键3松手时的操作
if(Num_Pointer==&Num_Page_A)
{
Num_Pointer=&Num_Page_B;
Smg_1.InvalidZero_NoDis=0;
}
else
{
if(Num_Pointer==&Num_Page_B)
{
Num_Pointer=&Num_Page_A;
Smg_1.InvalidZero_NoDis=1;
}
}
}
Key_Over=0;
Key_Scanning[2].Speed=0;
break;
case 4:
if(Key_Scanning[3].Speed==0)
{
//按键4无持续按松手时的操作
}
{
//按键4松手时的操作
Smg_1.Flash=!Smg_1.Flash;
IR_Learn_Mode=!IR_Learn_Mode;
WRITE_LED_LEARN_OVER=1;
for(i=0;i<8;i++)
IR_Code_OneFrame[i]=0;
}
Key_Over=0;
Key_Scanning[3].Speed=0;
break;
case 5:
if(Key_Scanning[4].Speed==0)
{
//按键5无持续按松手时的操作
}
{
//按键5松手时的操作
IR_Save_Code=1;
}
Key_Over=0;
Key_Scanning[4].Speed=0;
break;
default:
break;
}
switch(Key_Ing)
{
case 1:
Key_Ing=0;
if(Key_Scanning[0].Pushed>NUM_CONTINUE_PUSHED_JUDGE)
{
Key_Scanning[0].Pushed=NUM_PUSHED_JUDGE+Key_Scanning[0].Speed;
{
//按键1持续按时的操作
CharValAdd(Num_Pointer);
}
if(Key_Scanning[0].Speed<NUM_SPEED_MAX)
Key_Scanning[0].Speed+=NUM_SPEED_ADD;
}
break;
case 2:
Key_Ing=0;
if(Key_Scanning[1].Pushed>NUM_CONTINUE_PUSHED_JUDGE)
{
Key_Scanning[1].Pushed=NUM_PUSHED_JUDGE+Key_Scanning[1].Speed;
{
//按键2持续按时的操作
CharValReduce(Num_Pointer);
}
if(Key_Scanning[1].Speed<NUM_SPEED_MAX)
Key_Scanning[1].Speed+=NUM_SPEED_ADD;
}
break;
case 3:
Key_Ing=0;
if(Key_Scanning[2].Pushed>NUM_CONTINUE_PUSHED_JUDGE)
{
Key_Scanning[2].Pushed=NUM_PUSHED_JUDGE+Key_Scanning[2].Speed;
{
//按键3持续按时的操作
}
if(Key_Scanning[2].Speed<NUM_SPEED_MAX)
Key_Scanning[2].Speed+=NUM_SPEED_ADD;
}
break;
case 4:
Key_Ing=0;
if(Key_Scanning[3].Pushed>NUM_CONTINUE_PUSHED_JUDGE)
{
Key_Scanning[3].Pushed=NUM_PUSHED_JUDGE+Key_Scanning[3].Speed;
{
//按键4持续按时的操作
}
if(Key_Scanning[3].Speed<NUM_SPEED_MAX)
Key_Scanning[3].Speed+=NUM_SPEED_ADD;
}
break;
case 5:
Key_Ing=0;
if(Key_Scanning[4].Pushed>NUM_CONTINUE_PUSHED_JUDGE)
{
Key_Scanning[4].Pushed=NUM_PUSHED_JUDGE+Key_Scanning[4].Speed;
{
//按键5持续按时的操作
}
if(Key_Scanning[4].Speed<NUM_SPEED_MAX)
Key_Scanning[4].Speed+=NUM_SPEED_ADD;
}
break;
default:
break;
}
}
|