diff options
Diffstat (limited to 'rf_test')
| -rw-r--r-- | rf_test/Recv.Makefile | 2 | ||||
| -rw-r--r-- | rf_test/Send.Makefile | 2 | ||||
| -rw-r--r-- | rf_test/recv.c | 62 | ||||
| -rw-r--r-- | rf_test/send.c | 47 |
4 files changed, 42 insertions, 71 deletions
diff --git a/rf_test/Recv.Makefile b/rf_test/Recv.Makefile index 02c0b34..c7b98a7 100644 --- a/rf_test/Recv.Makefile +++ b/rf_test/Recv.Makefile @@ -9,7 +9,7 @@ CFLAGS = -std=gnu99 CFLAGS += -Os CFLAGS += -Wall CFLAGS += -mmcu=$(MCU) -CFLAGS += -DBAUD=9600 +CFLAGS += -DBAUD=4800 CFLAGS += -DF_CPU=16000000UL CFLAGS += -ffunction-sections -fdata-sections diff --git a/rf_test/Send.Makefile b/rf_test/Send.Makefile index a6bb6f0..e7d3e79 100644 --- a/rf_test/Send.Makefile +++ b/rf_test/Send.Makefile @@ -9,7 +9,7 @@ CFLAGS = -std=gnu99 CFLAGS += -Os CFLAGS += -Wall CFLAGS += -mmcu=$(MCU) -CFLAGS += -DBAUD=9600 +CFLAGS += -DBAUD=4800 CFLAGS += -DF_CPU=16000000UL CFLAGS += -ffunction-sections -fdata-sections diff --git a/rf_test/recv.c b/rf_test/recv.c index 02fab41..a908bbe 100644 --- a/rf_test/recv.c +++ b/rf_test/recv.c @@ -7,10 +7,10 @@ #define LOCK_LED PD6 #define UNLOCK_LED PD7 -#define SYN 0xA4 -#define ADDR 0x44 -#define LOCK_CMD 0x11 -#define UNLOCK_CMD 0x22 +#define SYN 0xA1 +#define FIN 0xB2 +#define LOCK 0xC3 +#define UNLOCK 0xD3 static void usart_init(void) { @@ -30,6 +30,7 @@ static void led_init(void) { DDRB |= (1 << TEST_LED); DDRD |= (1 << LOCK_LED) | (1 << UNLOCK_LED); + PORTD |= (1 << LOCK_LED) | (1 << UNLOCK_LED); } int main(void) @@ -45,38 +46,35 @@ int main(void) return 0; } -static inline int is_btn_pressed(unsigned char btn) +ISR(USART_RX_vect) { - if (!((PIND >> btn) & 0x01)) { - _delay_us(2000); - return !((PIND >> btn) & 0x01); - } + unsigned char data, buf; + + data = 0; + buf = usart_recv(); - return 0; -} + if (buf == SYN) { + buf = usart_recv(); -ISR(USART_RX_vect) -{ - unsigned char syn, addr, data, chk; - - syn = usart_recv(); - addr = usart_recv(); - data = usart_recv(); - chk = usart_recv(); - - if(chk == (addr + data)) - { - if(addr == ADDR) - { - if(data == LOCK_CMD) { - PORTD |= (1 << LOCK_LED); - PORTD &= ~(1 << UNLOCK_LED); - - } else if (data == UNLOCK_LED) { - PORTD |= (1 << UNLOCK_LED); - PORTD &= ~(1 << LOCK_LED); + while (buf != FIN) { + buf = usart_recv(); + + if (buf == SYN) { + PORTB ^= (1 << TEST_LED); + return; } + + if (buf != FIN) + data = buf; + } + + if(data == LOCK) { + PORTD |= (1 << LOCK_LED); + PORTD &= ~(1 << UNLOCK_LED); + } else if (data == UNLOCK) { + PORTD |= (1 << UNLOCK_LED); + PORTD &= ~(1 << LOCK_LED); } - PORTB ^= (1 << TEST_LED); } + } diff --git a/rf_test/send.c b/rf_test/send.c index 0a12692..de69818 100644 --- a/rf_test/send.c +++ b/rf_test/send.c @@ -7,10 +7,10 @@ #define LOCK_BTN PD6 #define UNLOCK_BTN PD7 -#define SYN 0xA4 -#define ADDR 0x44 -#define LOCK_CMD 0x11 -#define UNLOCK_CMD 0x22 +#define SYN 0xA1 +#define FIN 0xB2 +#define LOCK 0xC3 +#define UNLOCK 0xD3 static void usart_init(void) { @@ -35,22 +35,20 @@ static inline void pcint2_init(void) static inline void lock(void) { - PORTB ^= (1 << LOCK_LED); + PORTB |= (1 << LOCK_LED); usart_send(SYN); - usart_send(ADDR); - usart_send(LOCK_CMD); - usart_send(LOCK_CMD + ADDR); + usart_send(LOCK); + usart_send(FIN); } static inline void unlock(void) { - PORTB ^= (1 << LOCK_LED); + PORTB &= ~(1 << LOCK_LED); usart_send(SYN); - usart_send(ADDR); - usart_send(UNLOCK_CMD); - usart_send(UNLOCK_CMD + ADDR); + usart_send(UNLOCK); + usart_send(FIN); } int main(void) @@ -59,9 +57,6 @@ int main(void) PORTB |= (1 << LOCK_LED); usart_init(); - //pcint2_init(); - - //sei(); for (;;) { _delay_ms(4000); @@ -73,25 +68,3 @@ int main(void) return 0; } -static inline int is_btn_pressed(unsigned char btn) -{ - if (!((PIND >> btn) & 0x01)) { - _delay_us(2000); - return !((PIND >> btn) & 0x01); - } - - return 0; -} - -ISR(PCINT2_vect) -{ - if (is_btn_pressed(LOCK_BTN)) { - PORTB ^= (1 << LOCK_LED); - //lock(); - } - - if (is_btn_pressed(UNLOCK_BTN)) { - PORTB ^= (1 << LOCK_LED); - //unlock(); - } -} |
