📄 serialdrv.i
字号:
{
while (ncont--)
{
#asm("wdr");
while ((UCSR0A & (1<<5))==0);
UDR0 = *(pBuf ++);
}
}
void sp_init()
{
unsigned char i;
my_sp_status.buffer[0] = (BYTE)0x00;
my_sp_status.data = 0;
my_sp_status.empty = 0;
memset(my_sp_status.buffer, 0x00, 10 );
if (study_num1 > 250)
study_num1 = 0;
if (study_num2 > 250)
study_num2 = 0;
for (i=0;i<250;i++)
{
if (study_data1[i] > 65500)
study_data1[i] = 0;
if (study_data2[i] > 65500)
study_data2[i] = 0;
}
int_start = 0;
int_num = 0;
my_sp_status.timeout = 0;
}
/*
unsigned char sp_proc()
{
unsigned char nloop = 0;
//Note: Receive: start: 9ms(low)+4.5ms(high) 0: 0.565ms(low)+0.56ms(high)=1.125ms(T) 1: 0.565ms(low)+1.685ms(high)=2.25ms(T)
my_sp_status.timeout = timer_get_sp_timeout();
if( my_sp_status.timeout == TRUE)
{
if(my_sp_status.timeout == TRUE)
{
my_sp_status.timeout = FALSE;
}
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
timer_delay(500);
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
timer_delay(3000);
led_send0();
int_start = 0;
OCR3CL=0x00; //0x30
// int_num1=0;
int_num1 = int_num;
return 0;
if (int_num1 == int_num)
{
for (nloop = 0; nloop < int_num; nloop++)
{
if (abs(int_data[nloop]-int_data1[nloop]) > 15)
{
nloop=0;
break;
}
}
nloop = 1;
if (nloop)
{
for (nloop = 0; nloop < int_num; nloop++)
{
int_data1[nloop]=(int_data1[nloop]+int_data[nloop])/2;
}
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
timer_delay(500);
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
timer_delay(3000);
led_send0();
int_start = 0;
OCR3CL=0x00; //0x30
// int_num1=0;
int_num1 = int_num;
return 0;
}
else
{
for (nloop = 0; nloop < int_num; nloop++)
int_data1[nloop]=int_data[nloop];
int_num1 = int_num;
int_start = 0;
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
return 1;
}
}
else
{
for (nloop = 0; nloop < int_num; nloop++)
int_data1[nloop]=int_data[nloop];
WORK_LED = 1;
timer_delay(500);
WORK_LED = 0;
int_start = 0;
int_num1 = int_num;
}
}
}
*/
unsigned char sp_proc()
{
unsigned char nloop = 0;
bit abs_ok = 1;
//Note: Receive: start: 9ms(low)+4.5ms(high) 0: 0.565ms(low)+0.56ms(high)=1.125ms(T) 1: 0.565ms(low)+1.685ms(high)=2.25ms(T)
my_sp_status.timeout = timer_get_sp_timeout();
if( my_sp_status.timeout == 1)
{
#asm("wdr");
if ((count > 0) && (int_num1 == int_num))
{
for (nloop = 0; nloop < int_num; nloop++)
{
if (abs(int_data[nloop]-int_data1[nloop]) > 20) //20
{
abs_ok = 0;
break;
}
}
if (abs_ok)
{
if (count >= 2)
{
for (nloop = 0; nloop < int_num; nloop++)
{
int_data2[nloop]=(int_data2[nloop]+int_data1[nloop]+int_data[nloop])/3;
}
if (study_key)
{
study_num2 = int_num;
for (nloop = 0; nloop < int_num; nloop++)
{
study_data2[nloop]=int_data2[nloop];
}
study_key=0;
int_start = 0;
(*(unsigned char *) 0x82)=0x00; //0x30
count=0;
int_num=0;
int_num1=0;
my_sp_status.timeout = 0;
EIFR=0x0D;
EIMSK=0x01; //0: 0x01 //2&3: 0x0C //6&7: 0xC0 //0&6&7: 0xC1 //0&2&3&6&7: 0xCD
study_ok = 1;
}
else
{
study_num1 = int_num;
for (nloop = 0; nloop < int_num; nloop++)
{
study_data1[nloop]=int_data2[nloop];
}
study_key++;
int_start = 0;
(*(unsigned char *) 0x82)=0x00; //0x30
count=0;
int_num=0;
int_num1=0;
my_sp_status.timeout = 0;
}
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
timer_delay(500);
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
timer_delay(500);
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
// timer_delay(3000);
// led_send0(1);
return 0;
}
else
{
for (nloop = 0; nloop < int_num; nloop++)
{
int_data2[nloop]=int_data1[nloop];
int_data1[nloop]=int_data[nloop];
}
count++ ;
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
timer_delay(500);
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
}
}
else
{
for (nloop = 0; nloop < int_num; nloop++)
int_data1[nloop]=int_data[nloop];
}
}
else
if ((count > 0) && (int_num1 != int_num))
{
for (nloop = 0; nloop < int_num; nloop++)
int_data1[nloop]=int_data[nloop];
}
else
if ((count == 0) && (int_num > 0))
{
for (nloop = 0; nloop < int_num; nloop++)
int_data1[nloop]=int_data[nloop];
count++;
PORTD.7 = 1;
timer_delay(500);
PORTD.7 = 0;
timer_delay(500);
PORTD.7 = 1;
}
int_start = 0;
int_num1 = int_num;
(*(unsigned char *) 0x82)=0x00; //0x30
my_sp_status.timeout = 0;
}
#asm("wdr");
}
void led_send0(unsigned char onoff)
{
unsigned char nloop = 0;
//Note: send: start: 9ms(high)+4.5ms(low) 0: 0.565ms(high)+0.56ms(low)=1.125ms(T) 1: 0.565ms(high)+1.685ms(low)=2.25ms(T)
#asm("wdr");
timer3_initY();
if (onoff)
{
int_num = study_num1;
for (nloop = 0; nloop < int_num; nloop++)
int_data[nloop]=study_data1[nloop];
}
else
{
int_num = study_num2;
for (nloop = 0; nloop < int_num; nloop++)
int_data[nloop]=study_data2[nloop];
}
TCNT1 = 0;
(*(unsigned char *) 0x82)=0x30; //0x00: stop 0x30: start
for (nloop = 0; nloop < int_num; nloop++)
{
while (TCNT1 < int_data[nloop]); //int_data2[nloop]
if ((nloop+1)%2)
(*(unsigned char *) 0x82)=0x00; //0x00: stop 0x30: start
else
(*(unsigned char *) 0x82)=0x30; //0x00: stop 0x30: start
}
(*(unsigned char *) 0x82)=0x00; //0x30
#asm("wdr");
timer3_initN();
}
/*
unsigned char sp_proc()
{
unsigned char nloop = 0;
unsigned char nloop1 = 0;
unsigned char value = 0;
//Note: Receive: start: 9ms(low)+4.5ms(high) 0: 0.565ms(low)+0.56ms(high)=1.125ms(T) 1: 0.565ms(low)+1.685ms(high)=2.25ms(T)
my_sp_status.timeout = timer_get_sp_timeout();
if( my_sp_status.timeout == TRUE)
{
if(my_sp_status.timeout == TRUE)
{
my_sp_status.timeout = FALSE;
}
if ((int_data[0] >= 256 && int_data[0] <= 262) && (int_data[1] >= 386 && int_data[1] <= 392))
{
memset(my_sp_status.buffer, 0x00, SPMAXLEN);
for(nloop = 2; nloop < int_num; (nloop= nloop + 2))
{
if (((int_data[nloop] - int_data[nloop-1]) >= 13 && (int_data[nloop] - int_data[nloop-1]) <= 19)
&& ((int_data[nloop+1] - int_data[nloop]) >= 45 && (int_data[nloop+1] - int_data[nloop]) <= 51))
// if (((int_data[nloop] - int_data[nloop-1]) >= 10 && (int_data[nloop] - int_data[nloop-1]) <= 22)
// && ((int_data[nloop+1] - int_data[nloop]) >= 42 && (int_data[nloop+1] - int_data[nloop]) <= 54))
{
value = value ^ 0x01;
value = value << 1;
}
else if (((int_data[nloop] - int_data[nloop-1]) >= 13 && (int_data[nloop] - int_data[nloop-1]) <= 19)
&& ((int_data[nloop+1] - int_data[nloop]) >= 13 && (int_data[nloop+1] - int_data[nloop]) <= 19))
// else if (((int_data[nloop] - int_data[nloop-1]) >= 10 && (int_data[nloop] - int_data[nloop-1]) <= 22)
// && ((int_data[nloop+1] - int_data[nloop]) >= 10 && (int_data[nloop+1] - int_data[nloop]) <= 22))
{
value = value << 1;
}
else
{
nloop = 0;
break;
}
if (nloop % 16 == 0)
{
my_sp_status.buffer[nloop1++] = value;
value = 0;
}
}
my_sp_status.buffer[nloop1++] = value;
timer_delay(3000);
led_send1(my_sp_status.buffer);
}
int_start = 0;
OCR3CL=0x00; //0x30
}
nloop1 ++;
}
void led_send1(unsigned char * seed_data)
{
unsigned char nloop = 0;
unsigned char nloop1 = 0;
unsigned char value = 0;
unsigned char sed_data[6]={0x82,0xc0,0x02,0x9c,0x00,0x00};
//Note: send: start: 9ms(high)+4.5ms(low) 0: 0.565ms(high)+0.56ms(low)=1.125ms(T) 1: 0.565ms(high)+1.685ms(low)=2.25ms(T)
//T2: 28.2uS
OCR3CL=0x30; //0x00: stop 0x30: start
// delay_us(8600);
call_time=0;
while (call_time<310); //319
OCR3CL=0x00; //0x30
// delay_us(3500);
call_time=0;
while (call_time<125); //159
value=*seed_data;
OCR3CL=0x30; //0x00
// delay_us(540); //565
call_time=0;
while (call_time<19);
OCR3CL=0x00; //0x30
if (value&0x80)
{
// delay_us(1580); //1685
call_time=0;
while (call_time<59); //59.75
}
else
{
// delay_us(535);
call_time=0;
while (call_time<19); //20
}
for (nloop = 0; nloop < 6; nloop++)
{
value=*seed_data++;
OCR3CL=0x30; //0x00
for (nloop1=0;nloop1<8;nloop1++)
{
// delay_us(540); //565
call_time=0;
while (call_time<19); //20
OCR3CL=0x00; //0x30
if (value&0x80)
{
// delay_us(1580); //1685
call_time=0;
while (call_time<59); //59.75
}
else
{
// delay_us(535);
call_time=0;
while (call_time<19); //20
}
value=value<<1;
OCR3CL=0x30; //0x00
}
}
OCR3CL=0x00; //0x30
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -