// []-------------------------------------------------------------------------[]
//      Copyright(c) 2005 Electronic Device Services
//      
//      transimtter.c
//
// []-------------------------------------------------------------------------[]

#include <avr/io.h>
#include <math.h>
#include <stdio.h>
#include "lcd.h" // final transmitter wont need this.
#include "usart.h"
#include "transmitter.h"

void delay(unsigned int p)
{
  unsigned int i;
  unsigned char j;
  for(i=0;i<p;i++)
    for (j=0;j<100;j++);
}

int main(void)
{
    unsigned char byte;
    int i;
    unsigned char mychar;
    unsigned char data;
    
    unsigned char fp_string[64];
    double fp_test;
/*    
    byte=0xAA;
    i=-22;                              // uf freezing...:)
    mychar=0xDF;                        // ASCII code for degree

    fp_test = 3.14159;
    
    lcd_init();
    lcd_control(1,0,0);
    //lcd_putstr(" WTH from AVR ");
    lcd_goto(0x40);                     // see addressing table on my AVR page
    //printf("GIMP=%d%cC %x",i,mychar,byte);
    
    // dtostrf
    // param1: the number (double)
    // param2: width (total)
    // param3: precision
    // param4: dest str
    
    while(1)
    {
      dtostrf( tan(1/cos(fp_test)), 16, 5, fp_string);
      lcd_home();
      lcd_putstr(fp_string);
      fp_test+=0.001;
    }
 */
 
    lcd_init();
    lcd_control(1,0,0);
    
    // serial test
    
    USART_Init( 6 ); //9600 at 1mhz
    
    mychar = 'a';
    
    while(1)
    {
    
        lcd_home();
        data = USART_Receive();
        data &= 0x7F;
        lcd_putch(data);
        
        // send
        //USART_Transmit( mychar );
        
        //if(mychar=='z'){mychar='a';}
        //else { mychar++; }
        
        //delay(10000);
    }   
    return 0;
}
