Commit d2a71b921f9b838f2d2b1119644f51595bc5ae7b
1 parent
7565f6e8
Initial serial controlled version
Makefile adapted to match with the port configuration
Showing
2 changed files
with
37 additions
and
16 deletions
Show diff stats
Makefile
1 | -export CC = avr-gcc | 1 | +CC = avr-gcc |
2 | 2 | ||
3 | -export MCU = atmega328p | ||
4 | -export TARGET_ARCH = -mmcu=$(MCU) | 3 | +MCU = atmega328p |
4 | +TARGET_ARCH = -mmcu=$(MCU) | ||
5 | 5 | ||
6 | -export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g | ||
7 | -export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os | 6 | +CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g |
7 | +LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os | ||
8 | 8 | ||
9 | TARGET = usb | 9 | TARGET = usb |
10 | -TERM = /dev/ttyACM0 | 10 | +TERM = /dev/ttyACM1 |
11 | CPPFLAGS = -mmcu=$(MCU) | 11 | CPPFLAGS = -mmcu=$(MCU) |
12 | PGMER = -c stk500v1 -b 57600 -P $(TERM) | 12 | PGMER = -c stk500v1 -b 57600 -P $(TERM) |
13 | PGMERISP = -c stk500v1 -b 115200 -P $(TERM) | 13 | PGMERISP = -c stk500v1 -b 115200 -P $(TERM) |
14 | ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf | 14 | ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf |
15 | -export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) | 15 | +DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF) |
16 | 16 | ||
17 | C_SRC = $(wildcard *.c) | 17 | C_SRC = $(wildcard *.c) |
18 | OBJS = $(C_SRC:.c=.o) | 18 | OBJS = $(C_SRC:.c=.o) |
@@ -6,10 +6,9 @@ | @@ -6,10 +6,9 @@ | ||
6 | unsigned int joystick_lr; | 6 | unsigned int joystick_lr; |
7 | unsigned int joystick_ud; | 7 | unsigned int joystick_ud; |
8 | 8 | ||
9 | -void init_serial(unsigned long int speed) | 9 | +void init_serial(int speed) |
10 | { | 10 | { |
11 | - //UBRR0 = CPU_FREQ/((speed)<<4)-1; | ||
12 | - UBRR0 = 8; | 11 | + UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; |
13 | UCSR0B = (1<<TXEN0 | 1<<RXEN0); | 12 | UCSR0B = (1<<TXEN0 | 1<<RXEN0); |
14 | UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); | 13 | UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); |
15 | UCSR0A &= (1 << U2X0); | 14 | UCSR0A &= (1 << U2X0); |
@@ -37,26 +36,48 @@ void port_initio(void) | @@ -37,26 +36,48 @@ void port_initio(void) | ||
37 | 36 | ||
38 | int main(void) | 37 | int main(void) |
39 | { | 38 | { |
40 | - init_serial(250000); | 39 | + init_serial(19200); |
41 | port_initio(); | 40 | port_initio(); |
41 | + unsigned char ser; | ||
42 | uint8_t opto0 = 0; | 42 | uint8_t opto0 = 0; |
43 | - uint8_t opto2 = 0; | 43 | + uint8_t opto1 = 0; |
44 | + uint8_t once = 1; | ||
44 | 45 | ||
45 | while (1) | 46 | while (1) |
46 | { | 47 | { |
47 | if((opto0 == 1) && ((PIND & 0x40) == 0x40)) | 48 | if((opto0 == 1) && ((PIND & 0x40) == 0x40)) |
48 | - PORTD &= 0xE7; | 49 | + { |
50 | + if(once) | ||
51 | + { | ||
52 | + PORTD &= 0xE7; | ||
53 | + //_delay_ms(00000); | ||
54 | + //PORTD |= 0x18; | ||
55 | + //once = 0; | ||
56 | + } | ||
57 | + } | ||
49 | else | 58 | else |
59 | + { | ||
60 | + once = 1; | ||
50 | PORTD |= 0x18; | 61 | PORTD |= 0x18; |
51 | - if((opto2 == 1) && ((PIND & 0x80) == 0x80)) | 62 | + } |
63 | + if((opto1 == 1) && ((PIND & 0x80) == 0x80)) | ||
52 | PORTD &= 0xDB; | 64 | PORTD &= 0xDB; |
53 | else | 65 | else |
54 | PORTD |= 0x24; | 66 | PORTD |= 0x24; |
55 | 67 | ||
68 | + ser = get_serial(); | ||
69 | + if(ser == 'B') | ||
70 | + opto0 = 1; | ||
71 | + else if(ser == 'D') | ||
72 | + opto0 = 0; | ||
73 | + send_serial(ser); | ||
74 | +/* | ||
56 | if((PINB & 0x01) == 0x01) | 75 | if((PINB & 0x01) == 0x01) |
57 | - send_serial('U'); | 76 | + send_serial('1'); |
58 | else | 77 | else |
59 | - send_serial('D'); | 78 | + send_serial('0'); |
79 | + send_serial('\n'); | ||
80 | +*/ | ||
60 | } | 81 | } |
61 | 82 | ||
62 | return 0; | 83 | return 0; |