mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 13:41:13 +00:00
Added VERY old code. Very cringy to look at, but hey, we all had to start somewhere...
This commit is contained in:
@@ -0,0 +1,335 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Wunderboard Makefile Template written by Dan Albert
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Target file name.
|
||||
TARGET = main
|
||||
|
||||
# List C source files here.
|
||||
SRC = $(TARGET).c \
|
||||
|
||||
# MCU name, you MUST set this to match the board you are using
|
||||
# type "make clean" after changing this, so all files will be rebuilt
|
||||
MCU = at90usb646
|
||||
|
||||
# Detect platform
|
||||
UNAME = $(shell uname)
|
||||
|
||||
ifeq ($(UNAME),Linux)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifndef ENV
|
||||
ENV=windows
|
||||
endif
|
||||
|
||||
ifeq ($(ENV),unix)
|
||||
PROGRAM = dfu-programmer
|
||||
PROGRAMFLAGS = $(MCU)
|
||||
ERASE = erase
|
||||
FLASH = flash "$(TARGET).hex"
|
||||
START = start
|
||||
else
|
||||
PROGRAM = "C:/Program Files (x86)/Atmel/Flip 3.4.1/bin/batchisp.exe"
|
||||
PROGRAMFLAGS = -device at90usb646 -hardware USB
|
||||
ERASE = -operation erase F
|
||||
FLASH = -operation loadbuffer "$(TARGET).hex" program verify
|
||||
START = -operation start noreset 0
|
||||
endif
|
||||
|
||||
# Processor frequency.
|
||||
# Normally the first thing your program should do is set the clock prescaler,
|
||||
# so your program will run at the correct speed. You should also set this
|
||||
# variable to same clock speed. The _delay_ms() macro uses this, and many
|
||||
# examples use this variable to calculate timings. Do not add a "UL" here.
|
||||
F_CPU = 8000000
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
|
||||
# Object files directory
|
||||
# To put object files in current directory, use a dot (.), do NOT make
|
||||
# this an empty or blank macro!
|
||||
OBJDIR = obj
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
#---------------- Compiler Options C ----------------
|
||||
# -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 += $(CDEFS)
|
||||
CFLAGS += -O$(OPT)
|
||||
CFLAGS += -funsigned-char
|
||||
CFLAGS += -funsigned-bitfields
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fpack-struct
|
||||
CFLAGS += -fshort-enums
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
#CFLAGS += -mshort-calls
|
||||
#CFLAGS += -fno-unit-at-a-time
|
||||
#CFLAGS += -Wundef
|
||||
#CFLAGS += -Wunreachable-code
|
||||
#CFLAGS += -Wsign-compare
|
||||
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
CFLAGS += $(CSTANDARD)
|
||||
|
||||
#---------------- 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 = $(PRINTF_LIB_MIN)
|
||||
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
||||
|
||||
# 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 = $(SCANF_LIB_MIN)
|
||||
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
||||
|
||||
MATH_LIB = -lm
|
||||
|
||||
# List any extra directories to look for libraries 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.
|
||||
EXTRALIBDIRS =
|
||||
|
||||
#---------------- 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 += -Wl,--relax
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||
#LDFLAGS += -T linker_script.x
|
||||
|
||||
|
||||
#============================================================================
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
CC = avr-gcc
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
AR = avr-ar rcs
|
||||
NM = avr-nm
|
||||
REMOVE = rm -f
|
||||
REMOVEDIR = rm -rf
|
||||
COPY = cp
|
||||
WINSHELL = cmd
|
||||
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_ERRORS_NONE = Errors: none
|
||||
MSG_BEGIN = -------- begin --------
|
||||
MSG_END = -------- end --------
|
||||
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_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling C:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
MSG_CREATING_LIBRARY = Creating library:
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||
|
||||
# Default target.
|
||||
all: begin gccversion sizebefore build sizeafter end
|
||||
|
||||
# Change the build target to build a HEX file or a library.
|
||||
build: elf hex eep lss sym
|
||||
#build: lib
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
eep: $(TARGET).eep
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
LIBNAME=lib$(TARGET).a
|
||||
lib: $(LIBNAME)
|
||||
|
||||
# Eye candy.
|
||||
# AVR Studio 3.x does not check make's exit code but relies on
|
||||
# the following magic strings to be generated by the compile job.
|
||||
begin:
|
||||
@echo
|
||||
@echo $(MSG_BEGIN)
|
||||
|
||||
end:
|
||||
@echo $(MSG_END)
|
||||
@echo
|
||||
|
||||
# Display size of file.
|
||||
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
|
||||
|
||||
sizebefore:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
sizeafter:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
# Display compiler version information.
|
||||
gccversion :
|
||||
@$(CC) --version
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH) $@
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||
|
||||
%.eep: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EEPROM) $@
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S -z $< > $@
|
||||
|
||||
# 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) $^ --output $@ $(LDFLAGS)
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
$(OBJDIR)/%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
%.s : %.c
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
## Program
|
||||
.PHONY: program
|
||||
program: all
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(ERASE)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(FLASH)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(START)
|
||||
|
||||
doxygen:
|
||||
doxygen
|
||||
|
||||
# Target: clean project.
|
||||
clean: begin clean_list end
|
||||
|
||||
clean_list :
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).eep
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).sym
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
$(REMOVE) $(SRC:.c=.s)
|
||||
$(REMOVE) $(SRC:.c=.d)
|
||||
$(REMOVEDIR) .dep
|
||||
$(REMOVEDIR) $(OBJDIR)
|
||||
|
||||
# Create object files directory
|
||||
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||
build elf hex eep lss sym \
|
||||
clean clean_list
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
@file main.c
|
||||
@brief Lab 6 Starter Code
|
||||
@version .01
|
||||
@mainpage Lab 6 Starter Code
|
||||
|
||||
@section intro Code Overview
|
||||
This first lab allows outputs to the LED array and single patteren of lights. You need to revise it so that it outputs lights based on the input from the switches.
|
||||
|
||||
@section hw Hardware Pin Out
|
||||
PORTA:
|
||||
Switches A7 - A0
|
||||
|
||||
PORTB:
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/** Includes */
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
/** Constants */
|
||||
#define F_CPU 1000000U
|
||||
|
||||
/** Global Variables */
|
||||
|
||||
/** Functions */
|
||||
|
||||
/** The initialize() function initializes all of the Data Direction Registers for the Wunderboard. Before making changes to DDRx registers, ensure that you have read the peripherals section of the Wunderboard user guide.*/
|
||||
void initialize (void) {
|
||||
/** Port A is the switches and buttons. They should always be inputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRA=0b00000000;
|
||||
|
||||
/** Port B has the LED Array color control, SD card, and audio-out on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRB=0b11000000;
|
||||
|
||||
/** Port C is for the 'row' of the LED array. They should always be outputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRC=0b11111111;
|
||||
|
||||
/** Port D has the Serial on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRD=0b00000000;
|
||||
|
||||
/** Port E has the LED Array Column control out on it. Leave DDRE alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRE=0b00000111;
|
||||
|
||||
/** Port F has the accelerometer and audio-in on it. Leave DDRF alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRF=0b00000000;
|
||||
}
|
||||
|
||||
void clearArray(void)
|
||||
{
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
PORTC = 0x00;
|
||||
PORTB |= (1 << PB6) | (1 << PB7); // Enable latches
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
}
|
||||
|
||||
/** Main Function */
|
||||
|
||||
int main (void) {
|
||||
/** Local Varibles */
|
||||
unsigned char temp;
|
||||
unsigned char switches;
|
||||
|
||||
initialize();
|
||||
clearArray();
|
||||
|
||||
while(1){
|
||||
PORTB = 0b10000000; //Sets the green leds on
|
||||
PORTC = PINA; //Sets led values to the switch values
|
||||
}
|
||||
|
||||
}//main
|
||||
@@ -0,0 +1,335 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Wunderboard Makefile Template written by Dan Albert
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Target file name.
|
||||
TARGET = main
|
||||
|
||||
# List C source files here.
|
||||
SRC = $(TARGET).c \
|
||||
|
||||
# MCU name, you MUST set this to match the board you are using
|
||||
# type "make clean" after changing this, so all files will be rebuilt
|
||||
MCU = at90usb646
|
||||
|
||||
# Detect platform
|
||||
UNAME = $(shell uname)
|
||||
|
||||
ifeq ($(UNAME),Linux)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifndef ENV
|
||||
ENV=windows
|
||||
endif
|
||||
|
||||
ifeq ($(ENV),unix)
|
||||
PROGRAM = dfu-programmer
|
||||
PROGRAMFLAGS = $(MCU)
|
||||
ERASE = erase
|
||||
FLASH = flash "$(TARGET).hex"
|
||||
START = start
|
||||
else
|
||||
PROGRAM = "C:/Program Files (x86)/Atmel/Flip 3.4.1/bin/batchisp.exe"
|
||||
PROGRAMFLAGS = -device at90usb646 -hardware USB
|
||||
ERASE = -operation erase F
|
||||
FLASH = -operation loadbuffer "$(TARGET).hex" program verify
|
||||
START = -operation start noreset 0
|
||||
endif
|
||||
|
||||
# Processor frequency.
|
||||
# Normally the first thing your program should do is set the clock prescaler,
|
||||
# so your program will run at the correct speed. You should also set this
|
||||
# variable to same clock speed. The _delay_ms() macro uses this, and many
|
||||
# examples use this variable to calculate timings. Do not add a "UL" here.
|
||||
F_CPU = 8000000
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
|
||||
# Object files directory
|
||||
# To put object files in current directory, use a dot (.), do NOT make
|
||||
# this an empty or blank macro!
|
||||
OBJDIR = obj
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
#---------------- Compiler Options C ----------------
|
||||
# -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 += $(CDEFS)
|
||||
CFLAGS += -O$(OPT)
|
||||
CFLAGS += -funsigned-char
|
||||
CFLAGS += -funsigned-bitfields
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fpack-struct
|
||||
CFLAGS += -fshort-enums
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
#CFLAGS += -mshort-calls
|
||||
#CFLAGS += -fno-unit-at-a-time
|
||||
#CFLAGS += -Wundef
|
||||
#CFLAGS += -Wunreachable-code
|
||||
#CFLAGS += -Wsign-compare
|
||||
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
CFLAGS += $(CSTANDARD)
|
||||
|
||||
#---------------- 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 = $(PRINTF_LIB_MIN)
|
||||
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
||||
|
||||
# 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 = $(SCANF_LIB_MIN)
|
||||
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
||||
|
||||
MATH_LIB = -lm
|
||||
|
||||
# List any extra directories to look for libraries 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.
|
||||
EXTRALIBDIRS =
|
||||
|
||||
#---------------- 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 += -Wl,--relax
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||
#LDFLAGS += -T linker_script.x
|
||||
|
||||
|
||||
#============================================================================
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
CC = avr-gcc
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
AR = avr-ar rcs
|
||||
NM = avr-nm
|
||||
REMOVE = rm -f
|
||||
REMOVEDIR = rm -rf
|
||||
COPY = cp
|
||||
WINSHELL = cmd
|
||||
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_ERRORS_NONE = Errors: none
|
||||
MSG_BEGIN = -------- begin --------
|
||||
MSG_END = -------- end --------
|
||||
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_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling C:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
MSG_CREATING_LIBRARY = Creating library:
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||
|
||||
# Default target.
|
||||
all: begin gccversion sizebefore build sizeafter end
|
||||
|
||||
# Change the build target to build a HEX file or a library.
|
||||
build: elf hex eep lss sym
|
||||
#build: lib
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
eep: $(TARGET).eep
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
LIBNAME=lib$(TARGET).a
|
||||
lib: $(LIBNAME)
|
||||
|
||||
# Eye candy.
|
||||
# AVR Studio 3.x does not check make's exit code but relies on
|
||||
# the following magic strings to be generated by the compile job.
|
||||
begin:
|
||||
@echo
|
||||
@echo $(MSG_BEGIN)
|
||||
|
||||
end:
|
||||
@echo $(MSG_END)
|
||||
@echo
|
||||
|
||||
# Display size of file.
|
||||
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
|
||||
|
||||
sizebefore:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
sizeafter:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
# Display compiler version information.
|
||||
gccversion :
|
||||
@$(CC) --version
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH) $@
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||
|
||||
%.eep: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EEPROM) $@
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S -z $< > $@
|
||||
|
||||
# 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) $^ --output $@ $(LDFLAGS)
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
$(OBJDIR)/%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
%.s : %.c
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
## Program
|
||||
.PHONY: program
|
||||
program: all
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(ERASE)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(FLASH)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(START)
|
||||
|
||||
doxygen:
|
||||
doxygen
|
||||
|
||||
# Target: clean project.
|
||||
clean: begin clean_list end
|
||||
|
||||
clean_list :
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).eep
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).sym
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
$(REMOVE) $(SRC:.c=.s)
|
||||
$(REMOVE) $(SRC:.c=.d)
|
||||
$(REMOVEDIR) .dep
|
||||
$(REMOVEDIR) $(OBJDIR)
|
||||
|
||||
# Create object files directory
|
||||
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||
build elf hex eep lss sym \
|
||||
clean clean_list
|
||||
177
OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 7/main.c
Normal file
177
OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 7/main.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
@file main.c
|
||||
@brief Lab 6 Starter Code
|
||||
@version .01
|
||||
@mainpage Lab 6 Starter Code
|
||||
|
||||
@section intro Code Overview
|
||||
This first lab allows outputs to the LED array and single patteren of lights. You need to revise it so that it outputs lights based on the input from the switches.
|
||||
|
||||
@section hw Hardware Pin Out
|
||||
PORTA:
|
||||
Switches A7 - A0
|
||||
|
||||
PORTB:
|
||||
|
||||
*/
|
||||
|
||||
/** Includes */
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
/** Constants */
|
||||
#define F_CPU 1000000U
|
||||
#define DELAY .01
|
||||
/** Global Variables */
|
||||
|
||||
/** Functions */
|
||||
|
||||
/** The initialize() function initializes all of the Data Direction Registers for the Wunderboard. Before making changes to DDRx registers, ensure that you have read the peripherals section of the Wunderboard user guide.*/
|
||||
void initialize (void) {
|
||||
/** Port A is the switches and buttons. They should always be inputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRA=0b00000000;
|
||||
|
||||
/** Port B has the LED Array color control, SD card, and audio-out on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRB=0b11000000;
|
||||
|
||||
/** Port C is for the 'row' of the LED array. They should always be outputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRC=0b11111111;
|
||||
|
||||
/** Port D has the Serial on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRD=0b00000000;
|
||||
|
||||
/** Port E has the LED Array Column control out on it. Leave DDRE alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRE=0b00000111;
|
||||
|
||||
/** Port F has the accelerometer and audio-in on it. Leave DDRF alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRF=0b00000000;
|
||||
}
|
||||
|
||||
void clearArray(void)
|
||||
{
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
PORTC = 0x00;
|
||||
PORTB |= (1 << PB6) | (1 << PB7); // Enable latches
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
}
|
||||
|
||||
/** Main Function */
|
||||
|
||||
int main (void) {
|
||||
/** Local Varibles */
|
||||
//char red[8];
|
||||
//char green[8];
|
||||
char loop;
|
||||
|
||||
initialize();
|
||||
clearArray();
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
if (PINA == 0b01110000){
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b11000000;
|
||||
|
||||
PORTE = 0b00000011;
|
||||
PORTC = 0b11011010;
|
||||
_delay_ms(DELAY);
|
||||
clearArray();
|
||||
|
||||
|
||||
}else if (PINA == 0b10110000){
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b11000000;
|
||||
|
||||
PORTE = 0b00000011;
|
||||
PORTC = 0b01010101;
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b11000000;
|
||||
PORTE = 0b00000110;
|
||||
PORTC = 0b10101010;
|
||||
_delay_ms(DELAY);
|
||||
clearArray();
|
||||
|
||||
|
||||
}else if (PINA == 0b11010000){
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b10000000;
|
||||
|
||||
PORTE = 0b00000011;
|
||||
PORTC = 0b01010101;
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b01000000;
|
||||
|
||||
PORTE = 0b00000110;
|
||||
PORTC = 0b10101010;
|
||||
_delay_ms(DELAY);
|
||||
clearArray();
|
||||
|
||||
|
||||
}else if (PINA == 0b11111000){
|
||||
char red[8] = {0b10000000, 0b01000000, 0b00100000, 0b00010000, 0b00001000, 0b00000100, 0b00000010, 0b00000001};
|
||||
char green[8] = {0b01111000, 0b10111100, 0b11011110, 0b11101111, 0b11110111, 0b01111011, 0b00111101, 0b00011110};
|
||||
char orange[8] = {0b00000111, 0b00000011, 0b00000001, 0b00000000, 0b00000000, 0b10000000, 0b11000000, 0b11100000};
|
||||
|
||||
clearArray();
|
||||
|
||||
for ( loop = 0 ; loop < 8 ; loop++ ){
|
||||
|
||||
PORTB = 0b01000000;
|
||||
PORTE = loop;
|
||||
PORTC = red[loop];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b10000000;
|
||||
PORTC = green[loop];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b11000000;
|
||||
PORTC = orange[loop];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
}
|
||||
|
||||
}else if (PINA == 0b11100000){
|
||||
char red[8] = {0b11111111, 0b01110111, 0b00100010,0b00000000, 0b00000000, 0b00100010, 0b01110111, 0b11111111};
|
||||
char green[8] = {0b00000000, 0b10001000, 0b11011101, 0b11111111, 0b11111111, 0b11011101, 0b10001000, 0b00000000};
|
||||
|
||||
clearArray();
|
||||
|
||||
for ( loop = 0 ; loop < 8 ; loop++ ){
|
||||
|
||||
PORTB = 0b01000000;
|
||||
PORTE = loop;
|
||||
PORTC = red[loop];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB = 0b10000000;
|
||||
PORTC = green[loop];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//main
|
||||
@@ -0,0 +1,336 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Wunderboard Makefile Template written by Dan Albert
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# make all = Make software.
|
||||
#
|
||||
# make clean = Clean out built project files.
|
||||
#
|
||||
# make filename.s = Just compile filename.c into the assembler code only.
|
||||
#
|
||||
# To rebuild project do "make clean" then "make all".
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# Target file name.
|
||||
TARGET = main
|
||||
|
||||
# List C source files here.
|
||||
SRC = $(TARGET).c \
|
||||
adc.c
|
||||
|
||||
# MCU name, you MUST set this to match the board you are using
|
||||
# type "make clean" after changing this, so all files will be rebuilt
|
||||
MCU = at90usb646
|
||||
|
||||
# Detect platform
|
||||
UNAME = $(shell uname)
|
||||
|
||||
ifeq ($(UNAME),Linux)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME),Darwin)
|
||||
ENV=unix
|
||||
endif
|
||||
|
||||
ifndef ENV
|
||||
ENV=windows
|
||||
endif
|
||||
|
||||
ifeq ($(ENV),unix)
|
||||
PROGRAM = dfu-programmer
|
||||
PROGRAMFLAGS = $(MCU)
|
||||
ERASE = erase
|
||||
FLASH = flash "$(TARGET).hex"
|
||||
START = start
|
||||
else
|
||||
PROGRAM = "C:/Program Files (x86)/Atmel/Flip 3.4.1/bin/batchisp.exe"
|
||||
PROGRAMFLAGS = -device at90usb646 -hardware USB
|
||||
ERASE = -operation erase F
|
||||
FLASH = -operation loadbuffer "$(TARGET).hex" program verify
|
||||
START = -operation start noreset 0
|
||||
endif
|
||||
|
||||
# Processor frequency.
|
||||
# Normally the first thing your program should do is set the clock prescaler,
|
||||
# so your program will run at the correct speed. You should also set this
|
||||
# variable to same clock speed. The _delay_ms() macro uses this, and many
|
||||
# examples use this variable to calculate timings. Do not add a "UL" here.
|
||||
F_CPU = 8000000
|
||||
|
||||
# Output format. (can be srec, ihex, binary)
|
||||
FORMAT = ihex
|
||||
|
||||
# Object files directory
|
||||
# To put object files in current directory, use a dot (.), do NOT make
|
||||
# this an empty or blank macro!
|
||||
OBJDIR = obj
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
#---------------- Compiler Options C ----------------
|
||||
# -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 += $(CDEFS)
|
||||
CFLAGS += -O$(OPT)
|
||||
CFLAGS += -funsigned-char
|
||||
CFLAGS += -funsigned-bitfields
|
||||
CFLAGS += -ffunction-sections
|
||||
CFLAGS += -fpack-struct
|
||||
CFLAGS += -fshort-enums
|
||||
CFLAGS += -Wall
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
#CFLAGS += -mshort-calls
|
||||
#CFLAGS += -fno-unit-at-a-time
|
||||
#CFLAGS += -Wundef
|
||||
#CFLAGS += -Wunreachable-code
|
||||
#CFLAGS += -Wsign-compare
|
||||
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
|
||||
CFLAGS += $(CSTANDARD)
|
||||
|
||||
#---------------- 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 = $(PRINTF_LIB_MIN)
|
||||
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
|
||||
|
||||
# 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 = $(SCANF_LIB_MIN)
|
||||
#SCANF_LIB = $(SCANF_LIB_FLOAT)
|
||||
|
||||
MATH_LIB = -lm
|
||||
|
||||
# List any extra directories to look for libraries 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.
|
||||
EXTRALIBDIRS =
|
||||
|
||||
#---------------- 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 += -Wl,--relax
|
||||
LDFLAGS += -Wl,--gc-sections
|
||||
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
|
||||
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
|
||||
#LDFLAGS += -T linker_script.x
|
||||
|
||||
|
||||
#============================================================================
|
||||
|
||||
# Define programs and commands.
|
||||
SHELL = sh
|
||||
CC = avr-gcc
|
||||
OBJCOPY = avr-objcopy
|
||||
OBJDUMP = avr-objdump
|
||||
SIZE = avr-size
|
||||
AR = avr-ar rcs
|
||||
NM = avr-nm
|
||||
REMOVE = rm -f
|
||||
REMOVEDIR = rm -rf
|
||||
COPY = cp
|
||||
WINSHELL = cmd
|
||||
|
||||
|
||||
# Define Messages
|
||||
# English
|
||||
MSG_ERRORS_NONE = Errors: none
|
||||
MSG_BEGIN = -------- begin --------
|
||||
MSG_END = -------- end --------
|
||||
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_EXTENDED_LISTING = Creating Extended Listing:
|
||||
MSG_SYMBOL_TABLE = Creating Symbol Table:
|
||||
MSG_LINKING = Linking:
|
||||
MSG_COMPILING = Compiling C:
|
||||
MSG_ASSEMBLING = Assembling:
|
||||
MSG_CLEANING = Cleaning project:
|
||||
MSG_CREATING_LIBRARY = Creating library:
|
||||
|
||||
# Define all object files.
|
||||
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
|
||||
# Define all listing files.
|
||||
LST = $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
|
||||
# Compiler flags to generate dependency files.
|
||||
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
|
||||
|
||||
# Combine all necessary flags and optional flags.
|
||||
# Add target processor to flags.
|
||||
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
|
||||
|
||||
# Default target.
|
||||
all: begin gccversion sizebefore build sizeafter end
|
||||
|
||||
# Change the build target to build a HEX file or a library.
|
||||
build: elf hex eep lss sym
|
||||
#build: lib
|
||||
|
||||
elf: $(TARGET).elf
|
||||
hex: $(TARGET).hex
|
||||
eep: $(TARGET).eep
|
||||
lss: $(TARGET).lss
|
||||
sym: $(TARGET).sym
|
||||
LIBNAME=lib$(TARGET).a
|
||||
lib: $(LIBNAME)
|
||||
|
||||
# Eye candy.
|
||||
# AVR Studio 3.x does not check make's exit code but relies on
|
||||
# the following magic strings to be generated by the compile job.
|
||||
begin:
|
||||
@echo
|
||||
@echo $(MSG_BEGIN)
|
||||
|
||||
end:
|
||||
@echo $(MSG_END)
|
||||
@echo
|
||||
|
||||
# Display size of file.
|
||||
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
|
||||
ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
|
||||
|
||||
sizebefore:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
sizeafter:
|
||||
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
|
||||
2>/dev/null; echo; fi
|
||||
|
||||
# Display compiler version information.
|
||||
gccversion :
|
||||
@$(CC) --version
|
||||
|
||||
# Create final output files (.hex, .eep) from ELF output file.
|
||||
%.hex: %.elf
|
||||
@echo
|
||||
@echo $(MSG_FLASH) $@
|
||||
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@
|
||||
|
||||
%.eep: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EEPROM) $@
|
||||
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
|
||||
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
|
||||
|
||||
# Create extended listing file from ELF output file.
|
||||
%.lss: %.elf
|
||||
@echo
|
||||
@echo $(MSG_EXTENDED_LISTING) $@
|
||||
$(OBJDUMP) -h -S -z $< > $@
|
||||
|
||||
# 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) $^ --output $@ $(LDFLAGS)
|
||||
|
||||
# Compile: create object files from C source files.
|
||||
$(OBJDIR)/%.o : %.c
|
||||
@echo
|
||||
@echo $(MSG_COMPILING) $<
|
||||
$(CC) -c $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
# Compile: create assembler files from C source files.
|
||||
%.s : %.c
|
||||
$(CC) -S $(ALL_CFLAGS) $< -o $@
|
||||
|
||||
## Program
|
||||
.PHONY: program
|
||||
program: all
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(ERASE)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(FLASH)
|
||||
$(PROGRAM) $(PROGRAMFLAGS) $(START)
|
||||
|
||||
doxygen:
|
||||
doxygen
|
||||
|
||||
# Target: clean project.
|
||||
clean: begin clean_list end
|
||||
|
||||
clean_list :
|
||||
@echo
|
||||
@echo $(MSG_CLEANING)
|
||||
$(REMOVE) $(TARGET).hex
|
||||
$(REMOVE) $(TARGET).eep
|
||||
$(REMOVE) $(TARGET).elf
|
||||
$(REMOVE) $(TARGET).map
|
||||
$(REMOVE) $(TARGET).sym
|
||||
$(REMOVE) $(TARGET).lss
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
|
||||
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
|
||||
$(REMOVE) $(SRC:.c=.s)
|
||||
$(REMOVE) $(SRC:.c=.d)
|
||||
$(REMOVEDIR) .dep
|
||||
$(REMOVEDIR) $(OBJDIR)
|
||||
|
||||
# Create object files directory
|
||||
$(shell mkdir $(OBJDIR) 2>/dev/null)
|
||||
|
||||
# Include the dependency files.
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# Listing of phony targets.
|
||||
.PHONY : all begin finish end sizebefore sizeafter gccversion \
|
||||
build elf hex eep lss sym \
|
||||
clean clean_list
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
@file adc.c
|
||||
@brief Wunderboard ADC Helper Functions
|
||||
@version .01
|
||||
|
||||
@section intro Code Overview
|
||||
This is the code for the Wunderboard ADC helper functions.
|
||||
*/
|
||||
|
||||
#include "adc.h"
|
||||
|
||||
unsigned char read_adc(uint8_t channel){
|
||||
|
||||
unsigned char test;
|
||||
|
||||
ADMUX = 0x60 | channel; // Set the channel to the one we want
|
||||
ADCSRA = 0b11000110; // Start a new sample.
|
||||
while ((ADCSRA & 0b00010000) == 0 ); // Wait for a Valid Sample
|
||||
ADCSRA |= 0b00010000; // Tell ADC you have the sample you want.
|
||||
ADCSRA |= 0b01000000; // Start a new sample.
|
||||
while ((ADCSRA & 0b00010000) == 0 ); // Wait for a Valid Sample
|
||||
ADCSRA |= 0b00010000; // Tell ADC you have the sample you want.
|
||||
|
||||
test = ADCH;
|
||||
ADCSRA = 0x00; // Disable the ADC
|
||||
|
||||
return (test);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
@file adc.h
|
||||
@brief Wunderboard ADC Helper Functions
|
||||
@version .01
|
||||
|
||||
@section intro Code Overview
|
||||
This is the code for the Wunderboard ADC helper functions.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
/**
|
||||
The read_adc() function allows for taking 8 bit measurements from any of the single ended ADC inputs. The function call is blocking. eg. read_adc(5) would read from ADC channel 5.
|
||||
@param channel This is the channel to be read.
|
||||
@return This is the return value from the ADC.
|
||||
*/
|
||||
|
||||
unsigned char read_adc(uint8_t channel);
|
||||
|
||||
189
OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 8/main.c
Normal file
189
OSU Coursework/CS 161 - Intro to Programming I/Labs/Lab 8/main.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
@file main.c
|
||||
@brief Lab 8 Starter Code
|
||||
@version .01
|
||||
@mainpage Lab 8 Starter Code
|
||||
|
||||
@section intro Code Overview
|
||||
|
||||
@section hw Hardware Pin Out
|
||||
Port A:
|
||||
A0 - A3 : Push Buttons
|
||||
A4 - A7 : Slide Switches
|
||||
|
||||
Port B:
|
||||
B0 - B3 : SPI (SD Card)
|
||||
B4 : Nothing
|
||||
B5 : Audio Out
|
||||
B6 : Red Enable
|
||||
B7 : Green Enable
|
||||
|
||||
Port C:
|
||||
C0 - C7 : LED Array (Row)
|
||||
|
||||
Port D:
|
||||
D0 - D1 : Nothing
|
||||
D2 : Serial RX
|
||||
D3 : Serial TX
|
||||
D4 - D7 : Nothing
|
||||
|
||||
Port E:
|
||||
E0 - E2 : LED Array (Column)
|
||||
E3 : USB (UID)
|
||||
E4 - E5 : Nothing
|
||||
E6 : Relay
|
||||
E7 : Nothing
|
||||
|
||||
Port F:
|
||||
F0 : ADC Channel 0
|
||||
F1 : ADC Channel 1
|
||||
F2 : ADC Channel 2
|
||||
F3 : ADC Channel 3
|
||||
F4 : ADC Channel 4 (Audio In)
|
||||
F5 : ADC Channel 5 (Accel X Axis)
|
||||
F6 : ADC Channel 6 (Accel Y Axis)
|
||||
F7 : ADC Channel 7 (Accel Z Axis (if installed))
|
||||
|
||||
*/
|
||||
|
||||
/** Includes */
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "adc.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
/** Constants */
|
||||
#define F_CPU 1000000U
|
||||
#define DELAY .02
|
||||
|
||||
#define YMIN 180.0
|
||||
#define STEPSIZE 1.375
|
||||
/** Global Variables */
|
||||
|
||||
/** Functions */
|
||||
|
||||
/** The initialize() function initializes all of the Data Direction Registers for the Wunderboard. Before making changes to DDRx registers, ensure that you have read the peripherals section of the Wunderboard user guide.*/
|
||||
void initialize (void) {
|
||||
/** Port A is the switches and buttons. They should always be inputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRA=0b00000000;
|
||||
|
||||
/** Port B has the LED Array color control, SD card, and audio-out on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRB=0b11000000;
|
||||
|
||||
/** Port C is for the 'row' of the LED array. They should always be outputs. ( 0 = Input and 1 = Output )*/
|
||||
DDRC=0b11111111;
|
||||
|
||||
/** Port D has the Serial on it. Leave DDRB alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRD=0b00000000;
|
||||
|
||||
/** Port E has the LED Array Column control out on it. Leave DDRE alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRE=0b00000111;
|
||||
|
||||
/** Port F has the accelerometer and audio-in on it. Leave DDRF alone. ( 0 = Input and 1 = Output )*/
|
||||
DDRF=0b00000000;
|
||||
}
|
||||
|
||||
void clearArray(void)
|
||||
{
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
PORTC = 0x00;
|
||||
PORTB |= (1 << PB6) | (1 << PB7); // Enable latches
|
||||
PORTB &= ~((1 << PB6) | (1 << PB7)); // Disable latches
|
||||
}
|
||||
|
||||
int readadcval(void){
|
||||
int loop4;
|
||||
int adcreturn;
|
||||
char adcread = read_adc(5);
|
||||
|
||||
for(loop4 = 0 ; loop4 < 16 ; loop4++){
|
||||
if(((YMIN + (loop4*STEPSIZE)) <= adcread) & (adcread < (YMIN + ((loop4 + 1)*STEPSIZE)))){
|
||||
adcreturn = 2*loop4;
|
||||
}
|
||||
}
|
||||
return adcreturn;
|
||||
}
|
||||
|
||||
/** Main Function */
|
||||
|
||||
int main (void) {
|
||||
/** Local Varibles */
|
||||
int loop = 50;
|
||||
int loop2;
|
||||
int loop3;
|
||||
int speed = 20;
|
||||
int *speedpoint = &speed;
|
||||
|
||||
const int Red[120] = {0b00000000, 0b00000000, 0b01000000, 0b11000000, 0b01000000, 0b00000000, 0b00000000, 0b00001000, 0b00000000, 0b00001000, 0b00101000, 0b00001000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b10000000, 0b11000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001000, 0b00000000, 0b00000000, 0b01000000, 0b11000000, 0b11100000, 0b01000000, 0b00000000, 0b00000100, 0b00000100, 0b00010000, 0b00010000, 0b00010000, 0b00010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00010000, 0b00010100, 0b00000000, 0b00000000, 0b01001000, 0b11001000, 0b11000000, 0b10000000, 0b00001000, 0b00000000, 0b00101000, 0b00000000, 0b00001000, 0b00000000, 0b00000000, 0b00100000, 0b00100000, 0b00000000, 0b00000000, 0b00101000, 0b00100000, 0b00000000, 0b00000000, 0b00000010, 0b00000110, 0b00001110, 0b00000000, 0b00001110, 0b00000110, 0b01000010, 0b11000000, 0b01000000, 0b00000010, 0b00000110, 0b00001110, 0b00001110, 0b00000000, 0b00001110, 0b00000110, 0b00000010, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00001000, 0b00001000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000010, 0b00000110, 0b00001110, 0b00011110, 0b00011110, 0b00000000, 0b01000000, 0b11100000, 0b11100010, 0b01000000, 0b00000000, 0b00001110, 0b00111110, 0b00011000, 0b00111110, 0b00001110};
|
||||
const int Green[120] = {0b00000001, 0b00000001, 0b01000001, 0b11000001, 0b01000001, 0b00000001, 0b00000001, 0b00001001, 0b00000001, 0b00001001, 0b00101001, 0b00001001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b10000111, 0b11000111, 0b01000001, 0b00000001, 0b00000001, 0b00001111, 0b00001111, 0b00000001, 0b00000001, 0b00001111, 0b00001111, 0b00000001, 0b00000001, 0b00001111, 0b00001111, 0b00000001, 0b00000001, 0b00001001, 0b00000001, 0b00000001, 0b01000001, 0b11000001, 0b11100000, 0b01000000, 0b00000001, 0b00000101, 0b00000101, 0b00010001, 0b00010001, 0b00010001, 0b00010001, 0b00000001, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00010001, 0b00010101, 0b00000001, 0b00000001, 0b01001001, 0b11001001, 0b11000001, 0b10000001, 0b00001001, 0b00000001, 0b00101001, 0b00000001, 0b00001001, 0b00000001, 0b00000001, 0b00100001, 0b00100001, 0b00000001, 0b00000001, 0b00101001, 0b00100001, 0b00000001, 0b00000001, 0b00000011, 0b00000111, 0b00001111, 0b00000001, 0b00001111, 0b00000111, 0b01000011, 0b11000001, 0b01000001, 0b00000011, 0b00000111, 0b00001111, 0b00001111, 0b00000000, 0b00001111, 0b00000111, 0b00000011, 0b00000001, 0b00000111, 0b00000111, 0b00000001, 0b00000001, 0b00001001, 0b00001001, 0b00000001, 0b00000001, 0b00000001, 0b00000111, 0b00000111, 0b00000011, 0b00000111, 0b00001111, 0b00011111, 0b00011111, 0b00000001, 0b01000001, 0b11100001, 0b11100011, 0b01000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001};
|
||||
|
||||
initialize();
|
||||
clearArray();
|
||||
|
||||
while(1){
|
||||
|
||||
speedpoint = 25;
|
||||
|
||||
for(loop ; loop >= 0 ; loop--){
|
||||
speedpoint = readadcval();
|
||||
|
||||
if(speedpoint == 0){
|
||||
while(speedpoint == 0){
|
||||
for(loop2 = 0 ; loop2 < 150 ; loop2++){
|
||||
for(loop3 = 7 ; loop3 > -1 ; loop3--){
|
||||
|
||||
|
||||
int arrval;
|
||||
clearArray();
|
||||
PORTE = loop3;
|
||||
arrval = (loop+loop3);
|
||||
|
||||
PORTB = 0b10000000;
|
||||
PORTC = Green[arrval];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB= 0b01000000;
|
||||
PORTC = Red[arrval];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
}
|
||||
}
|
||||
speedpoint = readadcval();
|
||||
}
|
||||
}else{
|
||||
for(loop2 = 0 ; loop2 < speedpoint ; loop2++){
|
||||
for(loop3 = 7 ; loop3 > -1 ; loop3--){
|
||||
|
||||
|
||||
int arrval;
|
||||
clearArray();
|
||||
PORTE = loop3;
|
||||
arrval = (loop+loop3);
|
||||
|
||||
PORTB = 0b10000000;
|
||||
PORTC = Green[arrval];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
|
||||
PORTB= 0b01000000;
|
||||
PORTC = Red[arrval];
|
||||
_delay_ms(DELAY);
|
||||
|
||||
clearArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(loop == 0){
|
||||
loop = 112;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user