Main Page | File List | Globals

stationu.c

00001 //
00002 // C Implementation: stationu
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: Leonhard Klein <leoklein@gmx.net>, (C) 2004
00008 
00009 #include "stationu.h"
00010 
00011 volatile u08 lastkey;
00012 
00013 SIGNAL(SIG_UART_RECV)      /* signal handler for receive complete interrupt */
00014 {  lastkey = UDR;
00015 }
00016 
00017 void uart_send(u08 *buf) {
00018   u08 i=0;
00019   while ((buf[i])|(i>250)) {
00020 #ifndef TEST
00021     while (!(UCSRA & _BV(UDRE))) ;
00022 #endif
00023     UDR = buf[i++];
00024   }
00025 }
00026 void uart_send_pascal(u08 *buf) {
00027   buf[buf[0]+1]=0;
00028   uart_send(buf+1);
00029 }
00030 void uart_send_char(u08 val) {
00031 #ifndef TEST
00032   while (!(UCSRA & _BV(UDRE))) ;
00033 #endif
00034   UDR = val;
00035 }
00036 
00037 void uart_send_p(u08 buf[]) {
00038   u08 i=0;
00039   u08 ch; 
00040   while ((ch = pgm_read_byte_near(buf+(i++)))|(i>250)) {
00041 #ifndef TEST    
00042     while (!(UCSRA & _BV(UDRE))) ;
00043 #endif
00044     UDR = ch;
00045   }
00046 }
00047 
00048 void uart_send_int(s16 int1, u08 radix) {
00049   u08 *intstr = "\0\0\0\0\0\0\0\0";
00050   itoa(int1, intstr, radix);
00051   if ((radix==16)&(int1<16))
00052     uart_send("0");
00053   uart_send(intstr);
00054   uart_send(" ");
00055 }
00056 
00057 void initchip() {
00058   DDRB = _BV(DDB0) | _BV(DDB1) | _BV(DDB4);
00059   PORTC = _BV(PC4) | _BV(PC3);                        /* Pull-Up's for dip-switch */
00060   DDRD = _BV(DD7);
00061   UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXEN);          /* enable RxD/TxD and ints */
00062   UBRRL = (u08)UART_BAUD_SELECT;                       /* set baud rate */
00063 
00064   TCCR1A= _BV(COM1A1)|_BV(COM1B1)|_BV(WGM10);          /* PWM 8bit*/
00065   TCCR1B= _BV(CS01);                                   /*  /1 => 16kHz */
00066   TCNT1 = 0;
00067   OCR1A = 255;
00068 
00069   TIMSK = _BV(TOIE0);
00070   TCNT0 = 0;
00071   TCCR0 = _BV(CS01);                                  /* Clock / 8 intervall is 4m/256*8~=2k */
00072 }
00073 
00074 void start_ad(enum admodtype adm) {
00075   if (admodus == none) {
00076     admodus = adm;
00077     if (adm == vcc)
00078       ADMUX = _BV(REFS0) + 2;                     /* voltage of accu */
00079     if (adm == vout)
00080       ADMUX = _BV(REFS0) + 1;                     /* Output voltage for current measure */
00081     ADCSRA = _BV(ADEN)|_BV(ADSC)|_BV(ADIE) + 3;   /* enable single mode */
00082   } else
00083     uart_send("AD-ERROR\n\r\0");
00084 }
00085 
00086 SIGNAL(SIG_ADC) {
00087   if (admodus == vcc)
00088     vcc_value = ADC;
00089   if (admodus == vout)
00090     vout_value = ADC;
00091   ADCSRA = 0;                                         /* disable AD-Converter */
00092   admodus = none;
00093 }
00094 void itoa16(u08 val, u08 *buf) {
00095   u08 i1, i2;
00096   i1 = (val >> 4);
00097   i2 = (val & 0x0f);
00098   if (i1 > 9) i1 += 7;
00099   if (i2 > 9) i2 += 7;
00100   buf[0] = i1+'0';
00101   buf[1] = i2+'0';
00102 }

Generated on Wed Feb 2 21:19:12 2005 for Station by doxygen 1.3.6