У меня нет ни на одном компе Win7х64, так что не подскажу
Могу свой вариант скетча выложить , но я использую хардверный UART
PHP код:
//void setup()
//{
// pinMode(0, INPUT); //RX
// pinMode(1, INPUT);//TX
//}
//void loop() { }
#define F_CPU 16000000UL
#include <avr/io.h>
#include <stdint.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <SmallUart.h>
#include <avr/wdt.h>
#include "listen.h"
#include "repeat.h"
#include "performed.h"
#include "protocol.h"
char cmd;
byte Lamp_Stat=0;
volatile uint16_t sample=0;
volatile uint8_t lastSample, FirstSample;
volatile byte new_data,future_data,old_data;
volatile byte stat=0;
volatile boolean light_status=false;
unsigned char *wave;
unsigned int length;
volatile uint16_t timerCount, lengthImpuls;
volatile uint16_t Counter=0;
//********************************************************************
ISR(TIMER2_COMPA_vect)
{
switch (stat)
{
case 0:{
old_data = pgm_read_byte(&wave[sample]); ta;
stat=1;
++sample;
if (sample == length) stat=4;
future_data = pgm_read_byte(&wave[sample]);
new_data = (old_data+future_data)/2;
}
break;
case 1: {OCR2A=(old_data+new_data)/2; stat=2; }
break;
case 2: {OCR2A = new_data; stat=3; }
break;
case 3: {OCR2A=(new_data+future_data)/2; stat=0; }
break;
case 4: if(lastSample==0) stat=5; else {--lastSample; OCR2A=lastSample;}
break;
case 5: stopPlayback();
break;
}
}
//********************************************************************
void setup()
{
pinMode(2, INPUT); // Вход , к фототранзистору
pinMode(5, OUTPUT); //выход ШИМ на ИК светодод
TCCR0B = TCCR0B & 0b11111000 | 3;//частота ШИМ 1000Гц
analogWrite(5,128 ); //запустить ШИМ
for (uint8_t i=11; i<20; ++i) {pinMode(i, OUTPUT); digitalWrite(i,LOW);}//выходы на триаки
digitalWrite(11, LOW); //Выключить динамик
UART_Init(9600);
VRbot_setup();
attachInterrupt(0, Ir_sens, RISING); //внешнее прерывание по фронту
//Timer1.initialize(10); //инициализация таймера
//Timer1.attachInterrupt(callback); //прерывание таймера
wdt_enable (WDTO_8S);//wdt установить на 8сек
}
void callback() { timerCount++; }
void Ir_sens()
{
lengthImpuls = timerCount;
if(lengthImpuls<99 || lengthImpuls>105) Counter=0;
Counter++;
}
//********************************************************************
void loop()
{
//label1:
VRbot_RecognizeSD(3); //тригер label1:
cmd = VRbot_CheckResult();
if(cmd == 0 || cmd == 1 || cmd == 2 )
{
play_wave((unsigned char *)listen, listen_length);
_delay_ms(500);
VRbot_RecognizeSD(2); //label2:
cmd = VRbot_CheckResult();
// if(cmd > 0) goto label2;
switch (cmd)
{
case -4: VRbot_Detect(); break;
case -3: play_wave((unsigned char *)repeat, repeat_length); break; // INVALID
case -2: play_wave((unsigned char *)repeat, repeat_length); break;//TimeOut
case -1: play_wave((unsigned char *)repeat, repeat_length); break; // Error
case 0: Lamp_Stat=~Lamp_Stat; break;//я
case 1: Lamp_Stat=~Lamp_Stat; break;//Кристина
case 2: Lamp_Stat=~Lamp_Stat; break;//Таня
case 3: Lamp_Stat=~Lamp_Stat; break;//Максим
case 4: Lamp_Stat=~Lamp_Stat; break;//Игорь
}//switch
Lamp_Swich();
} else if(cmd == -4) VRbot_Detect(); //goto label1;
wdt_reset();
}
//******************************************************
void Lamp_Swich(void)
{
if(Lamp_Stat==0) for (int i=13; i < 20; i++) digitalWrite(i,LOW);
else for (int i=13; i < 20; i++) digitalWrite(i,HIGH);
}
//******************************************************
unsigned char VRbot_read(void)
{
uint8_t val = 0;
for (uint16_t i = 0; i < 3000; ++i)
{
if(UART_ReadByte(val)) break;
_delay_ms(2);
}
// while(!UART_ReadByte(val)) {_delay_ms(2);}
return val;
}
//******************************************************
void VRbot_write(uint8_t b)
{
//Serial.print(b, BYTE);
UART_SendByte(b);
_delay_ms(5);
}
//******************************************************
void VRbot_setup()
{
if (VRbot_Detect())
{
VRbot_ID();
//VRbot_SetBaudrate(115200);
VRbot_SetLanguage(0);
VRbot_SetTimeout(5);
VRbot_SetLDelay(0);
} else while(!VRbot_Detect){digitalWrite(13,LOW); _delay_ms(200); digitalWrite(13,HIGH); _delay_ms(200); }
}
//******************************************************
boolean VRbot_Detect(void)
{
unsigned char i;
for (i = 0; i < 100; ++i)
{
VRbot_write(CMD_BREAK);
if ( VRbot_read() == STS_SUCCESS) {return true; break;} else return false;
}
}
//******************************************************
boolean VRbot_ID(void)
{
VRbot_write(CMD_ID);
if (VRbot_read() == STS_ID) VRbot_write(ARG_ACK); else return 0;
if (VRbot_read() == ARG_ZERO) return true; else return false;
}
//******************************************************
boolean VRbot_SetTimeout(unsigned char s)
{
VRbot_write(CMD_TIMEOUT);
VRbot_write(ARG_ZERO + s);
if (VRbot_read() == STS_SUCCESS) return true; else return false;
}
//******************************************************
boolean VRbot_SetLanguage(unsigned char lang)
{
VRbot_write(CMD_LANGUAGE);
VRbot_write(ARG_ZERO + lang);
if (VRbot_read() == STS_SUCCESS) return true; else return false;
}
//******************************************************
boolean VRbot_SetBaudrate(unsigned int bdr)
{
unsigned char b=12;
if (bdr==115200)b=1;
if (bdr==57600) b=2;
if (bdr==38400)b=3;
if (bdr==19200)b=6;
if (bdr==9600)b=12;
VRbot_write(CMD_BAUDRATE);
VRbot_write(ARG_ZERO + b);
if (VRbot_read() == STS_SUCCESS) {Serial.begin(bdr); return true;} else return false;
}
//******************************************************
boolean VRbot_SetLDelay(unsigned char time)
{
VRbot_write(CMD_DELAY);
VRbot_write(ARG_ZERO + time);
if (VRbot_read() == STS_SUCCESS) return true; else return false;
}
//******************************************************
void VRbot_RecognizeSD(unsigned char group)
{
VRbot_write(CMD_RECOG_SD);
VRbot_write(ARG_ZERO + group);
}
//******************************************************
void VRbot_RecognizeSI(unsigned char ws)
{
VRbot_write(CMD_RECOG_SI);
VRbot_write(ARG_ZERO + ws);
}
//******************************************************
char VRbot_CheckResult(void)
{
unsigned char rx=0;
rx = VRbot_read();
if (rx == STS_SIMILAR || rx == STS_RESULT)
{
VRbot_write(ARG_ACK);
return (VRbot_read() - ARG_ZERO);
}
if (rx == STS_TIMEOUT) return -2;
if (rx == STS_ERROR) return -1;
if (rx == STS_INVALID) return -3;
if (rx == 0) return -4;
}
//*************************************************************************
void startPlayback()
{
sample=0;
stat=0;
ASSR |=(1<<AS2); //AS2 Asynchronous Timer/Counter2
TCCR2A |= ((1<<COM2A1)|(0<<COM2A0)|(1<<WGM21) | (0<<WGM20));
TCCR2B = ((0 << CS22) | (0 << CS21) | (1 << CS20) | (0<<WGM22));
lastSample = pgm_read_byte(&wave[length-1]);
FirstSample = pgm_read_byte(&wave[0]);
TCNT2 = 0;
TIMSK2|=(1<<OCIE2A);
sei();
for (int i=0; i <FirstSample; i++)
{
new_data=i;
stat=2;
sample = 0;
_delay_us(10);
}
stat=0;
}
void stopPlayback()
{
TIMSK2&=(0<<OCIE2A);
TCCR2B &=(0<<CS10);
}
//******************************************************
void play_wave(unsigned char *wave_data, unsigned int wave_length)
{
wave=wave_data;
length=wave_length;
startPlayback();
}
//******************************************************