diff options
| -rw-r--r-- | fpm.c (renamed from fpm10a.c) | 26 | ||||
| -rw-r--r-- | fpm.h (renamed from fpm10a.h) | 0 | ||||
| -rw-r--r-- | main.c | 51 | ||||
| -rw-r--r-- | r503.c | 22 | ||||
| -rw-r--r-- | r503.h | 6 |
5 files changed, 69 insertions, 36 deletions
@@ -127,22 +127,6 @@ static inline uint8_t check_pwd(void) return buf[0] == OK; } -static inline void uint8_t aura_on(void) -{ - unsigned int n; - uint8_t buf[MAXPDLEN]; - - buf[0] = 0x35; - buf[1] = 0x01; - buf[2] = 0x00; - buf[3] = 0x01; - buf[4] = 0x00; - - send(0x01, buf, 5); - recv(buf, &n); - return buf[0] == OK; -} - uint8_t fpm_init(void) { UBRR0H = UBRRH_VALUE; @@ -156,7 +140,15 @@ uint8_t fpm_init(void) UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); _delay_ms(RST_DELAY_MS); - aura_on(); + + uint8_t buf[5]; + buf[0] = 0x35; + buf[1] = 0x03; + buf[2] = 0x00; + buf[3] = 0x01; + buf[4] = 0x00; + send(0x01, buf, 5); + return check_pwd(); } @@ -1,26 +1,51 @@ +/* + * example_usage.c + * + */ + +#define bit_clr(a,b) ((a) &=~(1<<(b))) +#define bit_set(a,b) ((a) |= (1<<(b))) +#define bit_tst(a,b) ((a) & (1<<(b))) +#define bit_change(a,b) ((a) ^= (1<<(b))) + +#include <stdio.h> + +#include <avr/io.h> +#include <avr/interrupt.h> #include <util/delay.h> +#define Soft_UART_TX_PORT PORTD +#define Soft_UART_TX_DDR DDRD +#define Soft_UART_TX_PIN 3 +#define Soft_UART_Baud 9600 +#include "Soft_UART_Timer1.h" + #include "r503.h" +static inline void uart_write(const char *s) +{ + for (; *s; s++) { + Soft_UART_send_byte(*s); + } + Soft_UART_send_byte('\r'); + Soft_UART_send_byte('\n'); +} + int main(void) { + cli(); + Soft_UART_init(); + bit_set(DDRB,5); + sei(); + fpm_init(); + if (fpm_clear_db()) + fpm_led_on(PURPLE); - for (;;) + while (1) { - fpm_led_on(RED); - _delay_ms(500); - fpm_led_off(); - _delay_ms(500); - fpm_led_on(BLUE); - _delay_ms(500); - fpm_led_off(); - _delay_ms(500); - fpm_led_on(PURPLE); - _delay_ms(500); - fpm_led_off(); - _delay_ms(500); } return 0; } + @@ -126,9 +126,10 @@ static inline uint8_t check_pwd(void) return buf[0] == OK; } -void fpm_led_on(FPM_LED_COLOR color) +void fpm_led_on(COLOR color) { - uint8_t buf[5]; + uint16_t n; + uint8_t buf[MAXPDLEN]; buf[0] = 0x35; buf[1] = 0x03; @@ -137,11 +138,13 @@ void fpm_led_on(FPM_LED_COLOR color) buf[4] = 0x00; send(0x01, buf, 5); + recv(buf, &n); } void fpm_led_off(void) { - uint8_t buf[5]; + uint16_t n; + uint8_t buf[MAXPDLEN]; buf[0] = 0x35; buf[1] = 0x04; @@ -150,6 +153,7 @@ void fpm_led_off(void) buf[4] = 0x00; send(0x01, buf, 5); + recv(buf, &n); } uint8_t fpm_init(void) @@ -165,6 +169,16 @@ uint8_t fpm_init(void) UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); _delay_ms(RST_DELAY_MS); - return 1; + return check_pwd(); } +uint8_t fpm_clear_db(void) +{ + uint16_t n; + uint8_t buf[MAXPDLEN]; + + buf[0] = 0x0D; + send(0x01, buf, 1); + recv(buf, &n); + return buf[0] == OK; +} @@ -7,12 +7,14 @@ typedef enum { RED = 0x01, BLUE = 0x02, PURPLE = 0x03 -} FPM_LED_COLOR; +} COLOR; uint8_t fpm_init(void); -void fpm_led_on(FPM_LED_COLOR color); +void fpm_led_on(COLOR color); void fpm_led_off(void); +uint8_t fpm_clear_db(void); + #endif /* FPM_R50_H */ |
