From 15e0b0dd99a31fd28d1471f6f372b410be31c1fc Mon Sep 17 00:00:00 2001 From: Ole Artz Date: Fri, 23 Jun 2017 12:02:49 +0200 Subject: [PATCH] Add configuration channels fo ADCuc --- atmega32u4/adcuc/main.c | 132 +++++++++++++++++++++++++++++----------- 1 file changed, 98 insertions(+), 34 deletions(-) diff --git a/atmega32u4/adcuc/main.c b/atmega32u4/adcuc/main.c index f6139ab..6822b56 100644 --- a/atmega32u4/adcuc/main.c +++ b/atmega32u4/adcuc/main.c @@ -32,51 +32,64 @@ //Icc? -- Firmware Info -#define LED2_ON() PORTB |= (1<> (nib*4)) & 0xF; if (t <= 9) {return t + 0x30;} return t - 10 + 0x61; } - + uint8_t hex_to_int(uint8_t h) { //assumes valid number if (h < 0x40) return h-0x30; if (h < 0x50) return h-0x41+10; return h-0x61+10; } - -void sub2(uint8_t* c1, uint8_t* c2) { - uint8_t b = hex_to_int(*c1)*16 + hex_to_int(*c2); - b -= 4; - *c1 = nib_to_hex(b,1); - *c2 = nib_to_hex(b,0); - } -void send_answer_buf(uint8_t* b) { - UCSR1B |= (1<< UDRIE1); - } - -void send_answer_hex(uint16_t v) { - txbuf[0]='A'; - txbuf[1]=nib_to_hex(v,2); - txbuf[2]=nib_to_hex(v,1); - txbuf[3]=nib_to_hex(v,0); - txbuf[4]='\n'; - txbuf[5] = 0; - send_answer_buf(txbuf); +void send_answer_hex(uint8_t chan, uint16_t v) { + txbuf[0]='A';//ADC + txbuf[1]=nib_to_hex(chan,0); + txbuf[2]='-';//temperature or modi + txbuf[3]=nib_to_hex(v,3); + txbuf[4]=nib_to_hex(v,2); + txbuf[5]=nib_to_hex(v,1); + txbuf[6]=nib_to_hex(v,0); + txbuf[7]='\n'; + txbuf[8] = 0; + usb_serial_write(txbuf,8); } @@ -102,21 +115,64 @@ void getdata(uint8_t buf) { 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; + send_answer_hex(channel,result); +} + void update_eeprom(void) { //etc... // eeprom_update_byte((uint8_t*)0x28,adc_enable); } - - +void do_channel(uint8_t channel) { + uint8_t get_value_1; + uint8_t get_value_2; + if(channel<4) + ADC1_select(); + else + ADC2_select(); + SPDR = 0b11000011 + ((channel & 0b00000011) << 4); // MSB=Byte1 + while(SPDR & ((1<