adding files

This commit is contained in:
Tanish25 2022-10-04 18:52:43 +05:30
commit 63bd4b3f03
214 changed files with 6841 additions and 0 deletions

106
ADC/Makefile Normal file
View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

20
ADC/main.c Normal file
View File

@ -0,0 +1,20 @@
//ADC
#include <avr/io.h>
#define F_CPU 16000000//16MHz
int main(void)
{
DDRL = 0xff;//port L direction: output //pins- 49:42
DDRC = 0xff;//port C direction: output //pins- 37:30
DDRA = 0x00;//port A direction: input //pins- 22:29
ADCSRA = 0x87;// ADC enabled and prescaler=128
ADMUX = 0xC0;// input at ADC0// data is right-justified
while(1)
{
ADCSRA |= (1<<ADSC); //to start conversion
while(ADCSRA && (1<<ADIF)==0);// waiting for conversion to finish
PORTL = ADCL;
PORTC = ADCH;
}
}

BIN
ADC/main.elf Executable file

Binary file not shown.

21
ADC/main.hex Normal file
View File

@ -0,0 +1,21 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C949A000C94000059
:100100008FEF80930A0187B911B887E880937A004E
:1001100080EC80937C0080917A00806480937A00E8
:1001200080917A008091780080930B018091790012
:0801300088B9F1CFF894FFCF6C
:00000001FF

BIN
ADC/main.o Normal file

Binary file not shown.

20
ADC/readme.txt Normal file
View File

@ -0,0 +1,20 @@
Registers involved:
GPIO:
DDRL: Data Direction Register for Port L= 0xFF for output
DDRC: Data Direction Register for Port C= 0xFF for output
ADC:
ADCSRA: ADC Control and Status Register A = 0x87
Bit 7= 1= ADC Enabled
Bit 6= ADSC: ADC Start Conversion Bit- In Single Conversion mode, write this bit to one to start each conversion.
Bit 4= ADIF: ADC Interrupt Flag- This bit is set when an ADC conversion completes and the Data Registers are updated
Bit [2:0] = 111 = Prescaler-128
ADMUX: ADC Multiplexer = 0xC0
Bit [7:6] = 11 = Vref= 2.56V
Bit 5 = 0 = Result(10-bits-wide) is right-justified
Bit [4:0] = 00000 = Input at ADC0
ADCL: ADC Data Register Lower= stores the lower 8 bits of result of conversion
ADCH: ADC Data Register Higher= stores the higher 8 bits of result of conversion

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,20 @@
//ADC
#include <avr/io.h>
#define F_CPU 16000000//16MHz
int main(void)
{
DDRL = 0xff;//port L direction: output //pins- 49:42
DDRC = 0xff;//port C direction: output //pins- 37:30
DDRA = 0x00;//port A direction: input //pins- 22:29
ADCSRA = 0x87;// ADC enabled and prescaler=128
ADMUX = 0xC0;// input at ADC0// data is right-justified
while(1)
{
ADCSRA |= (1<<ADSC); //to start conversion
while(ADCSRA && (1<<ADIF)==0);// waiting for conversion to finish
PORTL = ADCL;
PORTC = ADCH;
}
}

Binary file not shown.

View File

@ -0,0 +1,21 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C949A000C94000059
:100100008FEF80930A0187B911B887E880937A004E
:1001100080EC80937C0080917A00806480937A00E8
:1001200080917A008091780080930B018091790012
:0801300088B9F1CFF894FFCF6C
:00000001FF

Binary file not shown.

View File

@ -0,0 +1,20 @@
Registers involved:
GPIO:
DDRL: Data Direction Register for Port L= 0xFF for output
DDRC: Data Direction Register for Port C= 0xFF for output
ADC:
ADCSRA: ADC Control and Status Register A = 0x87
Bit 7= 1= ADC Enabled
Bit 6= ADSC: ADC Start Conversion Bit- In Single Conversion mode, write this bit to one to start each conversion.
Bit 4= ADIF: ADC Interrupt Flag- This bit is set when an ADC conversion completes and the Data Registers are updated
Bit [2:0] = 111 = Prescaler-128
ADMUX: ADC Multiplexer = 0xC0
Bit [7:6] = 11 = Vref= 2.56V
Bit 5 = 0 = Result(10-bits-wide) is right-justified
Bit [4:0] = 00000 = Input at ADC0
ADCL: ADC Data Register Lower= stores the lower 8 bits of result of conversion
ADCH: ADC Data Register Higher= stores the higher 8 bits of result of conversion

View File

@ -0,0 +1,201 @@
AVR: Alf and Regards's RISC Processor
Installing AVR toolchain:
Basic requirements:
gcc-avr : a GNU C cross-compiler for specifically for AVR
avr-libc: it is a package for AVR C library
more info: https://www.nongnu.org/avr-libc/user-manual/index.html
https://exploreembedded.com/wiki/AVR_C_Library
avrdude: it is a utility that transfers codes from the UBUNTU to the microcontroller. AVR downloader uploader: software(utility program) for downloading and uploading on-chip memories of Microchip's AVR microcontrollers
arduino CLI: Arduino Command LIne Interface- Arduino CLI is a command line tool that contains all you need to easily build applications around the Arduino ecosystem.
Basic installation commands:
sudo apt-get install gcc-avr binutils-avr avr-libc
sudo apt-get install avrdude
sudo apt-get install arduino-cli or snap install arduino-cli
More info about installation: https://www.nongnu.org/avr-libc/user-manual/install_tools.html
Basic processes involved:
1)Compilation which creates object files
2)Linking the object files to create ELF files(Executable and Linkable Format)
3)Object-copy(assembly) to create hex files
4)Flashing(dumping) the hex file on the board using avrdude
more info: https://www.avrfreaks.net/forum/avr-gcc-compiling-linking-and-assembly --(pic in this website)--
Instructions to compile the code:
Compile and linking Instruction(generating object files and linking them):
avr-gcc -Os -mmcu=atmega2560 -c -o <destination_file-blinking_led> <source.c> //avoid using '-c' to avoid improper linking
Object Copy Instruction:
avr-objcopy -O ihex -R .eeprom <destination_file-blinking_led> <file_name.hex>
Programming(flashing the hex file on board):
avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -patmega2560 -cwiring -P /dev/ttyACM0 -b 115200 -D -U flash:w:<file_name.hex>:i
Execution using make:
GNU make:
The "make" utility automates the mundane aspects of building executable from source code. "make" uses a so-called makefile, which contains rules on how to build the executables. Make is different from a script as a script shows no intelligence. All instructions run blindly, without dpending on the consequences of the previous instructions.
more info: https://www3.ntu.edu.sg/home/ehchua/programming/cpp/gcc_make.html#zz-1.6
makefile youtube tutorial: https://www.youtube.com/playlist?list=PLNmACol6lYY7Dzvg7jKgvMdDaDEDFnNqD
based on the makefile created..
//change parameters accordingly in makefile to make sure the correct files get executed
Instructions:
make all
make flash
Makefile:
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf
main.c file for blinking of led code:
#include <avr/io.h>
#define F_CPU 16000000//16MHz
#define MS_DELAY 1000//1 second=1000 ms
#include <util/delay.h>
int main(void)
{
//pin 37-port C0
DDRC = 0xff;
PORTC = 0xff;
while(1)
{
PORTC = 0x01;
_delay_ms(1000);//1 second delay
PORTC = 0x00;
_delay_ms(1000);//1 second delay
}
return 0;
}

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,57 @@
//GPIO- Input Configuration
#include <avr/io.h>
#define F_CPU 16000000//16MHz
#include <util/delay.h>
int main(void)
{
//pin 37-port C0 ; C7- pin 30
DDRC = 0xff;//port C direction: output
DDRA = 0xff;//port A direction: output
DDRB = 0x00;//pin 10-13: Port B4 to B7 //direction: input
//PINB = 0x00;//clearing PINB register
//PORTA = PINB;
//while(1);
//enabling pull-up resistors//use=?//default output when pull-up enabled=high
PORTB = 0xff;
//PORTC = 0xff;
//PORTB=0x00;//disabling pull-up resistors?//does it help or not?
while(1)
{
PORTA = PINB;//PortA= pin 22-29
if(PINB==0xFF)
{
PORTC = 0x01;
_delay_ms(5);
PORTC = 0x00;
_delay_ms(5);
}//f=100Hz
else if(PINB==0x00)
{
PORTC = 0x01;
_delay_ms(10);
PORTC = 0x00;
_delay_ms(10);
}//f=50Hz
/*else if(PINB==0x10)
{
PORTC = 0x01;
_delay_ms(7);
PORTC = 0x00;
_delay_ms(7);
}//f=approx 75Hz
else if(PINB==0x20)
{
PORTC = 0x01;
_delay_ms(20);
PORTC = 0x00;
_delay_ms(20);
}//f=25Hz
*/
}
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C94AA000C94000049
:100100008FEF87B981B914B885B981E093B192B9FD
:1001100093B19F3F69F488B9EFE1FEE43197F1F7BD
:1001200000C0000018B8EFE1FEE43197F1F70FC00E
:1001300093B19111EBCF88B9EFE3FCE93197F1F777
:1001400000C0000018B8EFE3FCE93197F1F700C0F8
:080150000000DCCFF894FFCFA2
:00000001FF

Binary file not shown.

View File

@ -0,0 +1,13 @@
Registers involved:
GPIO:
DDRA: Data Direction Register for Port A= 0xFF for output (Port A- pin 22:29)
DDRB: Data Direction Register for Port B= 0x00 for input (Port B- pin 53:50[B0:B3] & pin 10:13[B4:B7] )
DDRC: Data Direction Register for Port C= 0xFF for output (Port C- pin 37:30)
PORTB: Port B Data Register
PINB: Port B Input Pins Address
About pull-up and pull-down resistors:

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,57 @@
//GPIO- Input Configuration
#include <avr/io.h>
#define F_CPU 16000000//16MHz
#include <util/delay.h>
int main(void)
{
//pin 37-port C0 ; C7- pin 30
DDRC = 0xff;//port C direction: output
DDRA = 0xff;//port A direction: output
DDRB = 0x00;//pin 10-13: Port B4 to B7 //direction: input
//PINB = 0x00;//clearing PINB register
//PORTA = PINB;
//while(1);
//enabling pull-up resistors//use=?//default output when pull-up enabled=high
PORTB = 0xff;
//PORTC = 0xff;
//PORTB=0x00;//disabling pull-up resistors?//does it help or not?
while(1)
{
PORTA = PINB;//PortA= pin 22-29
if(PINB==0xFF)
{
PORTC = 0x01;
_delay_ms(5);
PORTC = 0x00;
_delay_ms(5);
}//f=100Hz
else if(PINB==0x00)
{
PORTC = 0x01;
_delay_ms(10);
PORTC = 0x00;
_delay_ms(10);
}//f=50Hz
/*else if(PINB==0x10)
{
PORTC = 0x01;
_delay_ms(7);
PORTC = 0x00;
_delay_ms(7);
}//f=approx 75Hz
else if(PINB==0x20)
{
PORTC = 0x01;
_delay_ms(20);
PORTC = 0x00;
_delay_ms(20);
}//f=25Hz
*/
}
}

Binary file not shown.

View File

@ -0,0 +1,23 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C94AA000C94000049
:100100008FEF87B981B914B885B981E093B192B9FD
:1001100093B19F3F69F488B9EFE1FEE43197F1F7BD
:1001200000C0000018B8EFE1FEE43197F1F70FC00E
:1001300093B19111EBCF88B9EFE3FCE93197F1F777
:1001400000C0000018B8EFE3FCE93197F1F700C0F8
:080150000000DCCFF894FFCFA2
:00000001FF

Binary file not shown.

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,104 @@
#define F_CPU 16000000
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
volatile int i,j,k;
int main (void) {
//DDRB &= 0x7F;
//PORTB &= 0x7F;
DDRC = 0xff;
PORTC = 0xff;
//while(1);
PORTC = 0x00;
//PORTC pins= pins 30-37
while(1)
{
PORTC = 0xff;
// PORTC ^= 0xff;
for (i = 0; i < 500; i++)
{
for (j = 0; j < 10; j++)
{
for (k = 0; k < 10; k++);
}
}
PORTC = 0x00;
//PORTB &= 0x00;
for (i = 0; i < 500; i++)
{
for (j = 0; j < 10; j++)
{
for (k = 0; k < 10; k++);
}
}
//PORTB &= 0x00;
//PORTB |= 0x80;
}
//DDRB |= ~_BV(DDB7);
/* while(1){
//PORTB |= 0x20;
PORTB |= (0<<PB7) ;
_delay_ms(1000);
// PORTB &= ~0x20;
PORTB &= ~(0<<PB7) ;
_delay_ms(1000);
} */
/*while(1) {
//Set to one the fifth bit of PORTB to one
// Set to HIGH the pin 13
PORTB |= _BV(PORTB7);
//Wait 3000 ms
_delay_ms(MS_DELAY);
//Set to zero the fifth bit of PORTB
//Set to LOW the pin 13
PORTB &= _BV(PORTB7);
//Wait 3000 ms
_delay_ms(MS_DELAY);
}*/
}
/*
#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
int main(void)
{
DDRA = 0x01;
while(1)
{
PORTA = 0x01;
_delay_ms(1000);
PORTA = 0x00;
_delay_ms(1000);
}
return 0;
}
*/

View File

@ -0,0 +1,35 @@
:100000000C9472000C9486000C9486000C9486006C
:100010000C9486000C9486000C9486000C94860048
:100020000C9486000C9486000C9486000C94860038
:100030000C9486000C9486000C9486000C94860028
:100040000C9486000C9486000C9486000C94860018
:100050000C9486000C9486000C9486000C94860008
:100060000C9486000C9486000C9486000C948600F8
:100070000C9486000C9486000C9486000C948600E8
:100080000C9486000C9486000C9486000C948600D8
:100090000C9486000C9486000C9486000C948600C8
:1000A0000C9486000C9486000C9486000C948600B8
:1000B0000C9486000C9486000C9486000C948600A8
:1000C0000C9486000C9486000C9486000C94860098
:1000D0000C9486000C9486000C9486000C94860088
:1000E0000C94860011241FBECFEFD1E2DEBFCDBF3E
:1000F00000E00CBF22E0A0E0B2E001C01D92A630FB
:10010000B207E1F70E9488000C940A010C940000E9
:100110008FEF87B988B918B82FEF28B91092050268
:10012000109204028091040290910502843F914054
:1001300094F51092010210920002809100029091B9
:1001400001020A97F4F410920302109202028091C5
:100150000202909103020A9754F480910202909156
:10016000030201969093030280930202F0CF8091E4
:100170000002909101020196909301028093000287
:10018000DCCF8091040290910502019690930502C4
:1001900080930402C7CF18B810920502109204028F
:1001A0008091040290910502843F91400CF0B5CFFC
:1001B00010920102109200028091000290910102BF
:1001C0000A97F4F410920302109202028091020244
:1001D000909103020A9754F48091020290910302D5
:1001E00001969093030280930202F0CF8091000267
:1001F0009091010201969093010280930002DCCF5E
:1002000080910402909105020196909305028093DB
:080210000402C6CFF894FFCFF1
:00000001FF

View File

@ -0,0 +1,6 @@
F_CPU= 16000000= To set clock frequency as 16MHz
MS_DELAY= 1000= To set value 1000 as equivalent to 1 second
Registers Involved:
DDRC: Data Direction Register for Port C= 0xFF for output
PORTC: Port C Data Register= Data written here is observed in the corresponding output pins(Port C= pin 37:30)

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = inbuilt_delay
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,22 @@
#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
int main(void)
{
//pin 37-port C0
DDRC = 0xff;
PORTC = 0xff;
while(1)
{
PORTC = 0x01;
_delay_ms(20000);
PORTC = 0x00;
_delay_ms(20000);
}
return 0;
}
//name of file is toggle_inbuilt and accordingly changes have been made in makefile

View File

@ -0,0 +1,21 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9499000C9400005A
:100100008FEF87B988B981E088B92FEF38E09DE398
:10011000215030409040E1F700C0000018B82FEFA8
:1001200038E09DE3215030409040E1F700C00000EE
:06013000EBCFF894FFCFB5
:00000001FF

View File

@ -0,0 +1,23 @@
#include <avr/io.h>
#define F_CPU 16000000//16MHz
#define MS_DELAY 1000//1 second=1000 ms
#include <util/delay.h>
int main(void)
{
//pin 37-port C0
DDRC = 0xff;
PORTC = 0xff;
while(1)
{
PORTC = 0x01;
_delay_ms(1000);//1 second delay
PORTC = 0x00;
_delay_ms(1000);//1 second delay
}
return 0;
}
//name of file is toggle_inbuilt and accordingly changes have been made in makefile

View File

@ -0,0 +1,21 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9499000C9400005A
:100100008FEF87B988B981E088B92FE734E89EE19D
:10011000215030409040E1F700C0000018B82FE7B0
:1001200034E89EE1215030409040E1F700C00000EB
:06013000EBCFF894FFCFB5
:00000001FF

View File

@ -0,0 +1,9 @@
F_CPU= 16000000= To set clock frequency as 16MHz
MS_DELAY= 1000= To set value 1000 as equivalent to 1 second
Registers Involved:
DDRC: Data Direction Register for Port C= 0xFF for output
PORTC: Port C Data Register= Data written here is observed in the corresponding output pins(Port C= pin 37:30)
in-built function used: _delay_ms()
This function takes in "compiler-time" constants as a parameter,which defines the delay in milliseconds

View File

@ -0,0 +1,106 @@
# simple AVR Makefile
#
# written by michael cousins (http://github.com/mcous)
# released to the public domain
# Makefile
#
# targets:
# all: compiles the source code
# test: tests the isp connection to the mcu
# flash: writes compiled hex file to the mcu's flash memory
# fuse: writes the fuse bytes to the MCU
# disasm: disassembles the code for debugging
# clean: removes all .hex, .elf, and .o files in the source code and library directories
# parameters (change this stuff accordingly)
# project name
PRJ = main
# avr mcu
MCU = atmega2560
# mcu clock frequency
CLK = 16000000
# avr programmer (and port if necessary)
# e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
PRG = wiring -P /dev/ttyACM0
# fuse values for avr: low, high, and extended
# these values are from an Arduino Uno (ATMega328P)
# see http://www.engbedded.com/fusecalc/ for other MCUs and options
LFU = 0xFF
HFU = 0xD0
EFU = 0xFD
# program source files (not including external libraries)
SRC = $(PRJ).c
# where to look for external libraries (consisting of .c/.cpp files and .h files)
# e.g. EXT = ../../EyeToSee ../../YouSART
EXT =
#################################################################################################
# \/ stuff nobody needs to worry about until such time that worrying about it is appropriate \/ #
#################################################################################################
# include path
INCLUDE := $(foreach dir, $(EXT), -I$(dir))
# c flags
CFLAGS = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
# any aditional flags for c++
CPPFLAGS =
# executables
AVRDUDE = avrdude -C /usr/share/arduino/hardware/tools/avrdude.conf -c $(PRG) -p $(MCU) -b 115200 -D
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size --format=avr --mcu=$(MCU)
CC = avr-gcc
# generate list of objects
CFILES = $(filter %.c, $(SRC))
EXTC := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
CPPFILES = $(filter %.cpp, $(SRC))
EXTCPP := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
OBJ = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)
# user targets
# compile all files
all: $(PRJ).hex
# test programmer connectivity
test:
$(AVRDUDE) -v
# flash program to mcu
flash: all
$(AVRDUDE) -U flash:w:$(PRJ).hex:i
# write fuses to mcu
fuse:
$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m
# generate disassembly files for debugging
disasm: $(PRJ).elf
$(OBJDUMP) -d $(PRJ).elf
# remove compiled files
clean:
rm -f *.hex *.elf *.o
$(foreach dir, $(EXT), rm -f $(dir)/*.o;)
# other targets
# objects from c files
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# objects from c++ files
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# elf file
$(PRJ).elf: $(OBJ)
$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)
# hex file
$(PRJ).hex: $(PRJ).elf
rm -f $(PRJ).hex
$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex
$(SIZE) $(PRJ).elf

View File

@ -0,0 +1,50 @@
#define F_CPU 16000000
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
volatile int i,j,k;
int main (void) {
//DDRB &= 0x7F;
//PORTB &= 0x7F;
DDRC = 0xff;
PORTC = 0xff;
//while(1);
PORTC = 0x00;
//PORTC pins= pins 30-37
while(1)
{
PORTC = 0xff;
for (i = 0; i < 5; i++)
{