diff --git a/newcode/main.c b/newcode/main.c index e34c808..0230b57 100644 --- a/newcode/main.c +++ b/newcode/main.c @@ -1,11 +1,12 @@ #include #include -#include "uart.h" #include +#include "yaMBSiavr.h" + +uint16_t inputStatus[9]; void init_clk(void) { - // ========= System Clock configuration ========= // Set to external 16Mhz crystal, using the PLL at *2 // set it to be a 12-16Mhz crystal with a slow start-up time. @@ -28,18 +29,47 @@ void init_clk(void) // ============================================== } +void init_timer_100us(){ + TCC0.CTRLA |= TC_CLKSEL_DIV256_gc; + TCC0.PER = 13; // ==> 9615us + TCC0.INTCTRLA |= TC_OVFINTLVL_MED_gc; +} + +void modbusGet(void) { + if (modbusGetBusState() & (1<> 8) | (bscale << USART_BSCALE0_bp); + + USARTD0.CTRLB = USART_TXEN_bm | USART_RXEN_bm; + //Interrupt enable (levels) - //Physical type - //Busstate + USARTD0.CTRLA |= USART_RXCINTLVL_HI_gc; + USARTD0.CTRLA |= USART_TXCINTLVL_HI_gc; + + PORTD_OUTSET = PIN3_bm; + PORTD_DIRSET = PIN3_bm; + PORTD_OUTCLR = PIN2_bm; + PORTD_DIRCLR = PIN2_bm; + + //TODO Physical type 485 + + BusState=(1<