#include #include #include #include #include "yaMBSiavr.h" uint8_t font[] = { 0xEE, 0x82, 0xDC, 0xD6, 0xB2, 0x76, 0x7E, 0xC2, 0xFE, 0xF6, }; uint8_t display[4]; volatile uint16_t holdingRegisters[4]; void timer0_init() { TCCR0 = (1<250kHz:250-=>1kHz) TIMSK |= 1<250kHz:250-=>1kHz) //TIMSK |= 1<> 4]; display[2] = font[(bcd&0x0f00) >> 8]; display[3] = bcd&0xF000 ? font[(bcd&0xf000) >> 12] : 0; break; default: modbusSendException(ecIllegalFunction); break; } } } int main(void){ DDRB |= _BV(4) | _BV(3) | _BV(2) | _BV(1) | _BV(0); DDRD = 0xFC; DDRA = 0x03 << 4; DDRC = 0xFE; modbusSetAddress(24); //better set this to sth. modbusInit(); timer0_init(); timer2_init(); sei(); while(1){ modbusGet(); } } ISR(TIMER0_COMP_vect) { if(PORTB & 0x01){ PORTB = (PORTB & 0xF0) | 1<<1 | 1<<3; PORTD = display[3] & 0xFC; PORTA = (PORTA & 0xCF) | (display[3] & 0x03) << 4; PORTC = display[1]; } else{ PORTB = (PORTB & 0xF0) | 1<<0 | 1<<2; PORTD = display[2] & 0xFC; PORTA = (PORTA & 0xCF) | (display[2] & 0x03) << 4; PORTC = display[0]; } } ISR(TIMER2_OVF_vect) { //this ISR is called 9765.625 times per second modbusTickTimer(); }