txbuf[7]='\n';
txbuf[8] = 0;
usb_serial_write(txbuf,8);
+ usb_serial_flush_output();
}
if (rxcnt >= 7 || buf == '\n' || buf == '\r') { rxcnt = 0; }
}
-void orignal_value(uint8_t channel, uint8_t get_value_1, uint8_t get_value_2) {
- uint16_t result = (get_value_2 << 8) | get_value_1;
+void original_value(uint8_t channel, uint8_t get_value_1, uint8_t get_value_2) {
+ uint16_t result = (get_value_1 << 8) | get_value_2;
send_answer_hex(channel,result);
}
else
ADC2_select();
SPDR = 0b11000011 + ((channel & 0b00000011) << 4); // MSB=Byte1
- while(SPDR & ((1<<SPIF) ==0));
+ while ((SPSR & (1<<SPIF)) == 0);
get_value_1 = SPDR;
SPDR = 0b11101011; // LSB=Byte2
- while(SPDR & ((1<<SPIF) ==0));
+ while ((SPSR & (1<<SPIF)) == 0);
get_value_2 = SPDR;
if(channel<4)
ADC1_unselect();
ADC1_select();
else
ADC2_select();
- SPDR = 0b10000000; // MSB=Byte1
- while(SPDR & ((1<<SPIF) ==0));
+ SPDR = 0b00000000; // MSB=Byte1
+ while ((SPSR & (1<<SPIF)) == 0);
get_value_1 = SPDR;
- SPDR = 0b00000001; // LSB=Byte2
- while(SPDR & ((1<<SPIF) ==0));
+ SPDR = 0b00000000; // LSB=Byte2
+ while ((SPSR & (1<<SPIF)) == 0);
get_value_2 = SPDR;
if(channel<4)
ADC1_unselect();
else
ADC2_unselect();
- orignal_value(channel, get_value_1, get_value_2);
+ original_value(channel, get_value_1, get_value_2);
}
PORTC = 0b11000000;
DDRC = 0b00000000;
- PORTE = 0b01000100;
+ PORTE = 0b01000000;
DDRE = 0b00000000;
//limit[3] |= eeprom_read_byte((uint8_t*)0x26);
//Timer0 at ~488 Hz overflow for ADC control and buttons
- TCCR0B = (1 << CS01) | (1 << CS00);
+ TCCR0B = 4 << CS00; //(1 << CS01) | (1 << CS00);
TIMSK0 = (1 << TOIE0); //Overflow interrupt`
sei();
uint16_t lasttime = 0;
+ uint16_t step = 0;
while(1) {
int n = usb_serial_getchar();
- if (n >= 0) {
+ while (n >= 0) {
getdata(n);
+ n = usb_serial_getchar();
}
if(time != lasttime) {
- switch(time) {
- case 1: do_channel(1); break;
- case 2: read_channel(1); break;
- case 487: time = 0; break;
+ switch(step++) {
+ case 10: do_channel(0); break;
+ case 20: read_channel(0); break;
+ case 30: do_channel(1); break;
+ case 40: read_channel(1); break;
+ case 50: do_channel(2); break;
+ case 60: read_channel(2); break;
+ case 70: do_channel(3); break;
+ case 80: read_channel(3); break;
+ case 90: do_channel(4); break;
+ case 100: read_channel(4); break;
+ case 110: do_channel(5); break;
+ case 120: read_channel(5); break;
+ case 130: do_channel(6); break;
+ case 140: read_channel(6); break;
+ case 150: do_channel(7); break;
+ case 160: read_channel(7); break;
+ }
+ if (step >= 487/2) {
+ //time = 0;
+ step = 0;
}
}