From ebba9c2a59d773a59be28b4fe465fd52d597d901 Mon Sep 17 00:00:00 2001 From: bigalex Date: Mon, 1 Oct 2012 21:39:25 +0200 Subject: [PATCH] usart works, timer works --- firmware/lib/bughal.c | 2 ++ firmware/lib/usart.c | 19 +++---------------- firmware/main.c | 37 +++++++++++++++++++++++++++++++++---- fw_test/main.c | 1 + 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/firmware/lib/bughal.c b/firmware/lib/bughal.c index c08005f..89fd73b 100644 --- a/firmware/lib/bughal.c +++ b/firmware/lib/bughal.c @@ -65,6 +65,8 @@ void buzzr_inv(void){ } void init_switch(void){ + DDRD &= ~( (1 << PORTD1) | (1< 100)&&(xon==0)) -// { -// xon=1; -// //set the CTS pin -// } + } UCSR0B |= (1 << RXCIE0); } @@ -62,8 +58,8 @@ void USART0_Init (void) { // set baudrate #define BAUD_TOL 4 - #undef BAUD - #define BAUD 115200 + #undef BAUD + #define BAUD 115200 #include UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; @@ -94,7 +90,6 @@ void USART0_Init (void) void USART0_putc (char c) { - loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = c; } @@ -105,14 +100,6 @@ uint8_t USART0_Getc_nb(uint8_t *c) if (rxhead0==rxtail0) return 0; *c = *rxtail0; if (++rxtail0 == (rxbuf0 + UART_RXBUFSIZE)) rxtail0 = rxbuf0; - -// uint8_t diff = rxhead0 - rxtail0; -// if((diff < 10)&&(xon==1)) -// { -// xon=0; -// //set the CTS pin -// } - return 1; } diff --git a/firmware/main.c b/firmware/main.c index dcfe79e..f83e457 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,6 +1,7 @@ #include #include #include +#define __DELAY_BACKWARD_COMPATIBLE__ #include #include @@ -8,6 +9,7 @@ #include "lib/synth.h" #include "lib/usart.h" #include "lib/bughal.h" +#include "lib/util.h" @@ -17,18 +19,45 @@ main(void) /* hardware initialisation: */ init_leds(); init_buzzr(); - //USART0_Init(); - // init_motor(); + init_switch(); + USART0_Init(); + init_motor(); + /* software initialisation */ + timer_init(); /* here the show begins:*/ - //sei(); + sei(); //set_motor(MOTOR_ON); + timer_t t; + uint8_t ledmode =0; + uint16_t ct =0; + led_on(LED_R); + timer_set(&t, 100); for(;;) /* ever */ { //do something - //synth_poll(); + //main polling loop; + if (timer_expired(&t)){ + if (0==ledmode){ + ledmode =1; + led_on(LED_L); + + } else { + + ledmode=0; + led_off(LED_L); + + }; + timer_set(&t, 1); + USART0_crlf(); + USART0_put_uint16(ct); + ct++; + }; //end if timer expired + //USART0_put_uint16(0xA09F); //USART0_crlf(); + + } /* never return 0; */ diff --git a/fw_test/main.c b/fw_test/main.c index 5b3f951..e3ea38a 100644 --- a/fw_test/main.c +++ b/fw_test/main.c @@ -1,6 +1,7 @@ #include #include #include +#define __DELAY_BACKWARD_COMPATIBLE__ #include #include