X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fnano%2Fmain.c;fp=avr%2Fnano%2Fmain.c;h=0cb0acfba471aaaf79d67feba98932da429af36c;hp=0000000000000000000000000000000000000000;hb=4053424236542640b1cb23624877725d5ae8e50f;hpb=34bae39fabd9b44e1d169087e8d18d542f4f1525 diff --git a/avr/nano/main.c b/avr/nano/main.c new file mode 100644 index 0000000..0cb0acf --- /dev/null +++ b/avr/nano/main.c @@ -0,0 +1,167 @@ +#include +#include +#include +#include +#include +#include +#include "uart.h" + +/* + * I2C Register Map (8 Bit) + * 0x00 Register select + * 0x01 Distance left MSB + * 0x02 Distance left LSB + * 0x03 Distance right MSB + * 0x04 Distance right LSB + * + * 0xff Bootloader + */ + + +#define TWI_ACK TWCR = (1<>8; + TWI_ACK; + break; + case 0x02: // Distance right LSB + TWDR = tmp16; + TWI_ACK; + break; + case 0x03: // Distance right MSB + tmp16 = dist_right; + TWDR = tmp16>>8; + TWI_ACK; + break; + case 0x04: // Distance right LSB + TWDR = tmp16; + TWI_ACK; + break; + default: + TWDR = 0; + TWI_NAK; + } + ireg++; + break; + default: + TWI_RESET; + } +} + + +uint16_t ReadChannel(uint8_t mux) { + uint8_t i; + uint16_t result; + + ADCSRA = (1<