Rev 298 | 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.
//----------------------------------------------------------------------------------
#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)
{
int delay;
int spozdeni;
int last;
DDRD |= (1<<DDD5);
// DDRB |= (1<<DDB3);
TCCR1B |= (1 << CS10); // Set up timer
// PORTB |= (1<<PB3);
while(1)
{
if(!(PIND & (1<<PD1))) // kdyz je 0 na datech
{
PORTD &= ~(1<<PD5); // zapni vysilani
for (spozdeni=0;spozdeni<=8;spozdeni ++)
{
last = (PIND & (1<<PD1));
TCNT1 = 0; // zacni znova merit cas
while (TCNT1 <= delay)
{
if((PIND & (1<<PD1)) != last)
{
if (TCNT1 < delay) delay = TCNT1;
break;
}
}
}
while (!(PIND & (1<<PD1)));
}
else PORTD |= (1<<PD5); // kdyz je 1 prepni na prijem
}
return(0);
}