Flip ADC bytes around
[fw/altos] / target / serial / serial.c
index 1050b9a63344c81479a4ecccb01b7392861d1c8d..2939042635ca84d48e0ea586d9fa6d518ea9d1cd 100644 (file)
@@ -156,6 +156,7 @@ delay (unsigned char n)
        unsigned char i = 0;
        unsigned char j = 0;
 
+       n++;
        while (--n != 0)
                while (--i != 0)
                        while (--j != 0)
@@ -206,7 +207,7 @@ usart_init(void)
                 UxUCR_D9_ODD_PARITY |
                 UxUCR_BIT9_8_BITS |
                 UxUCR_PARITY_DISABLE |
-                UxUCR_SPB_1_STOP_BIT |
+                UxUCR_SPB_2_STOP_BITS |
                 UxUCR_STOP_HIGH |
                 UxUCR_START_LOW);
 }
@@ -215,10 +216,20 @@ void
 usart_out_byte(uint8_t byte)
 {
        U1DBUF = byte;
-       while (!UTX1IF);
+       while (!UTX1IF)
+               ;
        UTX1IF = 0;
 }
 
+void
+usart_out_string(uint8_t *string)
+{
+       uint8_t b;
+
+       while (b = *string++)
+               usart_out_byte(b);
+}
+
 uint8_t
 usart_in_byte(void)
 {
@@ -230,27 +241,30 @@ usart_in_byte(void)
        return b;
 }
 
-#define spi_init()     usart_init()
-#define spi_out_byte(b)        usart_out_byte(b)
-#define spi_in_byte()  usart_in_byte()
+void
+debug_byte(uint8_t byte)
+{
+       uint8_t s;
 
-static char string[] = "hello world\r\n";
+       for (s = 0; s < 8; s++) {
+               DEBUG = byte & 1;
+               delay(5);
+               byte >>= 1;
+       }
+}
 
 main ()
 {
-       uint8_t i;
-
        P1DIR |= 2;
        CLKCON = 0;
        while (!(SLEEP & SLEEP_XOSC_STB))
                ;
        
-       spi_init();
+       usart_init();
 
        for (;;) {
-               for (i = 0; i < sizeof(string) - 1; i++)
-                       usart_out_byte(string[i]);
-               delay(5);
-               P1 ^= 2;
+               usart_out_string("hello world\r\n");
+               debug_byte(usart_in_byte());
        }
+       
 }