From 9177693c7a201e70743d7ab786c4053abe1fcb84 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 30 Jan 2014 14:36:28 +0100 Subject: Unix line endings --- main.c | 714 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 355 insertions(+), 359 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index e5a1056..a747b31 100644 --- a/main.c +++ b/main.c @@ -1,359 +1,355 @@ -/* cpu freq */ -#define F_CPU 1000000 - -#include -#include -#include - -/* cpu runs at 1mhz */ - -/* i2c device addresses */ -#define L2GD20 0b11010100 -#define L2GD20_WHOAMI 0xf -#define L2GD20_CTRLREG1 0x20 -#define LIS302DL 0b00111000 -#define LIS302DL_WHOAMI 0xf - -/* i2c constants */ -#define TW_READ 1 -#define TW_WRITE 0 -#define TW_STATUS (TWSR & 0xF8) - -void twStart () { - /* disable stop, reset twint, enable start, enable i2c */ - TWCR = (TWCR & ~(1 << TWSTO)) | (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); -} - -void twStop () { - /* disable start, reset twint, enable stop, enable i2c */ - TWCR = (TWCR & ~(1 << TWSTA)) | (1 << TWINT) | (1 << TWSTO) | (1 << TWEN); -} - -void twFlush () { - /* disable start/stop, reset twint, enable i2c */ - TWCR = (TWCR & ~((1 << TWSTA) | (1 << TWSTO))) | (1 << TWINT) | (1 << TWEN); -} - -void twWait () { - while (!(TWCR & (1 << TWINT))); -} - -void twInit () { - /* set scl to 3.6 kHz (at 1Mhz CPU speed)*/ - TWBR = 2; - TWSR |= 0x3; /* set prescaler to 64 */ -} - -void ledInit () { - /* set led1,led2 to output */ - DDRB |= (1 << PB6) | (1 << PB7); - /* set led3,led4,led5,led6 to output */ - DDRD |= (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5); -} - -/* show data with leds */ -void ledShow (unsigned char val) { - PORTB = (PORTB & ~((1 << PB6) | (1 << PB7))) | ((val & 0x3) << PB6); - PORTD = (PORTD & ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5))) | (((val >> 2) & 0xf) << PD2); -} - -void uartInit () { - /* Set baud rate (9600, double speed, at 1mhz) */ - UBRR0H = 0; - UBRR0L = 12; - /* enable double speed mode */ - UCSR0A = (1 << U2X0); - /* Enable receiver and transmitter */ - UCSR0B = (1< +#include +#include +#include + +/* cpu runs at 1mhz */ + +/* i2c device addresses */ +#define L3GD20 0b11010100 +#define L3GD20_WHOAMI 0xf +#define L3GD20_CTRLREG1 0x20 +#define LIS302DL 0b00111000 +#define LIS302DL_WHOAMI 0xf + +void twStart () { + /* disable stop, reset twint, enable start, enable i2c */ + TWCR = (TWCR & ~(1 << TWSTO)) | (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); +} + +void twStop () { + /* disable start, reset twint, enable stop, enable i2c */ + TWCR = (TWCR & ~(1 << TWSTA)) | (1 << TWINT) | (1 << TWSTO) | (1 << TWEN); +} + +void twFlush () { + /* disable start/stop, reset twint, enable i2c */ + TWCR = (TWCR & ~((1 << TWSTA) | (1 << TWSTO))) | (1 << TWINT) | (1 << TWEN); +} + +void twWait () { + while (!(TWCR & (1 << TWINT))); +} + +void twInit () { + /* set scl to 3.6 kHz (at 1Mhz CPU speed)*/ + TWBR = 2; + TWSR |= 0x3; /* set prescaler to 64 */ +} + +void ledInit () { + /* set led1,led2 to output */ + DDRB |= (1 << PB6) | (1 << PB7); + /* set led3,led4,led5,led6 to output */ + DDRD |= (1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5); +} + +/* show data with leds */ +void ledShow (unsigned char val) { + PORTB = (PORTB & ~((1 << PB6) | (1 << PB7))) | ((val & 0x3) << PB6); + PORTD = (PORTD & ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5))) | (((val >> 2) & 0xf) << PD2); +} + +void uartInit () { + /* Set baud rate (9600, double speed, at 1mhz) */ + UBRR0H = 0; + UBRR0L = 12; + /* enable double speed mode */ + UCSR0A = (1 << U2X0); + /* Enable receiver and transmitter */ + UCSR0B = (1<