Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
297 kaklik 1
//----------------------------------------------------------------------------------
2
//	Prevodnik RS232 <--> RS485 s prodlevou pri prevodu smerem do RS485
3
//	pri startbitu na RS232 zapne okamzite vysilac pokud nejsou detekovana data z RS485. pak ceka definovanou dobu, nez opet prepne kanal na prijem.
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
{
32
 
33
  DDRD |= (1<<DDD5);
34
  DDRB |= (1<<DDB3);
35
 
36
  TCCR1B |= ((1 << CS10) | (1 << CS11));  // Set up timer 
37
 
38
  PORTB |= (1<<PB3);
39
 
40
  while(1)
41
  {
42
	if(!(PIND & (1<<PD1)))
43
	{ 
44
	  TCNT1 = 0;
45
	  PORTD &= ~(1<<PD5);
46
    }
47
 
48
    if ((TCNT1 >= 1000) && ((PIND & (1<<PD1)))) 
49
    {  
50
	  PORTD |= (1<<PD5);
51
	  TCNT1 = 0;
52
    }
53
  }
54
  return( 0 );
55
}