Subversion Repositories svnkaklik

Rev

Rev 298 | Rev 300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
297 kaklik 1
//----------------------------------------------------------------------------------
2
//	Prevodnik RS232 <--> RS485 s prodlevou pri prevodu smerem do RS485
299 kaklik 3
//	pri startbitu na RS232 zapne okamzite vysilac pokud nejsou detekovana data z RS485.
297 kaklik 4
//----------------------------------------------------------------------------------
5
 
6
#include <avr/io.h>
7
#include <avr/interrupt.h>
8
#include <stdlib.h>
9
#include <ctype.h>
10
#include <avr/eeprom.h>
11
#include <avr/pgmspace.h>
12
 
13
 
14
#define F_CPU 3686400UL
15
#include <util/delay.h>
16
 
17
void delay_ms(unsigned int ms)
18
{
19
  while(ms)
20
  {
21
    _delay_ms(0.96);
22
	ms--;
23
  }
24
}
25
 
26
 
27
// ------------------------------------------------------------------
28
//	Main
29
// ------------------------------------------------------------------
30
int main(void)
31
{
298 kaklik 32
int delay;
33
int spozdeni;
299 kaklik 34
int last;
297 kaklik 35
 
36
  DDRD |= (1<<DDD5);
298 kaklik 37
//  DDRB |= (1<<DDB3);
297 kaklik 38
 
298 kaklik 39
  TCCR1B |= (1 << CS10);  // Set up timer 
297 kaklik 40
 
298 kaklik 41
//  PORTB |= (1<<PB3);
297 kaklik 42
 
43
  while(1)
44
  {
298 kaklik 45
	if(!(PIND & (1<<PD1)))   // kdyz je 0 na datech 
297 kaklik 46
	{ 
299 kaklik 47
	  PORTD &= ~(1<<PD5);    // zapni vysilani	  
48
	  for (spozdeni=0;spozdeni<=8;spozdeni ++)
49
	  {
50
		last = (PIND & (1<<PD1));
51
	    TCNT1 = 0;					// zacni znova merit cas
52
	    while (TCNT1 <= delay)
53
		{
54
		  if((PIND & (1<<PD1)) != last)
55
		  {
56
		    if (TCNT1 < delay) delay = TCNT1;
57
			break;
58
		  }
298 kaklik 59
        }
60
	  }
299 kaklik 61
	  while (!(PIND & (1<<PD1)));
297 kaklik 62
    }
298 kaklik 63
    else  PORTD |= (1<<PD5);  	// kdyz je 1 prepni na prijem 
297 kaklik 64
  }
298 kaklik 65
  return(0);
297 kaklik 66
}