Blame view

main.c 971 Bytes
7565f6e8   henyxia   C Style with doub...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #include <avr/io.h>
  #include <util/delay.h>
  
  #define CPU_FREQ        16000000L
  
  unsigned int joystick_lr;
  unsigned int joystick_ud;
  
  void init_serial(unsigned long int speed)
  {
  	//UBRR0 = CPU_FREQ/((speed)<<4)-1;
  	UBRR0 = 8;
  	UCSR0B = (1<<TXEN0 | 1<<RXEN0);
  	UCSR0C = (1<<UCSZ01 | 1<<UCSZ00);
  	UCSR0A &= (1 << U2X0);
  }
  
  void send_serial(unsigned char c)
  {
  	loop_until_bit_is_set(UCSR0A, UDRE0);
  	UDR0 = c;
  }
  
  unsigned char get_serial(void)
  {
  	loop_until_bit_is_set(UCSR0A, RXC0);
  	return UDR0;
  }
  
  void port_initio(void)
  {
  	DDRD &= 0xFC;
  	DDRD |= 0x3C;
  	DDRB &= 0xFE;
  	PORTD |= 0x3C;
  }
  
  int main(void)
  {
  	init_serial(250000);
  	port_initio();
  	uint8_t	opto0 = 0;
  	uint8_t	opto2 = 0;
    
  	while (1)
  	{
  		if((opto0 == 1) && ((PIND & 0x40) == 0x40))
  			PORTD &= 0xE7;
  		else
  			PORTD |= 0x18;
  		if((opto2 == 1) && ((PIND & 0x80) == 0x80))
  			PORTD &= 0xDB;
  		else
  			PORTD |= 0x24;
  
  		if((PINB & 0x01) == 0x01)
  			send_serial('U');
  		else
  			send_serial('D');
  	}
  
  	return 0;
  }