commit af88cd9d1a9eca2b49d8ed4330924be04f814143 Author: Steffen Vogel Date: Sat Jan 4 19:36:07 2014 +0100 added sourcecode diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..cc4100d --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +*.bin +*.hex +*.o diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..7daa8f3 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,441 @@ +# Hey Emacs, this is a -*- makefile -*- +#---------------------------------------------------------------------------- +# avr-gcc Makefile +# +# by Steffen Vogel +# +# Released to the Public Domain - Credits to: +# Eric B. Weddington, Jörg Wunsch, Peter Fleury, Tim Henigan Colin O'Flynn, +# Reiner Patommel, Markus Pfaff, Sander Pool, Frederik Rouleau, Carlos Lamas +#---------------------------------------------------------------------------- +# On command line: +# +# make all = Make software +# +# make clean = Clean out built project files +# +# make program = Download the hex file to the device, using avrdude +# Please customize the avrdude settings below first! +# +# make filename.s = Just compile filename.c into the assembler code only +# +# make filename.i = Create a preprocessed source file for use in submitting +# bug reports to the GCC project. +# +# To rebuild project do "make clean" then "make all". +#---------------------------------------------------------------------------- + +#------------------------------ General Options ----------------------------- +# MCU name +MCU = atmega8 +#MCU = atmega328p + +# Processor frequency +# This will define a symbol, F_CPU, in all source code files equal to the +# processor frequency. You can then use this symbol in your source code to +# calculate timings. Do NOT tack on a 'UL' at the end, this will be done +# automatically to create a 32-bit value in your source code. +# Typical values are: +#F_CPU = 1000000 +#F_CPU = 1843200 +#F_CPU = 2000000 +#F_CPU = 3686400 +#F_CPU = 4000000 +#F_CPU = 7372800 +#F_CPU = 8000000 +#F_CPU = 11059200 +#F_CPU = 14745600 +F_CPU = 8000000 +#F_CPU = 18432000 +#F_CPU = 20000000 + +# Output format +#FORMAT = srec +#FORMAT = binary +FORMAT = ihex + +# Target file name (without extension) +TARGET = main + +# Object files directory +OBJDIR = obj + +# List C source files here (C dependencies are automatically generated) +SRC = $(TARGET).c ds1820.c + +# List C++ source files here (C dependencies are automatically generated) +CPPSRC = + +# List Assembler source files here +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# are about how the name is spelled on its command-line. +ASRC = + +# Optimization level, can be [0, 1, 2, 3, ..., s] +# 0 = turn off optimization +# s = optimize for size +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) +OPT = s + +# Debugging format +# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. +# AVR Studio 4.10 requires dwarf-2. +# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. +DEBUG = dwarf-2 + +# List any extra directories to look for include files here. +# Each directory must be seperated by a space. +# Use forward slashes for directory separators. +# For a directory that has spaces, enclose it in quotes. +EXTRAINCDIRS = + +# Compiler flag to set the C Standard level +# c89 = "ANSI" C +# gnu89 = c89 plus GCC extensions +# c99 = ISO C99 standard (not yet fully implemented) +# gnu99 = c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +# Place -D or -U options here for C sources +CDEFS = -DF_CPU=$(F_CPU)UL + +# Place -D or -U options here for C++ sources +#CPPDEFS += -D__STDC_LIMIT_MACROS +#CPPDEFS += -D__STDC_CONSTANT_MACROS +CPPDEFS = -DF_CPU=$(F_CPU)UL + +#------------------------------ Compiler Options ----------------------------- +# C Compiler Options +# -g generate debugging information +# -O optimization level +# -f tuning, see GCC manual and avr-libc documentation +# -Wall warning level +# -Wa tell GCC to pass this to the assembler. +# -adhlns create assembler listing +#CFLAGS = -g$(DEBUG) +#CFLAGS += -mint8 +#CFLAGS += -mshort-calls +#CFLAGS += -Wunreachable-code +#CFLAGS += -Wsign-compare +CFLAGS += -Wall +CFLAGS += -Wstrict-prototypes +CFLAGS += -Wundef +#CFLAGS += -fno-unit-at-a-time +CFLAGS += -funsigned-char +CFLAGS += -funsigned-bitfields +CFLAGS += -fpack-struct +CFLAGS += -fshort-enums +CFLAGS += $(CDEFS) +CFLAGS += -O$(OPT) +CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst) +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) +CFLAGS += $(CSTANDARD) + +# C++ Compiler Options +# -g generate debugging information +# -O optimization level +# -f tuning, see GCC manual and avr-libc documentation +# -Wall warning level +# -Wa tell GCC to pass this to the assembler. +# -adhlns create assembler listing +#CPPFLAGS = -g$(DEBUG) +#CPPFLAGS += -mint8 +#CPPFLAGS += -mshort-calls +#CPPFLAGS += $(CSTANDARD) +#CPPFLAGS += -Wstrict-prototypes +#CPPFLAGS += -Wunreachable-code +#CPPFLAGS += -Wsign-compare +CPPFLAGS += -Wall +CFLAGS += -Wundef +#CPPFLAGS += -fno-unit-at-a-time +CPPFLAGS += -funsigned-char +CPPFLAGS += -funsigned-bitfields +CPPFLAGS += -fpack-struct +CPPFLAGS += -fshort-enums +CPPFLAGS += -fno-exceptions +CPPFLAGS += $(CPPDEFS) +CPPFLAGS += -O$(OPT) +CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst) +CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) + +# Assembler Options +# -Wa tell GCC to pass this to the assembler. +# -adhlms create listing +# -gstabs have the assembler create line number information; +# note that for use in COFF files, additional information +# about filenames and function names needs to be present +# in the assembler source files +ASFLAGS = -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs + + +#------------------------------ Library Options ------------------------------ +# Minimalistic printf version +PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min + +# Floating point printf version (requires MATH_LIB = -lm below) +PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt + +# If this is left blank, then it will use the Standard printf version. +#PRINTF_LIB = $(PRINTF_LIB_MIN) +PRINTF_LIB = $(PRINTF_LIB_FLOAT) +#PRINTF_LIB = + +# Minimalistic scanf version +SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min + +# Floating point + %[ scanf version (requires MATH_LIB = -lm below) +SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt + +# If this is left blank, then it will use the Standard scanf version. +#SCANF_LIB = $(SCANF_LIB_MIN) +#SCANF_LIB = $(SCANF_LIB_FLOAT) +SCANF_LIB = + +MATH_LIB = -lm + +#-------------------------- External Memory Options -------------------------- +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# used for variables (.data/.bss) and heap (malloc()). +#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff + +# 64 KB of external RAM, starting after internal RAM (ATmega128!), +# only used for heap (malloc()). +#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff +EXTMEMOPTS = + + +#------------------------------- Linker Options ------------------------------ +# -Wl tell GCC to pass this to linker. +# -Map create map file +# --cref add cross reference to map file +LDFLAGS = -Wl,-Map=$(TARGET).map,--cref +LDFLAGS += $(EXTMEMOPTS) +LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) + + +#------------------------ Programmer Options (avrdude) ----------------------- +# Programmer hardware +# avr910 +# avrisp +# arduino +# picoweb +# pony-stk200 +# stk200 +# stk500 +# "avrdude -c ?" to get a full listing +#AVRDUDE_PROGRAMMER = avr910 +AVRDUDE_PROGRAMMER = usbasp + +# The port your programmer is connected to +#AVRDUDE_PORT = /dev/ttyUSB0 +#AVRDUDE_PORT = /dev/ttyS0 +AVRDUDE_PORT = usb + +AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex +#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep + +# Uncomment the following if you want avrdude's erase cycle counter. +# Note that this counter needs to be initialized first using -Yn, +# see avrdude manual. +#AVRDUDE_ERASE_COUNTER = -y + +# Uncomment the following if you do /not/ wish a verification to be +# performed after programming the device. +#AVRDUDE_NO_VERIFY = -V + +# Increase verbosity level +#AVRDUDE_VERBOSE = -v -v + +AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) +AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) +AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) +AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) + + +#=========================== End of Configuration =========================== +# Define programs and commands. +SHELL = bash +CC = avr-gcc +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +NM = avr-nm +AVRDUDE = avrdude +REMOVE = rm -f +REMOVEDIR = rm -rf +COPY = cp + +# Define messages (english) +MSG_ERRORS_NONE = Errors: none +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after: +MSG_FLASH = Creating load file for Flash: +MSG_EEPROM = Creating load file for EEPROM: +MSG_BINARY = Creating binary: +MSG_EXTENDED_LISTING = Creating Extended Listing: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = Linking: +MSG_COMPILING = Compiling C: +MSG_COMPILING_CPP = Compiling C++: +MSG_ASSEMBLING = Assembling: +MSG_CLEANING = Cleaning project: +MSG_CREATING_LIBRARY = Creating library: +MSG_PROGRAM = Flashing controller: + +# Define all object files +OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o) + +# Define all listing files +LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst) + +# Compiler flags to generate dependency files +GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d + +# Combine all necessary flags and optional flags +# Add target processor to flags +ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) +ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS) +ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) + +# Default target +all: gccversion sizebefore build sizeafter + +# Change the build target to build a HEX file or a library +build: elf hex eep bin lss sym +#build: lib +#LIBNAME=lib$(TARGET).a + +elf: $(TARGET).elf +hex: $(TARGET).hex +eep: $(TARGET).eep +bin: $(TARGET).bin +lss: $(TARGET).lss +sym: $(TARGET).sym +lib: $(LIBNAME) + +# Display size of file +HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex +ELFSIZE = $(SIZE) -A $(TARGET).elf + +sizebefore: + @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ + $(SHELL) avr-mem.sh $(TARGET) $(MCU); fi + +sizeafter: + @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ + $(SHELL) avr-mem.sh $(TARGET) $(MCU); fi + +# Display compiler version information +gccversion: + @$(CC) --version + +# Program the device +program: $(TARGET).hex $(TARGET).eep + @echo $(MSG_PROGRAM) + @echo + $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) + $(AVRDUDE_WRITE_EEPROM) + +# Create final output files (.hex, .eep) from ELF output file +%.hex: %.elf + @echo + @echo $(MSG_FLASH) $@ + $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ + +%.eep: %.elf + @echo + @echo $(MSG_EEPROM) $@ + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ +--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ + +# Create binary output +%.bin: %.elf + @echo + @echo $(MSG_BINARY) $@ + $(OBJCOPY) $(TARGET).elf -O binary $(TARGET).bin + +# Create extended listing file from ELF output file +%.lss: %.elf + @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S $< > $@ + +# Create a symbol table from ELF output file +%.sym: %.elf + @echo + @echo $(MSG_SYMBOL_TABLE) $@ + $(NM) -n $< > $@ + +# Create library from object files +.SECONDARY: $(TARGET).a +.PRECIOUS: $(OBJ) +%.a: $(OBJ) + @echo + @echo $(MSG_CREATING_LIBRARY) $@ + $(AR) $@ $(OBJ) + +# Link: create ELF output file from object files +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(OBJ) +%.elf: $(OBJ) + @echo + @echo $(MSG_LINKING) $@ + $(CC) $(ALL_CFLAGS) $^ -o $@ $(LDFLAGS) + +# Compile: create object files from C source files +$(OBJDIR)/%.o : %.c + @echo $(MSG_COMPILING) $< + $(CC) -c $(ALL_CFLAGS) $< -o $@ + +# Compile: create object files from C++ source files +$(OBJDIR)/%.o : %.cpp + @echo + @echo $(MSG_COMPILING_CPP) $< + $(CC) -c $(ALL_CPPFLAGS) $< -o $@ + +# Compile: create assembler files from C source files +%.s : %.c + $(CC) -S $(ALL_CFLAGS) $< -o $@ + +# Compile: create assembler files from C++ source files +%.s : %.cpp + $(CC) -S $(ALL_CPPFLAGS) $< -o $@ + +# Assemble: create object files from assembler source files +$(OBJDIR)/%.o : %.S + @echo + @echo $(MSG_ASSEMBLING) $< + $(CC) -c $(ALL_ASFLAGS) $< -o $@ + +# Create preprocessed source for use in sending a bug report +%.i : %.c + $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ + +# Clean project +clean: + @echo $(MSG_CLEANING) + $(REMOVE) $(TARGET).hex + $(REMOVE) $(TARGET).eep + $(REMOVE) $(TARGET).elf + $(REMOVE) $(TARGET).map + $(REMOVE) $(TARGET).sym + $(REMOVE) $(TARGET).lss + $(REMOVEDIR) $(OBJDIR) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRC:.c=.d) + $(REMOVEDIR) .dep + +# Create object files directory + mkdir $(OBJDIR) + +# Include the dependency files +-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) + +# Listing of phony targets +.PHONY: all finish sizebefore sizeafter gccversion \ +build elf hex eep lss sym \ +clean program diff --git a/src/avr-mem.sh b/src/avr-mem.sh new file mode 100755 index 0000000..2e89d0d --- /dev/null +++ b/src/avr-mem.sh @@ -0,0 +1,26 @@ +#!/bin/bash +MAXPERCENT=40 +IMAGESIZE=$(ls -l $1.bin | awk '{ print $5 }') +FLASHSIZE=$(perl -e "print 0x$(echo -e "#include \nFLASHEND" | avr-cpp -mmcu=$2 | tail -n 1 |cut -c3-);") +FLASHSIZE=$[$FLASHSIZE + 1] +PERCENT=$(perl -e "printf('%.2f', $IMAGESIZE.0 / $FLASHSIZE.0 *100.0);" ) +PER=$(perl -e "printf('%i', $IMAGESIZE / $FLASHSIZE *$MAXPERCENT);" ) + +echo "Imagesize: $IMAGESIZE/$FLASHSIZE bytes (${PERCENT}%)" +if [ $IMAGESIZE -gt $FLASHSIZE ];then + echo " WARNING! Your Image is too big for the selected chip. WARNING!" + echo "" + exit 1 +else + echo -n " [" + COUNTER=0 + while [ $COUNTER -lt $MAXPERCENT ]; do + if [ $COUNTER -lt $PER ]; then + echo -n "=" + else + echo -n "-" + fi + let COUNTER=COUNTER+1 + done + echo "]" +fi diff --git a/src/ds1820.c b/src/ds1820.c new file mode 100644 index 0000000..82da45b --- /dev/null +++ b/src/ds1820.c @@ -0,0 +1,168 @@ +/** + * Library to use DS18x20 with ATMEL Atmega family. + * + * For short DS18x20 wires there is no need for an external pullup resistor. + * If the wire length exceeds one meter you should use a 4.7k pullup resistor + * on the data line. This library does not work for parasite power. + * You can just use one DS18x20 per Atmega Pin. + * + * @copyrigth 2010, Stefan Sicklinger + * @url http://www.sicklinger.com + * @author Stefan Sicklinger + * @author Steffen Vogel + * + * This library 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, either version 3 of the License, or + * any later version. + * + * 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, see . + */ + +#include "ds1820.h" + +uint8_t ds1820_reset(uint8_t pin) { + uint8_t err = 100; + + DS1820_DDR |= (1 << pin); + DS1820_PORT &= ~(1 << pin); + _delay_us(480); + + DS1820_DDR &= ~(1 << pin); + DS1820_PORT |= 1 << pin; + _delay_us(66); + + err = (DS1820_PIN & (1 << pin)) >> pin; + _delay_us(240); + + if ((DS1820_PIN & (1 << pin)) == 0) { + err = 2; + } + + return err; +} +void ds1820_wr_bit(uint8_t bit, uint8_t pin) { + if (bit) { + DS1820_DDR |= (1 << pin); + DS1820_PORT &= ~(1 << pin); + _delay_us(10); + DS1820_DDR &= ~(1 << pin); + DS1820_PORT |= (1 << pin); + _delay_us(54); + } + else { + DS1820_DDR |= (1 << pin); + DS1820_PORT &= ~(1 << pin); + _delay_us(60); + DS1820_DDR &= ~(1 << pin); + DS1820_PORT |= (1 << pin); + _delay_us(4); + } +} +uint8_t ds1820_re_bit(uint8_t pin) { + uint8_t rebit; + + DS1820_DDR |= 1<> pin; + _delay_us(50); + + return rebit; +} + +uint8_t ds1820_re_byte(uint8_t pin) { + uint8_t byte = 0; + uint8_t i; + + for (i = 0; i < 8; i++) { + if (ds1820_re_bit(pin)) { + byte |= (1 << i); + } + + //delay_us(2); // be on the save side + } + + return byte; +} +void ds1820_wr_byte(uint8_t byte,uint8_t pin) { + uint8_t i; + + for (i = 0; i < 8; i++) { // writes byte, one bit at a time + ds1820_wr_bit((byte & (1 << i)), pin); + } + + _delay_us(5); +} + +float ds1820_read_temp(uint8_t pin) { + uint8_t error,i; + uint16_t j = 0; + uint8_t scratchpad[9] = { 0 }; + float temp = 0; + + error = ds1820_reset(pin); // 1. Reset + + if (!error) { + ds1820_wr_byte(0xCC, pin); // 2. skip ROM + ds1820_wr_byte(0x44, pin); // 3. ask for temperature conversion + + while (ds1820_re_byte(pin) == 0xFF && j < 1000){ // 4. wait until conversion is finished + _delay_us(1); + j++; + } + + error = ds1820_reset(pin); // 5. Reset + ds1820_wr_byte(0xCC, pin); // 6. skip ROM + ds1820_wr_byte(0xBE, pin); // 7. Read entire scratchpad 9 bytes + + for (i = 0; i < 9; i++) { // 8. Get scratchpad byte by byte + scratchpad[i] = ds1820_re_byte(pin); // 9. read one DS18S20 byte + } + } + + if (scratchpad[1] == 0x00 && scratchpad[7]) { // Value positive + temp = (scratchpad[0] >>= 1) - 0.25f + (((float) scratchpad[7] - (float) scratchpad[6]) / (float) scratchpad[7]); + temp = floor(temp * 10.0 + 0.5) / 10; // Round value .x + } + + if (scratchpad[1] != 0x00){ // Value negative + temp = -((~scratchpad[0] >> 1) + 1); + + if (scratchpad[0] & 1){ + temp += 0.5; + } + } + + return temp; +} + +void ds1820_init(uint8_t pin) { + uint16_t i = 0; + uint8_t error = ds1820_reset(pin); // 1. Reset + + if (!error) { + ds1820_wr_byte(0xCC,pin); // 2. skip ROM + ds1820_wr_byte(0x44,pin); // 3. ask for temperature conversion + + while (ds1820_re_byte(pin) == 0xFF && i < 1000) { // 4. wait until conversion is finished + _delay_us(1); + i++; + } + + error=ds1820_reset(pin); // 5. Reset + ds1820_wr_byte(0xCC,pin); // 6. skip ROM + ds1820_wr_byte(0xBE,pin); // 7. Read entire scratchpad 9 bytes + } +} diff --git a/src/ds1820.h b/src/ds1820.h new file mode 100644 index 0000000..0e6b9b2 --- /dev/null +++ b/src/ds1820.h @@ -0,0 +1,47 @@ +/** + * Library to use DS18x20 with ATMEL Atmega family. + * + * For short DS18x20 wires there is no need for an external pullup resistor. + * If the wire length exceeds one meter you should use a 4.7k pullup resistor + * on the data line. This library does not work for parasite power. + * You can just use one DS18x20 per Atmega Pin. + * + * @copyrigth 2010, Stefan Sicklinger + * @url http://www.sicklinger.com + * @author Stefan Sicklinger + * @author Steffen Vogel + * + * This library 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, either version 3 of the License, or + * any later version. + * + * 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, see . + */ + +#include +#include +#include + +#ifndef _DS18X20LIB_h_ +#define _DS18X20LIB_h_ + +#define DS1820_PIN PINB +#define DS1820_PORT PORTB +#define DS1820_DDR DDRB + +uint8_t ds1820_reset(uint8_t); +void ds1820_wr_bit(uint8_t,uint8_t); +uint8_t ds1820_re_bit(uint8_t); +uint8_t ds1820_re_byte(uint8_t); +void ds1820_wr_byte(uint8_t,uint8_t); +float ds1820_read_temp(uint8_t); +void ds1820_init(uint8_t); + +#endif diff --git a/src/ds1820/Makefile b/src/ds1820/Makefile new file mode 100644 index 0000000..23eeb4f --- /dev/null +++ b/src/ds1820/Makefile @@ -0,0 +1,83 @@ +# Hey Emacs, this is a -*- makefile -*- +#---------------------------------------------------------------------------- +# Makefile for the avr-gcc Toolchain +# +# by Steffen Vogel +# +#---------------------------------------------------------------------------- + + +# Target Options +TARGET = main + +OBJS = $(TARGET).o ds1820.o lcd.o + +# Target +MCU = atmega16 +F_CPU = 14745000 + +# Programming +AVRDUDE_FLAGS = -p m16 -c usbasp -P usb + +HFUSE= +LFUSE= + +DEFINES = -DF_CPU=$(F_CPU) -DBAUD=115200 +WARNINGS = -Wall -Wextra + +CPPFLAGS += -MD -MP +CXXFLAGS += +CFLAGS += -g -O2 -mmcu=$(MCU) $(DEFINES) $(WARNINGS) +LDFLAGS += -Wl,-Map,$(TARGET).map -Wl,-u,vfprintf -lprintf_flt -lm + +# Tools +AR = avr-ar +AS = avr-as +CC = avr-gcc +CXX = avr-g++ +NM = avr-nm +OBJCOPY = avr-objcopy +OBJDUMP = avr-objdump +SIZE = avr-size +AVRDUDE = avrdude + +# Dependencies +-include $(OBJS:.o=.d) + +# Default Target +all: $(TARGET).hex $(TARGET).eep $(TARGET).lst + +$(TARGET).elf: $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + +%.lst: %.elf + $(OBJDUMP) -h -S $< > $@ + +%.hex: %.elf + $(OBJCOPY) -j .text -j .data -O ihex $< $@ + +%.eep: %.elf + $(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@ + +flash: $(TARGET).hex + $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(TARGET).hex + +eeprom: $(TARGET).eep + $(AVRDUDE) $(AVRDUDE_FLAGS) -U eeprom:w:$(TARGET).eep + +fuses: + $(AVRDUDE) $(AVRDUDE_FLAGS) -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m + +size: $(TARGET).elf + $(SIZE) -A $(TARGET).elf --format=avr --mcu $(MCU) | tail -n +5 + $(NM) --print-size --size-sort --reverse-sort --radix=d main.elf --format=s | tail -n +5 | head -n 12 + +clean: + rm -f $(OBJS) $(OBJS:.o=.d) + rm -f $(TARGET).elf + rm -f $(TARGET).hex + rm -f $(TARGET).eep + rm -f $(TARGET).lst + rm -f $(TARGET).map + +.PHONY: all size clean flash eeprom fuses diff --git a/src/ds1820/lcd.c b/src/ds1820/lcd.c new file mode 100644 index 0000000..2ea4a17 --- /dev/null +++ b/src/ds1820/lcd.c @@ -0,0 +1,632 @@ +/**************************************************************************** + Title : HD44780U LCD library + Author: Peter Fleury http://jump.to/fleury + File: $Id: lcd.c,v 1.14.2.1 2006/01/29 12:16:41 peter Exp $ + Software: AVR-GCC 3.3 + Target: any AVR device, memory mapped mode only for AT90S4414/8515/Mega + + DESCRIPTION + Basic routines for interfacing a HD44780U-based text lcd display + + Originally based on Volker Oth's lcd library, + changed lcd_init(), added additional constants for lcd_command(), + added 4-bit I/O mode, improved and optimized code. + + Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in + 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported. + + Memory mapped mode compatible with Kanda STK200, but supports also + generation of R/W signal through A8 address line. + + USAGE + See the C include lcd.h file for a description of each function + +*****************************************************************************/ + +#include "lcd.h" + +/* +** constants/macros +*/ +#define DDR(x) (*(&x - 1)) /* address of data direction register of port x */ +#if defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) + /* on ATmega64/128 PINF is on port 0x00 and not 0x60 */ + #define PIN(x) ( &PORTF==&(x) ? _SFR_IO8(0x00) : (*(&x - 2)) ) +#else + #define PIN(x) (*(&x - 2)) /* address of input register of port x */ +#endif + + +#if LCD_IO_MODE +#define lcd_e_delay() __asm__ __volatile__( "rjmp 1f\n 1:" ); +#define lcd_e_high() LCD_E_PORT |= _BV(LCD_E_PIN); +#define lcd_e_low() LCD_E_PORT &= ~_BV(LCD_E_PIN); +#define lcd_e_toggle() toggle_e() +#define lcd_rw_high() LCD_RW_PORT |= _BV(LCD_RW_PIN) +#define lcd_rw_low() LCD_RW_PORT &= ~_BV(LCD_RW_PIN) +#define lcd_rs_high() LCD_RS_PORT |= _BV(LCD_RS_PIN) +#define lcd_rs_low() LCD_RS_PORT &= ~_BV(LCD_RS_PIN) +#endif + +#if LCD_IO_MODE +#if LCD_LINES==1 +#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_1LINE +#else +#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_4BIT_2LINES +#endif +#else +#if LCD_LINES==1 +#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_1LINE +#else +#define LCD_FUNCTION_DEFAULT LCD_FUNCTION_8BIT_2LINES +#endif +#endif + +#if LCD_CONTROLLER_KS0073 +#if LCD_LINES==4 + +#define KS0073_EXTENDED_FUNCTION_REGISTER_ON 0x24 /* |0|010|0100 4-bit mode extension-bit RE = 1 */ +#define KS0073_EXTENDED_FUNCTION_REGISTER_OFF 0x20 /* |0|000|1001 4 lines mode */ +#define KS0073_4LINES_MODE 0x09 /* |0|001|0000 4-bit mode, extension-bit RE = 0 */ + +#endif +#endif + +/* +** function prototypes +*/ +#if LCD_IO_MODE +static void toggle_e(void); +#endif + +/* +** local functions +*/ +// +// +// +///************************************************************************* +// delay loop for small accurate delays: 16-bit counter, 4 cycles/loop +//*************************************************************************/ +//static inline void _delayFourCycles(unsigned int __count) +//{ +// if ( __count == 0 ) +// __asm__ __volatile__( "rjmp 1f\n 1:" ); // 2 cycles +// else +// __asm__ __volatile__ ( +// "1: sbiw %0,1" "\n\t" +// "brne 1b" // 4 cycles/loop +// : "=w" (__count) +// : "0" (__count) +// ); +//} +// +// +///************************************************************************* +//delay for a minimum of microseconds +//the number of loops is calculated at compile-time from MCU clock frequency +//*************************************************************************/ +//#define delay(us) _delayFourCycles( ( ( 1*(F_CPU/4000) )*us)/1000 ) + + +#if LCD_IO_MODE +/* toggle Enable Pin to initiate write */ +static void toggle_e(void) +{ + lcd_e_high(); + lcd_e_delay(); + lcd_e_low(); +} +#endif + + +/************************************************************************* +Low-level function to write byte to LCD controller +Input: data byte to write to LCD + rs 1: write data + 0: write instruction +Returns: none +*************************************************************************/ +#if LCD_IO_MODE +static void lcd_write(uint8_t data,uint8_t rs) +{ + unsigned char dataBits ; + + + if (rs) { /* write data (RS=1, RW=0) */ + lcd_rs_high(); + } else { /* write instruction (RS=0, RW=0) */ + lcd_rs_low(); + } + lcd_rw_low(); + + if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT ) + && (LCD_DATA0_PIN == 0) && (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) ) + { + /* configure data pins as output */ + DDR(LCD_DATA0_PORT) |= 0x0F; + + /* output high nibble first */ + dataBits = LCD_DATA0_PORT & 0xF0; + LCD_DATA0_PORT = dataBits |((data>>4)&0x0F); + lcd_e_toggle(); + + /* output low nibble */ + LCD_DATA0_PORT = dataBits | (data&0x0F); + lcd_e_toggle(); + + /* all data pins high (inactive) */ + LCD_DATA0_PORT = dataBits | 0x0F; + } + else + { + /* configure data pins as output */ + DDR(LCD_DATA0_PORT) |= _BV(LCD_DATA0_PIN); + DDR(LCD_DATA1_PORT) |= _BV(LCD_DATA1_PIN); + DDR(LCD_DATA2_PORT) |= _BV(LCD_DATA2_PIN); + DDR(LCD_DATA3_PORT) |= _BV(LCD_DATA3_PIN); + + /* output high nibble first */ + LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN); + LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN); + LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN); + LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); + if(data & 0x80) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); + if(data & 0x40) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); + if(data & 0x20) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); + if(data & 0x10) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); + lcd_e_toggle(); + + /* output low nibble */ + LCD_DATA3_PORT &= ~_BV(LCD_DATA3_PIN); + LCD_DATA2_PORT &= ~_BV(LCD_DATA2_PIN); + LCD_DATA1_PORT &= ~_BV(LCD_DATA1_PIN); + LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); + if(data & 0x08) LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); + if(data & 0x04) LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); + if(data & 0x02) LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); + if(data & 0x01) LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); + lcd_e_toggle(); + + /* all data pins high (inactive) */ + LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); + LCD_DATA1_PORT |= _BV(LCD_DATA1_PIN); + LCD_DATA2_PORT |= _BV(LCD_DATA2_PIN); + LCD_DATA3_PORT |= _BV(LCD_DATA3_PIN); + } +} +#else +#define lcd_write(d,rs) if (rs) *(volatile uint8_t*)(LCD_IO_DATA) = d; else *(volatile uint8_t*)(LCD_IO_FUNCTION) = d; +/* rs==0 -> write instruction to LCD_IO_FUNCTION */ +/* rs==1 -> write data to LCD_IO_DATA */ +#endif + + +/************************************************************************* +Low-level function to read byte from LCD controller +Input: rs 1: read data + 0: read busy flag / address counter +Returns: byte read from LCD controller +*************************************************************************/ +#if LCD_IO_MODE +static uint8_t lcd_read(uint8_t rs) +{ + uint8_t data; + + + if (rs) + lcd_rs_high(); /* RS=1: read data */ + else + lcd_rs_low(); /* RS=0: read busy flag */ + lcd_rw_high(); /* RW=1 read mode */ + + if ( ( &LCD_DATA0_PORT == &LCD_DATA1_PORT) && ( &LCD_DATA1_PORT == &LCD_DATA2_PORT ) && ( &LCD_DATA2_PORT == &LCD_DATA3_PORT ) + && ( LCD_DATA0_PIN == 0 )&& (LCD_DATA1_PIN == 1) && (LCD_DATA2_PIN == 2) && (LCD_DATA3_PIN == 3) ) + { + DDR(LCD_DATA0_PORT) &= 0xF0; /* configure data pins as input */ + + lcd_e_high(); + lcd_e_delay(); + data = PIN(LCD_DATA0_PORT) << 4; /* read high nibble first */ + lcd_e_low(); + + lcd_e_delay(); /* Enable 500ns low */ + + lcd_e_high(); + lcd_e_delay(); + data |= PIN(LCD_DATA0_PORT)&0x0F; /* read low nibble */ + lcd_e_low(); + } + else + { + /* configure data pins as input */ + DDR(LCD_DATA0_PORT) &= ~_BV(LCD_DATA0_PIN); + DDR(LCD_DATA1_PORT) &= ~_BV(LCD_DATA1_PIN); + DDR(LCD_DATA2_PORT) &= ~_BV(LCD_DATA2_PIN); + DDR(LCD_DATA3_PORT) &= ~_BV(LCD_DATA3_PIN); + + /* read high nibble first */ + lcd_e_high(); + lcd_e_delay(); + data = 0; + if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x10; + if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x20; + if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x40; + if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x80; + lcd_e_low(); + + lcd_e_delay(); /* Enable 500ns low */ + + /* read low nibble */ + lcd_e_high(); + lcd_e_delay(); + if ( PIN(LCD_DATA0_PORT) & _BV(LCD_DATA0_PIN) ) data |= 0x01; + if ( PIN(LCD_DATA1_PORT) & _BV(LCD_DATA1_PIN) ) data |= 0x02; + if ( PIN(LCD_DATA2_PORT) & _BV(LCD_DATA2_PIN) ) data |= 0x04; + if ( PIN(LCD_DATA3_PORT) & _BV(LCD_DATA3_PIN) ) data |= 0x08; + lcd_e_low(); + } + return data; +} +#else +#define lcd_read(rs) (rs) ? *(volatile uint8_t*)(LCD_IO_DATA+LCD_IO_READ) : *(volatile uint8_t*)(LCD_IO_FUNCTION+LCD_IO_READ) +/* rs==0 -> read instruction from LCD_IO_FUNCTION */ +/* rs==1 -> read data from LCD_IO_DATA */ +#endif + + +/************************************************************************* +loops while lcd is busy, returns address counter +*************************************************************************/ +static uint8_t lcd_waitbusy(void) + +{ + register uint8_t c; + + /* wait until busy flag is cleared */ + while ( (c=lcd_read(0)) & (1<= LCD_START_LINE2) && (pos < LCD_START_LINE3) ) + addressCounter = LCD_START_LINE3; + else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE4) ) + addressCounter = LCD_START_LINE4; + else + addressCounter = LCD_START_LINE1; +#else + if ( pos < LCD_START_LINE3 ) + addressCounter = LCD_START_LINE2; + else if ( (pos >= LCD_START_LINE2) && (pos < LCD_START_LINE4) ) + addressCounter = LCD_START_LINE3; + else if ( (pos >= LCD_START_LINE3) && (pos < LCD_START_LINE2) ) + addressCounter = LCD_START_LINE4; + else + addressCounter = LCD_START_LINE1; +#endif +#endif + lcd_command((1<>4; + LCD_DATA0_PORT |= _BV(LCD_DATA0_PIN); // _BV(LCD_FUNCTION_8BIT)>>4; + lcd_e_toggle(); + _delay_us(4992); /* delay, busy flag can't be checked here */ + + /* repeat last command */ + lcd_e_toggle(); + _delay_us(64); /* delay, busy flag can't be checked here */ + + /* repeat last command a third time */ + lcd_e_toggle(); + _delay_us(64); /* delay, busy flag can't be checked here */ + + /* now configure for 4bit mode */ + LCD_DATA0_PORT &= ~_BV(LCD_DATA0_PIN); // LCD_FUNCTION_4BIT_1LINE>>4 + lcd_e_toggle(); + _delay_us(64); /* some displays need this additional delay */ + + /* from now the LCD only accepts 4 bit I/O, we can use lcd_command() */ +#else + /* + * Initialize LCD to 8 bit memory mapped mode + */ + + /* enable external SRAM (memory mapped lcd) and one wait state */ + MCUCR = _BV(SRE) | _BV(SRW); + + /* reset LCD */ + delay(16000); /* wait 16ms after power-on */ + lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */ + delay(4992); /* wait 5ms */ + lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */ + delay(64); /* wait 64us */ + lcd_write(LCD_FUNCTION_8BIT_1LINE,0); /* function set: 8bit interface */ + delay(64); /* wait 64us */ +#endif + +#if KS0073_4LINES_MODE + /* Display with KS0073 controller requires special commands for enabling 4 line mode */ + lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_ON); + lcd_command(KS0073_4LINES_MODE); + lcd_command(KS0073_EXTENDED_FUNCTION_REGISTER_OFF); +#else + lcd_command(LCD_FUNCTION_DEFAULT); /* function set: display lines */ +#endif + lcd_command(LCD_DISP_OFF); /* display off */ + lcd_clrscr(); /* display clear */ + lcd_command(LCD_MODE_DEFAULT); /* set entry mode */ + lcd_command(dispAttr); /* display/cursor control */ + +}/* lcd_init */ diff --git a/src/ds1820/lcd.h b/src/ds1820/lcd.h new file mode 100644 index 0000000..23bb3b3 --- /dev/null +++ b/src/ds1820/lcd.h @@ -0,0 +1,268 @@ +#ifndef LCD_H +#define LCD_H +/************************************************************************* + Title : C include file for the HD44780U LCD library (lcd.c) + Author: Peter Fleury http://jump.to/fleury + File: $Id: lcd.h,v 1.13.2.2 2006/01/30 19:51:33 peter Exp $ + Software: AVR-GCC 3.3 + Hardware: any AVR device, memory mapped mode only for AT90S4414/8515/Mega +***************************************************************************/ + +/** + @defgroup pfleury_lcd LCD library + @code #include @endcode + + @brief Basic routines for interfacing a HD44780U-based text LCD display + + Originally based on Volker Oth's LCD library, + changed lcd_init(), added additional constants for lcd_command(), + added 4-bit I/O mode, improved and optimized code. + + Library can be operated in memory mapped mode (LCD_IO_MODE=0) or in + 4-bit IO port mode (LCD_IO_MODE=1). 8-bit IO port mode not supported. + + Memory mapped mode compatible with Kanda STK200, but supports also + generation of R/W signal through A8 address line. + + @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury + + @see The chapter Interfacing a HD44780 Based LCD to an AVR + on my home page. + +*/ + +/*@{*/ + +#if (__GNUC__ * 100 + __GNUC_MINOR__) < 303 +#error "This library requires AVR-GCC 3.3 or later, update to newer AVR-GCC compiler !" +#endif + +#include +#include +#include +#include "lcd.h" +#include "util/delay.h" + + + + +/** + * @name Definition for LCD controller type + * Use 0 for HD44780 controller, change to 1 for displays with KS0073 controller. + */ +#define LCD_CONTROLLER_KS0073 0 /**< Use 0 for HD44780 controller, 1 for KS0073 controller */ + +/** + * @name Definitions for Display Size + * Change these definitions to adapt setting to your display + */ +#define LCD_LINES 2 /**< number of visible lines of the display */ +#define LCD_DISP_LENGTH 8 /**< visibles characters per line of the display */ +#define LCD_LINE_LENGTH 0x40 /**< internal line length of the display */ +#define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */ +#define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */ +#define LCD_START_LINE3 0x14 /**< DDRAM address of first char of line 3 */ +#define LCD_START_LINE4 0x54 /**< DDRAM address of first char of line 4 */ +#define LCD_WRAP_LINES 0 /**< 0: no wrap, 1: wrap at end of visibile line */ + + +#define LCD_IO_MODE 1 /**< 0: memory mapped mode, 1: IO port mode */ +#if LCD_IO_MODE +/** + * @name Definitions for 4-bit IO mode + * Change LCD_PORT if you want to use a different port for the LCD pins. + * + * The four LCD data lines and the three control lines RS, RW, E can be on the + * same port or on different ports. + * Change LCD_RS_PORT, LCD_RW_PORT, LCD_E_PORT if you want the control lines on + * different ports. + * + * Normally the four data lines should be mapped to bit 0..3 on one port, but it + * is possible to connect these data lines in different order or even on different + * ports by adapting the LCD_DATAx_PORT and LCD_DATAx_PIN definitions. + * + */ +#define LCD_PORT PORTC /**< port for the LCD lines */ +#define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */ +#define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */ +#define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */ +#define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */ +#define LCD_DATA0_PIN 3 /**< pin for 4bit data bit 0 */ +#define LCD_DATA1_PIN 4 /**< pin for 4bit data bit 1 */ +#define LCD_DATA2_PIN 5 /**< pin for 4bit data bit 2 */ +#define LCD_DATA3_PIN 6 /**< pin for 4bit data bit 3 */ +#define LCD_RS_PORT LCD_PORT /**< port for RS line */ +#define LCD_RS_PIN 0 /**< pin for RS line */ +#define LCD_RW_PORT LCD_PORT /**< port for RW line */ +#define LCD_RW_PIN 1 /**< pin for RW line */ +#define LCD_E_PORT LCD_PORT /**< port for Enable line */ +#define LCD_E_PIN 2 /**< pin for Enable line */ + +#elif defined(__AVR_AT90S4414__) || defined(__AVR_AT90S8515__) || defined(__AVR_ATmega64__) || \ + defined(__AVR_ATmega8515__)|| defined(__AVR_ATmega103__) || defined(__AVR_ATmega128__) || \ + defined(__AVR_ATmega161__) || defined(__AVR_ATmega162__) +/* + * memory mapped mode is only supported when the device has an external data memory interface + */ +#define LCD_IO_DATA 0xC000 /* A15=E=1, A14=RS=1 */ +#define LCD_IO_FUNCTION 0x8000 /* A15=E=1, A14=RS=0 */ +#define LCD_IO_READ 0x0100 /* A8 =R/W=1 (R/W: 1=Read, 0=Write */ +#else +#error "external data memory interface not available for this device, use 4-bit IO port mode" + +#endif + + +/** + * @name Definitions for LCD command instructions + * The constants define the various LCD controller instructions which can be passed to the + * function lcd_command(), see HD44780 data sheet for a complete description. + */ + +/* instruction register bit positions, see HD44780U data sheet */ +#define LCD_CLR 0 /* DB0: clear display */ +#define LCD_HOME 1 /* DB1: return to home position */ +#define LCD_ENTRY_MODE 2 /* DB2: set entry mode */ +#define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */ +#define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */ +#define LCD_ON 3 /* DB3: turn lcd/cursor on */ +#define LCD_ON_DISPLAY 2 /* DB2: turn display on */ +#define LCD_ON_CURSOR 1 /* DB1: turn cursor on */ +#define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */ +#define LCD_MOVE 4 /* DB4: move cursor/display */ +#define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */ +#define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */ +#define LCD_FUNCTION 5 /* DB5: function set */ +#define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */ +#define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */ +#define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */ +#define LCD_CGRAM 6 /* DB6: set CG RAM address */ +#define LCD_DDRAM 7 /* DB7: set DD RAM address */ +#define LCD_BUSY 7 /* DB7: LCD is busy */ + +/* set entry mode: display shift on/off, dec/inc cursor move direction */ +#define LCD_ENTRY_DEC 0x04 /* display shift off, dec cursor move dir */ +#define LCD_ENTRY_DEC_SHIFT 0x05 /* display shift on, dec cursor move dir */ +#define LCD_ENTRY_INC_ 0x06 /* display shift off, inc cursor move dir */ +#define LCD_ENTRY_INC_SHIFT 0x07 /* display shift on, inc cursor move dir */ + +/* display on/off, cursor on/off, blinking char at cursor position */ +#define LCD_DISP_OFF 0x08 /* display off */ +#define LCD_DISP_ON 0x0C /* display on, cursor off */ +#define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */ +#define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */ +#define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */ + +/* move cursor/shift display */ +#define LCD_MOVE_CURSOR_LEFT 0x10 /* move cursor left (decrement) */ +#define LCD_MOVE_CURSOR_RIGHT 0x14 /* move cursor right (increment) */ +#define LCD_MOVE_DISP_LEFT 0x18 /* shift display left */ +#define LCD_MOVE_DISP_RIGHT 0x1C /* shift display right */ + +/* function set: set interface data length and number of display lines */ +#define LCD_FUNCTION_4BIT_1LINE 0x20 /* 4-bit interface, single line, 5x7 dots */ +#define LCD_FUNCTION_4BIT_2LINES 0x28 /* 4-bit interface, dual line, 5x7 dots */ +#define LCD_FUNCTION_8BIT_1LINE 0x30 /* 8-bit interface, single line, 5x7 dots */ +#define LCD_FUNCTION_8BIT_2LINES 0x38 /* 8-bit interface, dual line, 5x7 dots */ + + +#define LCD_MODE_DEFAULT ((1< + * @link http://www.mmi.rwth-aachen.de/?microcontrollerag + */ +/* + * This 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, either version 3 of the License, or + * any later version. + */ + +#include + +#include "lcd.h" +#include "ds1820.h" + +int main() { + float temp; + char buffer[16]; + + + lcd_init(LCD_DISP_ON); + ds1820_init(PB2); + + lcd_puts("DS1820\nReadout"); + _delay_ms(1000); + lcd_clrscr(); + + + for (;;) { + temp = ds1820_read_temp(PB2); + snprintf(buffer, sizeof(buffer), "%.2f ", temp); + + lcd_home(); + lcd_puts(buffer); + lcd_putc(0xdf); + lcd_putc('C'); + + _delay_ms(500); + } + + return 0; +} diff --git a/src/font.h b/src/font.h new file mode 100644 index 0000000..8f6b170 --- /dev/null +++ b/src/font.h @@ -0,0 +1,435 @@ +#include + +#define FONT_WIDTH 3 + +#if FONT_WIDTH == 5 + +char font[][5] = { + {0xff,0xff,0xff,0xff,0x00}, // Space + {0x00,0x00,0xfa,0x00,0x00}, // ! + {0x00,0xe0,0x00,0xe0,0x00}, // " + {0x28,0xfe,0x28,0xfe,0x28}, // # + {0x24,0x54,0xfe,0x54,0x48}, // $ + {0xc4,0xc8,0x10,0x26,0x46}, // % + {0x6c,0x92,0xaa,0x44,0x0a}, // & + {0x00,0xa0,0xc0,0x00,0x00}, // ' + {0x00,0x38,0x44,0x82,0x00}, // ( + {0x00,0x82,0x44,0x38,0x00}, // ) + {0x10,0x54,0x38,0x54,0x10}, // * + {0x10,0x10,0x7c,0x10,0x10}, // + + {0x00,0x0a,0x0c,0x00,0x00}, // , + {0x10,0x10,0x10,0x10,0x10}, // - +// {0x00,0x01,0x06,0x00,0x00}, // . + {0x01,0x06,0xff,0x00,0x00}, // . + {0x04,0x08,0x10,0x20,0x40}, // / + {0x7c,0x8a,0x92,0xa2,0x7c}, // 0 + {0x00,0x42,0xfe,0x02,0x00}, // 1 + {0x42,0x86,0x8a,0x92,0x62}, // 2 + {0x84,0x82,0xa2,0xd2,0x8c}, // 3 + {0x18,0x28,0x48,0xfe,0x08}, // 4 + {0xe4,0xa2,0xa2,0xa2,0x9c}, // 5 + {0x3c,0x52,0x92,0x92,0x0c}, // 6 + {0x80,0x8e,0x90,0xa0,0xc0}, // 7 + {0x6c,0x92,0x92,0x92,0x6c}, // 8 + {0x60,0x92,0x92,0x94,0x78}, // 9 + {0x00,0x6c,0x6c,0x00,0x00}, // : + {0x00,0x6a,0x6c,0x00,0x00}, // ; + {0x00,0x10,0x28,0x44,0x82}, // < + {0x28,0x28,0x28,0x28,0x28}, // = + {0x82,0x44,0x28,0x10,0x00}, // > + {0x40,0x80,0x8a,0x90,0x60}, // ? + {0x4c,0x92,0x9e,0x82,0x7c}, // @ + {0x7e,0x88,0x88,0x88,0x7e}, // A + {0xfe,0x92,0x92,0x92,0x6c}, // B + {0x7c,0x82,0x82,0x82,0x44}, // C + {0xfe,0x82,0x82,0x44,0x38}, // D + {0xfe,0x92,0x92,0x92,0x82}, // E + {0xfe,0x90,0x90,0x80,0x80}, // F + {0x7c,0x82,0x82,0x8a,0x4c}, // G + {0xfe,0x10,0x10,0x10,0xfe}, // H + {0x00,0x82,0xfe,0x82,0x00}, // I + {0x04,0x02,0x82,0xfc,0x80}, // J + {0xfe,0x10,0x28,0x44,0x82}, // K + {0xfe,0x02,0x02,0x02,0x02}, // L + {0xfe,0x40,0x20,0x40,0xfe}, // M + {0xfe,0x20,0x10,0x08,0xfe}, // N + {0x7c,0x82,0x82,0x82,0x7c}, // O + {0xfe,0x90,0x90,0x90,0x60}, // P + {0x7c,0x82,0x8a,0x84,0x7a}, // Q + {0xfe,0x90,0x98,0x94,0x62}, // R + {0x62,0x92,0x92,0x92,0x8c}, // S + {0x80,0x80,0xfe,0x80,0x80}, // T + {0xfc,0x02,0x02,0x02,0xfc}, // U + {0xf8,0x04,0x02,0x04,0xf8}, // V + {0xfe,0x04,0x18,0x04,0xfe}, // W + {0xc6,0x28,0x10,0x28,0xc6}, // X + {0xc0,0x20,0x1e,0x20,0xc0}, // Y + {0x86,0x8a,0x92,0xa2,0xc2}, // Z + {0x00,0x00,0xfe,0x82,0x82}, // [ + {0x40,0x20,0x10,0x08,0x04}, // "\" + {0x82,0x82,0xfe,0x00,0x00}, // ] + {0x20,0x40,0x80,0x40,0x20}, // ^ + {0x02,0x02,0x02,0x02,0x02}, // _ + {0x00,0x80,0x40,0x20,0x00}, // ` + {0x04,0x2a,0x2a,0x2a,0x1e}, // a + {0xfe,0x12,0x22,0x22,0x1c}, // b + {0x1c,0x22,0x22,0x22,0x04}, // c + {0x1c,0x22,0x22,0x12,0xfe}, // d + {0x1c,0x2a,0x2a,0x2a,0x18}, // e + {0x10,0x7e,0x90,0x80,0x40}, // f + {0x10,0x28,0x2a,0x2a,0x3c}, // g + {0xfe,0x10,0x20,0x20,0x1e}, // h + {0x00,0x22,0xbe,0x02,0x00}, // i + {0x04,0x02,0x22,0xbc,0x00}, // j + {0x00,0xfe,0x08,0x14,0x22}, // k + {0x00,0x82,0xfe,0x02,0x00}, // l + {0x3e,0x20,0x18,0x20,0x1e}, // m + {0x3e,0x10,0x20,0x20,0x1e}, // n + {0x1c,0x22,0x22,0x22,0x1c}, // o + {0x3e,0x28,0x28,0x28,0x10}, // p + {0x10,0x28,0x28,0x18,0x3e}, // q + {0x3e,0x10,0x20,0x20,0x10}, // r + {0x12,0x2a,0x2a,0x2a,0x04}, // s + {0x20,0xfc,0x22,0x02,0x04}, // t + {0x3c,0x02,0x02,0x04,0x3e}, // u + {0x38,0x04,0x02,0x04,0x38}, // v + {0x3c,0x02,0x0c,0x02,0x3c}, // w + {0x22,0x14,0x08,0x14,0x22}, // x + {0x30,0x0a,0x0a,0x0a,0x3c}, // y + {0x22,0x26,0x2a,0x32,0x22}, // z + {0x00,0x10,0x6c,0x82,0x00}, // { + {0x00,0x00,0xfe,0x00,0x00}, // | + {0x00,0x82,0x6c,0x10,0x00}, // } + {0x40,0x80,0xc0,0x40,0x80}, // ~ +// {0x00,0x60,0x90,0x90,0x60}, // ° (DEL) 0x7f + {0x00,0x40,0xA0,0x40,0xff}, // ° (DEL) 0x7f +}; + +#elif FONT_WIDTH == 4 + +uint8_t font[][9] = { + {3,0x00,0x00,0x00}, // + {1,0xfa,0x00,0x00}, // ! + {3,0xc0,0x00,0xc0}, // " + {3,0x14,0x3e,0x14}, // # + {3,0x74,0xd6,0x5c}, // $ + {3,0x26,0x08,0x32}, // % + {3,0xfa,0xae,0xea}, // & + {1,0xc0,0x00,0x00}, // ' + {3,0x38,0x44,0x82}, // ( + {3,0x82,0x44,0x38}, // ) + {3,0x50,0x20,0x50}, // * + {3,0x20,0x70,0x20}, // + + {1,0x06,0x00,0x00}, // , + {3,0x20,0x20,0x20}, // - + {1,0x02,0x00,0x00}, // . + {3,0x06,0x18,0x60}, // / + {3,0xfe,0x82,0xfe}, // 0 + {3,0x42,0xfe,0x02}, // 1 + {3,0xbe,0xa2,0xe2}, // 2 + {3,0xa2,0xa2,0xfe}, // 3 + {3,0xf8,0x08,0xfe}, // 4 + {3,0xe2,0xa2,0xbe}, // 5 + {3,0xfe,0xa2,0xbe}, // 6 + {3,0x80,0x80,0xfe}, // 7 + {3,0xfe,0xa2,0xfe}, // 8 + {3,0xf9,0x89,0xfe}, // 9 + {1,0x0a,0x00,0x00}, // : + {1,0x16,0x00,0x00}, // ; + {3,0x10,0x28,0x44}, // < + {3,0x28,0x28,0x28}, // = + {3,0x44,0x28,0x10}, // > + {2,0x9a,0xf0,0x00}, // ? + {3,0x2e,0x22,0x3e}, // @ + {3,0xfe,0x84,0xfe}, // A + {3,0xfe,0xe2,0x3e}, // B + {3,0xfe,0x82,0xc6}, // C + {3,0xbe,0x82,0xfe}, // D + {3,0xfe,0xa2,0xa2}, // E + {3,0xfe,0xa0,0xa0}, // F + {3,0xfe,0x82,0xbe}, // G + {3,0xfe,0x20,0xfe}, // H + {3,0x82,0xfe,0x82}, // I + {3,0x02,0x82,0xfe}, // J + {3,0xfe,0x50,0xde}, // K + {3,0xfe,0x02,0x02}, // L + {3,0xfe,0x70,0xfe}, // M + {3,0xfe,0x80,0xfe}, // N + {3,0xfe,0x82,0xfe}, // O + {3,0xfe,0x84,0xfc}, // P + {3,0xfc,0x84,0xfa}, // Q + {3,0xfe,0x8c,0xfa}, // R + {3,0xe2,0xa2,0xbe}, // S + {3,0x80,0xfe,0x80}, // T + {3,0xfe,0x02,0xfe}, // U + {3,0xfe,0x04,0xf8}, // V + {3,0xfe,0x1c,0xfe}, // W + {3,0xde,0x70,0xde}, // X + {3,0xe0,0x3e,0xe0}, // Y + {3,0x9e,0xa2,0xc2}, // Z + {2,0xfe,0x82,0x00}, // [ + {3,0x60,0x18,0x06}, // + {2,0x82,0xfe,0x00}, // ] + {3,0x40,0x80,0x40}, // ^ + {3,0x02,0x02,0x02}, // _ + {2,0x80,0x40,0x00}, // ` + {3,0x2e,0x2a,0x3e}, // a + {3,0xfe,0x22,0x3e}, // b + {3,0x3e,0x22,0x22}, // c + {3,0x3e,0x22,0xfe}, // d + {3,0x3e,0x2a,0x3a}, // e + {3,0x20,0xfe,0xa0}, // f + {3,0x3a,0x2a,0x3e}, // g + {3,0xfe,0x20,0x3e}, // h + {1,0xbe,0x00,0x00}, // i + {2,0x02,0xbe,0x00}, // j + {3,0xfe,0x08,0x36}, // k + {2,0xfe,0x02,0x00}, // l + {3,0x3e,0x18,0x3e}, // m + {3,0x3e,0x20,0x3e}, // n + {3,0x3e,0x22,0x3e}, // o + {3,0x3e,0x24,0x3c}, // p + {3,0x3c,0x24,0x3e}, // q + {3,0x3e,0x20,0x20}, // r + {3,0x3a,0x2a,0x2e}, // s + {3,0x20,0x7e,0x22}, // t + {3,0x3e,0x02,0x3e}, // u + {3,0x3e,0x04,0x38}, // v + {3,0x3e,0x0c,0x3e}, // w + {3,0x36,0x08,0x36}, // x + {3,0x3a,0x0a,0x3e}, // y + {3,0x26,0x2a,0x32}, // z + {3,0x10,0xfe,0x82}, // { + {1,0xfe,0x00,0x00}, // | + {3,0x82,0xfe,0x10}, // } + {3,0x80,0xc0,0x40}, // ~ + {8,0xff,0xff,0xff}, // Full filled + {3,0x40,0xa0,0x40}, // ° + {5,0x20,0x40,0xfe,0x40,0x20,0x00,0x00,0x00}, // arrow up + {5,0x04,0x02,0xfe,0x02,0x04,0x00,0x00,0x00}, // arrow down + {8,0x44,0xee,0xfe,0x7c,0x38,0x10,0x00,0x00}, // Heart big + {8,0x00,0x6C,0x7C,0x38,0x10,0x00,0x00,0x00} // Heart small +}; + +#elif FONT_WIDTH == 3 + +uint8_t font[][3] = { + {0x00,0x00,0x00}, // + {0xfa,0xff,0x00}, // ! + {0xc0,0x00,0xc0}, // " + {0x14,0x3e,0x14}, // # + {0x74,0xd6,0x5c}, // $ + {0x26,0x08,0x32}, // % + {0xfa,0xae,0xea}, // & + {0xc0,0xff,0x00}, // ' + {0x38,0x44,0x82}, // ( + {0x82,0x44,0x38}, // ) + {0x50,0x20,0x50}, // * + {0x20,0x70,0x20}, // + + {0x06,0xff,0xff}, // , + {0x20,0x20,0x20}, // - + {0x02,0xff,0x00}, // . + {0x06,0x18,0x60}, // / + {0xfe,0x82,0xfe}, // 0 + {0x42,0xfe,0x02}, // 1 + {0xbe,0xa2,0xe2}, // 2 + {0xa2,0xa2,0xfe}, // 3 + {0xf8,0x08,0xfe}, // 4 + {0xe2,0xa2,0xbe}, // 5 + {0xfe,0xa2,0xbe}, // 6 + {0x80,0x80,0xfe}, // 7 + {0xfe,0xa2,0xfe}, // 8 + {0xfa,0x8a,0xfe}, // 9 + {0x0a,0x00,0x00}, // : + {0x16,0x00,0x00}, // ; + {0x10,0x28,0x44}, // < + {0x28,0x28,0x28}, // = + {0x44,0x28,0x10}, // > + {0x9a,0xf0,0x00}, // ? + {0x2e,0x22,0x3e}, // @ + {0xfe,0x84,0xfe}, // A + {0xfe,0xe2,0x3e}, // B + {0xfe,0x82,0xc6}, // C + {0xbe,0x82,0xfe}, // D + {0xfe,0xa2,0xa2}, // E + {0xfe,0xa0,0xa0}, // F + {0xfe,0x82,0xbe}, // G + {0xfe,0x20,0xfe}, // H + {0x82,0xfe,0x82}, // I + {0x02,0x82,0xfe}, // J + {0xfe,0x50,0xde}, // K + {0xfe,0x02,0x02}, // L + {0xfe,0x70,0xfe}, // M + {0xfe,0x80,0xfe}, // N + {0xfe,0x82,0xfe}, // O + {0xfe,0x84,0xfc}, // P + {0xfc,0x84,0xfa}, // Q + {0xfe,0x8c,0xfa}, // R + {0xe2,0xa2,0xbe}, // S + {0x80,0xfe,0x80}, // T + {0xfe,0x02,0xfe}, // U + {0xfe,0x04,0xf8}, // V + {0xfe,0x1c,0xfe}, // W + {0xde,0x70,0xde}, // X + {0xe0,0x3e,0xe0}, // Y + {0x9e,0xa2,0xc2}, // Z + {0xfe,0x82,0xff}, // [ + {0x60,0x18,0x06}, // + {0x82,0xfe,0xff}, // ] + {0x40,0x80,0x40}, // ^ + {0x02,0x02,0x02}, // _ + {0x80,0x40,0xff}, // ` + {0x2e,0x2a,0x3e}, // a + {0xfe,0x22,0x3e}, // b + {0x3e,0x22,0x22}, // c + {0x3e,0x22,0xfe}, // d + {0x3e,0x2a,0x3a}, // e + {0x20,0xfe,0xa0}, // f + {0x3a,0x2a,0x3e}, // g + {0xfe,0x20,0x3e}, // h + {0xbe,0xff,0xff}, // i + {0x02,0xbe,0xff}, // j + {0xfe,0x08,0x36}, // k + {0xfe,0x02,0xff}, // l + {0x3e,0x18,0x3e}, // m + {0x3e,0x20,0x3e}, // n + {0x3e,0x22,0x3e}, // o + {0x3e,0x24,0x3c}, // p + {0x3c,0x24,0x3e}, // q + {0x3e,0x20,0x20}, // r + {0x3a,0x2a,0x2e}, // s + {0x20,0x7e,0x22}, // t + {0x3e,0x02,0x3e}, // u + {0x3e,0x04,0x38}, // v + {0x3e,0x0c,0x3e}, // w + {0x36,0x08,0x36}, // x + {0x3a,0x0a,0x3e}, // y + {0x26,0x2a,0x32}, // z + {0x10,0xfe,0x82}, // { + {0xfe,0xff,0xff}, // | + {0x82,0xfe,0x10}, // } + {0x80,0xc0,0x40}, // ~ + {0xff,0xff,0xff}, // Full filled + {0x40,0xa0,0x40}, // ° + {0x40,0xfe,0x40}, // arrow up + {0x02,0xfe,0x02} // arrow down +}; + + +/* +12481248 + 1 + 1 +1111111 + 1 + 1 +84218421 +*/ + +#elif FONT_WIDTH == 8 + +uint8_t font[][8] = { + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x20, Space + {0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04, 0x00}, // 0x21, ! + {0x09, 0x09, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x22, " + {0x0a, 0x0a, 0x1f, 0x0a, 0x1f, 0x0a, 0x0a, 0x00}, // 0x23, # + {0x04, 0x0f, 0x14, 0x0e, 0x05, 0x1e, 0x04, 0x00}, // 0x24, $ + {0x19, 0x19, 0x02, 0x04, 0x08, 0x13, 0x13, 0x00}, // 0x25, % + {0x04, 0x0a, 0x0a, 0x0a, 0x15, 0x12, 0x0d, 0x00}, // 0x26, & + {0x04, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x27, ' + {0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02, 0x00}, // 0x28, ( + {0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00}, // 0x29, ) + {0x04, 0x15, 0x0e, 0x1f, 0x0e, 0x15, 0x04, 0x00}, // 0x2a, * + {0x00, 0x04, 0x04, 0x1f, 0x04, 0x04, 0x00, 0x00}, // 0x2b, + + {0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x08, 0x00}, // 0x2c, , + {0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00}, // 0x2d, - + {0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x00}, // 0x2e, . + {0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00}, // 0x2f, / + {0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e, 0x00}, // 0x30, 0 + {0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e, 0x00}, // 0x31, 1 + {0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1f, 0x00}, // 0x32, 2 + {0x0e, 0x11, 0x01, 0x06, 0x01, 0x11, 0x0e, 0x00}, // 0x33, 3 + {0x02, 0x06, 0x0a, 0x12, 0x1f, 0x02, 0x02, 0x00}, // 0x34, 4 + {0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e, 0x00}, // 0x35, 5 + {0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e, 0x00}, // 0x36, 6 + {0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08, 0x00}, // 0x37, 7 + {0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e, 0x00}, // 0x38, 8 + {0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c, 0x00}, // 0x39, 9 + {0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x0c, 0x00, 0x00}, // 0x3a, : + {0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x04, 0x08, 0x00}, // 0x3b, ; + {0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02, 0x00}, // 0x3c, < + {0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00}, // 0x3d, = + {0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x00}, // 0x3e, > + {0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04, 0x00}, // 0x3f, ? + {0x0e, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0f, 0x00}, // 0x40, @ + {0x04, 0x0a, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x00}, // 0x41, A + {0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e, 0x00}, // 0x42, B + {0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e, 0x00}, // 0x43, C + {0x1e, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1e, 0x00}, // 0x44, D + {0x1f, 0x10, 0x10, 0x1c, 0x10, 0x10, 0x1f, 0x00}, // 0x45, E + {0x1f, 0x10, 0x10, 0x1f, 0x10, 0x10, 0x10, 0x00}, // 0x46, F + {0x0e, 0x11, 0x10, 0x10, 0x13, 0x11, 0x0f, 0x00}, // 0x47, G + {0x11, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11, 0x00}, // 0x48, H + {0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e, 0x00}, // 0x49, I + {0x1f, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c, 0x00}, // 0x4a, J + {0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11, 0x00}, // 0x4b, K + {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1f, 0x00}, // 0x4c, L + {0x11, 0x1b, 0x15, 0x11, 0x11, 0x11, 0x11, 0x00}, // 0x4d, M + {0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11, 0x00}, // 0x4e, N + {0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00}, // 0x4f, O + {0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10, 0x00}, // 0x50, P + {0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d, 0x00}, // 0x51, Q + {0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11, 0x00}, // 0x52, R + {0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e, 0x00}, // 0x53, S + {0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00}, // 0x54, T + {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00}, // 0x55, U + {0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04, 0x00}, // 0x56, V + {0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11, 0x00}, // 0x57, W + {0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11, 0x00}, // 0x58, X + {0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04, 0x00}, // 0x59, Y + {0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1f, 0x00}, // 0x5a, Z + {0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00}, // 0x5b, [ + {0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01, 0x00}, // 0x5c, \ + {0x0e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0e, 0x00}, // 0x5d, ] + {0x04, 0x0a, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x5e, ^ + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00}, // 0x5f, _ + {0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x60, ` + {0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x60, ` ??? + {0x00, 0x0e, 0x01, 0x0d, 0x13, 0x13, 0x0d, 0x00}, // 0x61, a + {0x10, 0x10, 0x10, 0x1c, 0x12, 0x12, 0x1c, 0x00}, // 0x62, b + {0x00, 0x00, 0x00, 0x0e, 0x10, 0x10, 0x0e, 0x00}, // 0x63, c + {0x01, 0x01, 0x01, 0x07, 0x09, 0x09, 0x07, 0x00}, // 0x64, d + {0x00, 0x00, 0x0e, 0x11, 0x1f, 0x10, 0x0f, 0x00}, // 0x65, e + {0x06, 0x09, 0x08, 0x1c, 0x08, 0x08, 0x08, 0x00}, // 0x66, f + {0x0e, 0x11, 0x13, 0x0d, 0x01, 0x01, 0x0e, 0x00}, // 0x67, g + {0x10, 0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x00}, // 0x68, h + {0x00, 0x04, 0x00, 0x0c, 0x04, 0x04, 0x0e, 0x00}, // 0x69, i + {0x02, 0x00, 0x06, 0x02, 0x02, 0x12, 0x0c, 0x00}, // 0x6a, j + {0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12, 0x00}, // 0x6b, k + {0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00}, // 0x6c, l + {0x00, 0x00, 0x0a, 0x15, 0x15, 0x11, 0x11, 0x00}, // 0x6d, m + {0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11, 0x00}, // 0x6e, n + {0x00, 0x00, 0x0e, 0x11, 0x11, 0x11, 0x0e, 0x00}, // 0x6f, o + {0x00, 0x1c, 0x12, 0x12, 0x1c, 0x10, 0x10, 0x00}, // 0x70, p + {0x00, 0x07, 0x09, 0x09, 0x07, 0x01, 0x01, 0x00}, // 0x71, q + {0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10, 0x00}, // 0x72, r + {0x00, 0x00, 0x0f, 0x10, 0x0e, 0x01, 0x1e, 0x00}, // 0x73, s + {0x08, 0x08, 0x1c, 0x08, 0x08, 0x09, 0x06, 0x00}, // 0x74, t + {0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0d, 0x00}, // 0x75, u + {0x00, 0x00, 0x11, 0x11, 0x11, 0x0a, 0x04, 0x00}, // 0x76, v + {0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0a, 0x00}, // 0x77, w + {0x00, 0x00, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x00}, // 0x78, x + {0x00, 0x11, 0x11, 0x0f, 0x01, 0x11, 0x0e, 0x00}, // 0x79, y + {0x00, 0x00, 0x1f, 0x02, 0x04, 0x08, 0x1f, 0x00}, // 0x7a, z + {0x06, 0x08, 0x08, 0x10, 0x08, 0x08, 0x06, 0x00}, // 0x7b, { + {0x04, 0x04, 0x04, 0x00, 0x04, 0x04, 0x04, 0x00}, // 0x7c, | + {0x0c, 0x02, 0x02, 0x01, 0x02, 0x02, 0x0c, 0x00}, // 0x7d, } + {0x08, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, // 0x7e, ~ + {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x00}, // 0x7f, DEL + {0x44, 0xEE, 0xFE, 0x7C, 0x38, 0x10, 0x00, 0x00}, // herz groß + {0x00, 0x6C, 0x7C, 0x38, 0x10, 0x00, 0x00, 0x00}, // herz klein + + +}; + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..4fd148c --- /dev/null +++ b/src/main.c @@ -0,0 +1,159 @@ +#include +#include +#include +#include + +#include "font.h" +#include "ds1820.h" + +#define BUFLEN (8*64) + +const char *msg = "Frohe Weihnachten und einen guten Rutsch wuenscht euch Steffen"; + +volatile float temp_cur; +volatile float temp_min = 1e6; +volatile float temp_max = -1e6; + +volatile uint8_t buffer[BUFLEN] = { 0 }; +volatile uint8_t scroll = 0; +volatile uint8_t len = 0; + + +void set_buffer(char* text) { + uint8_t a = 0, b, c; + + for (c = 0; c < 8; c++) + buffer[a++] = 0; + + for (b = 0; text[b]; b++) { + for (c = 0; a < BUFLEN && c < FONT_WIDTH && font[text[b] - ' '][c] != 0xff; c++, a++) { + buffer[a] = font[text[b] - ' '][c]; + } + + buffer[a++] = 0; + } + + len = a; + + for (c = 0; c < 8; c++) + buffer[a++] = 0; +} + +void init(void) { + /* IO Ports */ + DDRB = 0xc0; /* cathodes 6..7 */ + DDRC = 0x3f; /* cathodes 0..5 */ + DDRD = 0xff; /* anodes */ + + /* Timer2 */ + TCCR2 |= (1 << WGM21) | (1 << CS22) | (1 << CS21); /* prescaler = 256 */ + TIFR |= (1 << OCF2); + OCR2 = 90; /* interrupt = ??? Hz */ + + /* Timer1 */ + TCCR1A = 0; + TCCR1B = (1 << CS12) | (1 << CS10); /* prescaler = 1024 => 0,12 Hz = 8,3s */ + TIFR |= (1 << OCF1A); + OCR1A = (1 << 13); +} + +ISR(TIMER2_COMP_vect) { + static uint8_t cnt = 100; + uint8_t row = cnt % 8; + + PORTD = 0; + + PORTB |= 0xC0; + PORTB &= ~((1 << row) & 0xC0); + PORTC = ~((1 << row) & 0x3f); + + PORTD = *(buffer+scroll+7-row); + + + if (cnt) { + cnt--; + } + else { + if (scroll == len) { + /* stop timer2 */ + TIMSK &= ~(1 << OCIE2); + + /* start timer1 */ + TCNT1 = 0; + TIFR |= (1 << OCF1A); + TIMSK |= (1 << OCIE1A); + } + else { + scroll++; + } + + cnt = 100; + } +} + +ISR(TIMER1_COMPA_vect) { + static uint16_t cnt; + static uint8_t step; + char text[120]; + + TIMSK &= ~(1 << OCIE1A); /* stop timer1 */ + + if (cnt) { + cnt--; + } + else { + step++; + step %= 6; + +// cnt = 300; + scroll = 0; + + temp_cur = ds1820_read_temp(PB2); + + /* update minimum/maximum */ + if (temp_cur > temp_max) { + temp_max = temp_cur; + } + if (temp_cur < temp_min) { + temp_min = temp_cur; + } + + switch (step) { + case 0: + case 2: + case 4: + case 6: + snprintf(text, sizeof(text), "%.1f%cC", temp_cur, 0x80); + set_buffer(text); + break; + case 1: + snprintf(text, sizeof(text), "min %.1f%cC", temp_min, 0x80); + set_buffer(text); + break; + case 3: + snprintf(text, sizeof(text), "max %.1f%cC", temp_max, 0x80); + set_buffer(text); + break; + case 5: + set_buffer(msg); + break; + } + + + TIFR |= (1 << OCF2); + TIMSK |= (1 << OCIE2); /* start timer2 */ + } +} + +int main(void) { + init(); + ds1820_init(PB2); + +// set_buffer("hallo da"); + TIMSK |= (1 << OCIE2); /* start timer2 */ + + sei(); + while (1); + + return 0; +}