Blame | Last modification | View Log | Download
//----------------------------------------------------------------------------------
// Prevodnik RS232 <--> RS485 s prodlevou pri prevodu smerem do RS485
// pri startbitu na RS232 zapne okamzite vysilac pokud nejsou detekovana data z RS485. pak ceka definovanou dobu, nez opet prepne kanal na prijem.
//----------------------------------------------------------------------------------
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <ctype.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#define F_CPU 3686400UL
#include <util/delay.h>
void delay_ms(unsigned int ms)
{
while(ms)
{
_delay_ms(0.96);
ms--;
}
}
// ------------------------------------------------------------------
// Main
// ------------------------------------------------------------------
int main(void)
{
DDRD |= (1<<DDD5);
DDRB |= (1<<DDB3);
TCCR1B |= ((1 << CS10) | (1 << CS11)); // Set up timer
PORTB |= (1<<PB3);
while(1)
{
if(!(PIND & (1<<PD1)))
{
TCNT1 = 0;
PORTD &= ~(1<<PD5);
}
if ((TCNT1 >= 1000) && ((PIND & (1<<PD1))))
{
PORTD |= (1<<PD5);
TCNT1 = 0;
}
}
return( 0 );
}