From e26a1dc73313098cef235918d237f9b1a6e4cb5f Mon Sep 17 00:00:00 2001 From: neoraider Date: Wed, 4 Apr 2007 12:08:03 +0000 Subject: Rescue: Weitere Grundfunktionen implementiert --- adc.c | 18 -------- adc.cpp | 18 ++++++++ avr.c | 16 ------- avr.cpp | 34 ++++++++++++++ avr.h | 3 ++ hardware.c | 6 --- hardware.cpp | 28 +++++++++++ i2c.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ i2c.h | 13 ++++++ main.cpp | 5 ++ 10 files changed, 249 insertions(+), 40 deletions(-) delete mode 100644 adc.c create mode 100644 adc.cpp delete mode 100644 avr.c create mode 100644 avr.cpp delete mode 100644 hardware.c create mode 100644 hardware.cpp create mode 100644 i2c.cpp create mode 100644 i2c.h create mode 100644 main.cpp diff --git a/adc.c b/adc.c deleted file mode 100644 index 192d36c..0000000 --- a/adc.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "adc.h" - -#include - - -void initADC() { - ADMUX = (1< + + +void initADC() { + ADMUX = (1< 0) { - *motor->port &= ~motor->revMask; - *motor->port |= motor->fwdMask; - } - else if(speed < 0) { - *motor->port &= ~motor->fwdMask; - *motor->port |= motor->revMask; - } - else *motor->port |= motor->fwdMask|motor->revMask; - - *motor->pwmPort = CLAMP(0, ABS(speed), 255); -} diff --git a/avr.cpp b/avr.cpp new file mode 100644 index 0000000..a5194a4 --- /dev/null +++ b/avr.cpp @@ -0,0 +1,34 @@ +#include "avr.h" +#include "adc.h" +#include "util.h" + +void setMotorSpeed(MOTOR *motor, int speed) { + if(speed > 0) { + *motor->port &= ~motor->revMask; + *motor->port |= motor->fwdMask; + } + else if(speed < 0) { + *motor->port &= ~motor->fwdMask; + *motor->port |= motor->revMask; + } + else *motor->port |= motor->fwdMask|motor->revMask; + + *motor->pwmPort = CLAMP(0, ABS(speed), 255); +} + +int getButton() { + uint16_t val = getADCValue(7); + + if(val < 144) return 5; + if(val < 228) return 4; + if(val < 304) return 3; + if(val < 376) return 2; + if(val < 600) return 1; + + return 0; +} + +void waitForButton(int i) { + while(getButton() != CLAMP(0, i, 5)); + while(getButton() != 0); +} diff --git a/avr.h b/avr.h index 3727bdf..2d13616 100644 --- a/avr.h +++ b/avr.h @@ -13,4 +13,7 @@ typedef struct { void setMotorSpeed(MOTOR *motor, int speed); +int getButton(); +void waitForButton(int i); + #endif diff --git a/hardware.c b/hardware.c deleted file mode 100644 index 6bc329e..0000000 --- a/hardware.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "hardware.h" - - -void initHardware() { - -} diff --git a/hardware.cpp b/hardware.cpp new file mode 100644 index 0000000..41c7ea2 --- /dev/null +++ b/hardware.cpp @@ -0,0 +1,28 @@ +#include "hardware.h" +#include "adc.h" +#include "i2c.h" + + +void initHardware() { + DDRA = 0x00; + PORTA = 0xFF; + + DDRB = 0xFF; + PORTB = 0x00; + + DDRC = 0x7C; + PORTC = 0x83; + + DDRD = 0xFF; + PORTC = 0x00; + + TCCR0 = 0x62; + TCCR1A = 0xA1; + TCCR1B = 0x82; + OCR0 = 0; + OCR1A = 0; + OCR1B = 0; + + initADC(); + initI2C(); +} diff --git a/i2c.cpp b/i2c.cpp new file mode 100644 index 0000000..61450fa --- /dev/null +++ b/i2c.cpp @@ -0,0 +1,148 @@ +#include "i2c.h" + +#include + + +static bool I2CStartSend(uint8_t addr); +static bool I2CStartRecv(uint8_t addr); +static void I2CStop(); + + +static bool I2CStartSend(uint8_t addr) { + TWCR = (1< + + +void initI2C(); +bool I2CSendByte(uint8_t addr, uint8_t data); +bool I2CSend(uint8_t addr, uint8_t *data, int length); +bool I2CRecvByte(uint8_t addr, uint8_t *data); +int I2CRecv(uint8_t addr, uint8_t *data, int length); + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..2a3f761 --- /dev/null +++ b/main.cpp @@ -0,0 +1,5 @@ +int main() { + + + return 0; +} -- cgit v1.2.3