From: Jan Michel Date: Mon, 3 Aug 2015 16:20:04 +0000 (+0200) Subject: first version of pt100 X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=487f5af7dd80dda00ae1a1ea756393a7c64bdf33;p=avr.git first version of pt100 --- diff --git a/.gitignore b/.gitignore index bad5cf9..884d762 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ *.o *.d .kateproject.d +*lss +*.font +LICENSE diff --git a/pt100/Makefile b/pt100/Makefile index 143fc01..61201f8 100644 --- a/pt100/Makefile +++ b/pt100/Makefile @@ -5,12 +5,16 @@ # (GNU make, BSD make, SysV make) -MCU = attiny441 +MCU = atmega1284p FORMAT = ihex -TARGET = PowerSwitch -SRC = $(TARGET).c +TARGET = main +SRC = $(TARGET).c lcdlib/lcd-color-graphic.c lcdlib/font.c \ + lcdlib/Fonts/digits_24px.c lcdlib/Fonts/digits_32px.c lcdlib/Fonts/font_proportional_16px.c \ + lcdlib/Fonts/font_proportional_8px.c lcdlib/Fonts/symbols_16px.c ASRC = -OPT = s +OPT = 2 + +#usb/usb_serial.c 1wire.c # Name of this Makefile (used for "make depend"). MAKEFILE = Makefile @@ -28,17 +32,17 @@ DEBUG = stabs CSTANDARD = -std=gnu99 # Place -D or -U options here -CDEFS = +CDEFS = -DF_CPU=8000000UL # Place -I options here -CINCS = +CINCS = CDEBUG = -g$(DEBUG) -CWARN = -Wall -Wstrict-prototypes -CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums +CWARN = -Wall -Wstrict-prototypes +CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wl,--relax #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) -CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) +CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CTUNING) #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs @@ -82,7 +86,7 @@ LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) # Programming support using avrdude. Settings and variables. -AVRDUDE_PROGRAMMER = usbtiny +AVRDUDE_PROGRAMMER = dragon_jtag AVRDUDE_PORT = usb AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex @@ -96,7 +100,7 @@ AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex # Uncomment the following if you do /not/ wish a verification to be # performed after programming the device. -#AVRDUDE_NO_VERIFY = -V +AVRDUDE_NO_VERIFY = -V # Increase verbosity level. Please use this when submitting bug # reports about avrdude. See @@ -131,7 +135,7 @@ ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) # Default target. all: build -build: elf hex eep +build: elf hex eep lss elf: $(TARGET).elf hex: $(TARGET).hex @@ -145,8 +149,9 @@ program: $(TARGET).hex $(TARGET).eep $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) - - +size: + $(SIZE) $(TARGET).elf +#-C --mcu=$(MCU) # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. COFFCONVERT=$(OBJCOPY) --debugging \ --change-section-address .data-0x800000 \ @@ -220,4 +225,10 @@ depend: >> $(MAKEFILE); \ $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) -.PHONY: all build elf hex eep lss sym program coff extcoff clean depend +.PHONY: all build elf hex eep lss sym program coff extcoff clean depend program_bootloader program_arduino + +program_bootloader: all + dfu-programmer $(MCU) erase && dfu-programmer $(MCU) flash $(TARGET).hex && dfu-programmer $(MCU) start + +program_arduino: all + avrdude -patmega32u4 -cavr109 -P$(PORT) -b57600 -D -Uflash:w:$(TARGET).hex:i diff --git a/pt100/main.c b/pt100/main.c index 6079184..9255381 100644 --- a/pt100/main.c +++ b/pt100/main.c @@ -1,4 +1,4 @@ -#define F_CPU 8000000UL + #include #include @@ -6,15 +6,59 @@ #include #include -#define FIRMWARE_VERSION 0x01 +#include "main.h" +#include "lcdlib/lcd-color-graphic.h" +#include "lcdlib/font.h" + + +/****************** + * Init USART for LCD + *****************/ +void init_spi_lcd(void) { + UCSR1B = (1 << TXEN1); + UCSR1C = (1 << UMSEL10) | (0 << UDORD1) | (0 << UCPHA1) | (0 << UCPOL1); + UBRR1L = 0; + UBRR1H = 0; +} + + +/****************** + * Init all functions + *****************/ void init(void) { + +//Init ADC SPI + SPCR = (0 << SPIE) | (1 << SPE ) | (0 << DORD) | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (0 << SPR0); + SPSR = (1 << SPI2X); //fcpu/8 + DDRB |= (1 << PB7) | (1 << PB5) | (1 << PB4); //ADC has three control lines + +//Init ADC for presence measurement + ADMUX = (3 << REFS0) | (1 << ADLAR) | (3 << MUX0); + ADCSRA = (1 << ADEN) | (0 << ADIE) | (5 << ADPS0); //fcpu/32 + DIDR0 = 0x08; //PA3 is analog only + +//Init UART + + +//GPIO + PORTD |= (0xc0); //pull-up for switches + PORTA |= (0x07); //spare I/O have pull-up + + DDRB |= (0x03); //LED are output + DDRA |= (0x70); //select outputs + DDRC |= (0xc0); //outputs for Inhibit signals + + } -void main(void) { +int main(void) { + init(); + lcd_init(); while(1); + return 0; } \ No newline at end of file diff --git a/pt100/main.h b/pt100/main.h index e69de29..ce68998 100644 --- a/pt100/main.h +++ b/pt100/main.h @@ -0,0 +1,24 @@ + + +#define FIRMWARE_VERSION 0x01 + +#define UDORD1 2 +#define UCPHA1 1 + +#define ADC_SELECT() PORTB &= ~(1<< PB4) +#define ADC_UNSELECT() PORTB |= (1<< PB4) + +#define LED1_ON() PORTB |= (1<< PB1) +#define LED1_OFF() PORTB &= ~(1<< PB1) +#define LED2_ON() PORTB |= (1<< PB0) +#define LED2_OFF() PORTB &= ~(1<< PB0) + +#define SWITCH1() ((PIND>>PD6)&1) +#define SWITCH2() ((PIND>>PD7)&1) + +#define SELECT(i) (PORTA = (PORTA & 0x8F) | (((i)&0x7) << 4) + +#define MUX_C_ON() PORTC &= ~(1<