From: Scott W Harden Date: Sat, 15 Oct 2016 15:53:18 +0000 (+0200) Subject: http://www.swharden.com/wp/2016-09-19-hacking-a-cheap-%E2%80%A6oth-pc-interface/ X-Git-Url: http://git.rot13.org/?p=Arduino-Nano-VA-meter;a=commitdiff_plain;h=f3baf83eaef905a49236de14fe9cc572cbea3700 swharden.com/wp/2016-09-19-hacking-a-cheap-%E2%80%A6oth-pc-interface/ --- f3baf83eaef905a49236de14fe9cc572cbea3700 diff --git a/main.c b/main.c new file mode 100644 index 0000000..17a4c16 --- /dev/null +++ b/main.c @@ -0,0 +1,210 @@ +#define F_CPU 11059200ul + +#include +#include + +#define USART_BAUDRATE 9600 +#define UBRR_VALUE (((F_CPU/(USART_BAUDRATE*16UL)))-1) + +void serial_init(){ + // initialize USART (must call this before using it) + UBRR0=UBRR_VALUE; // set baud rate + UCSR0B|=(1<>(bitPos-1))&1){serial_send('1');} + else {serial_send('0');} + } +} + +void serial_test(){ + char i; + serial_break(); + for(i=65;i<65+26;i++){ + serial_send(i); + } + serial_break(); +} + + + + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +// these variables will hold an instant capture of all input pins +volatile uint8_t regB; +volatile uint8_t regC; +volatile uint8_t regD; + +// these values will hold the current/voltage value +volatile char current[4]; +volatile char voltage[4]; + + +void read_capture(){ + // load the volatile capture variables with tue current pin state + regB=PINB; + regC=PINC; + regD=PIND; +} + +char saved_letter(){ + // returns the letter (1-8) of the segments stored in read_capture + // returned value will be in ASCII + // returns ? if no letter is selected, or if it's confusing + + // start by creating a "letter" variable which defines pin states + uint8_t letter=0; + if(regD&(1<