/*************************************************************************** * Copyright (C) 09/2007 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License, * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #define F_CPU 8000000 #include #include #define BAUDRATE 19200 #define UART_CALC_BAUDRATE(baudRate) ((uint32_t)(F_CPU) / ((uint32_t)(baudRate)*16) -1) /* * LCD: * - CS Chip Select * - RS Register Select * - RW Read/Write */ #define RS PORTB6 #define CS PORTB7 #define RW PORTD3 #define LCD_D4 PORTD4 #define LCD_D5 PORTD5 #define LCD_D6 PORTD6 #define LCD_D7 PORTD7 #define LCD_DATA_MASK ((1< 2V; 15mV -> 2.5mV/bit) * - CH1 - current with (1A -> 1000mV; 2.5mA -> 2.5mV/bit) * - PWM - high-active output to buckconverter */ #define CH0 PORTC0 #define CH1 PORTC1 #define SUMMER PORTB0 #define PWM PORTB1 #define NOP asm volatile ("nop") #define MOD_WAITING 0x00 #define MOD_CHARGING 0x01 #define MOD_READY 0x02 #define VOLTAGE_CONNECT 9000 #define VOLTAGE_CHARGE 12450 #define CURRENT_CHARGE 17500 #define CURRENT_READY 2000 #define VOLTAGE_REMOVE 1000 static void lcd_wait_busy(void) { uint8_t status; DDRD &= ~(LCD_DATA_MASK); PORTD |= (1<> 4); PORTB &= ~(1< VOLTAGE_CHARGE || current > CURRENT_CHARGE) if (pwm > 0x00) pwm--; OCR1A = pwm; TCCR1A |= (1< 9V is detected (lipo connected) */ if (voltage > VOLTAGE_CONNECT) mode = MOD_CHARGING; break; case MOD_CHARGING: /* end charging if voltage > 12.45V and current < 200mA */ if (voltage >= VOLTAGE_CHARGE && current < CURRENT_READY) mode = MOD_READY; break; case MOD_READY: /* wait for lipo disconnect */ if (voltage < VOLTAGE_REMOVE) mode = MOD_WAITING; break; } } int main(void) { DDRB = (1<>8) & 0xFF; UBRRL = (UART_CALC_BAUDRATE(BAUDRATE) & 0xFF); /* USART: rx/tx enable, 19200, 8n1 */ UCSRB = (1<