# HG changeset patch # User Matt Johnston # Date 1336926177 -28800 # Node ID ef64a178092fdc7c5e3cf7ee87bc2f366b5578b6 # Parent fc96a51bdce6e9c9b09650c85d70bf13d6d7f345 - Some basic ADC code - Turn on -mcall-prologues - Put strings in program space, saves RAM diff -r fc96a51bdce6 -r ef64a178092f Makefile --- a/Makefile Fri May 11 22:12:11 2012 +0800 +++ b/Makefile Mon May 14 00:22:57 2012 +0800 @@ -17,10 +17,11 @@ # default_serial = "avrdoper" # FUSES ........ Parameters for avrdude to flash the fuses appropriately. -DEVICE = atmega328 +DEVICE = atmega168 CLOCK = 1000000 PROGRAMMER = #-c stk500v2 -P avrdoper OBJECTS = main.o ff.o mmc.o onewire.o +LIBS = -lm FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m # ATMega8 fuse bits used above (fuse bits for other devices are different!): @@ -49,7 +50,7 @@ # Tune the lines below only if you know what you are doing: AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues # symbolic targets: all: main.hex @@ -85,7 +86,7 @@ # file targets: main.elf: $(OBJECTS) - $(COMPILE) -o main.elf $(OBJECTS) + $(COMPILE) -o main.elf $(OBJECTS) $(LIBS) main.hex: main.elf rm -f main.hex diff -r fc96a51bdce6 -r ef64a178092f main.c --- a/main.c Fri May 11 22:12:11 2012 +0800 +++ b/main.c Mon May 14 00:22:57 2012 +0800 @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "integer.h" @@ -28,12 +29,16 @@ #define BAUD 9600 #define UBRR ((F_CPU)/16/(BAUD)-1) +#define NUM_MEASUREMENTS 300 + static int uart_putchar(char c, FILE *stream); static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); static uint8_t n_measurements; -static uint8_t measurements[500]; +// stored as 1/5 degree above 0 +static uint8_t measurements[NUM_MEASUREMENTS]; +static uint8_t internal_measurements[NUM_MEASUREMENTS]; // boolean flags static uint8_t need_measurement; @@ -49,14 +54,27 @@ static void deep_sleep(); static void -uart_init(unsigned int ubrr) +uart_on(unsigned int ubrr) { // baud rate UBRR0H = (unsigned char)(ubrr >> 8); UBRR0L = (unsigned char)ubrr; - UCSR0B = (1<