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++)
{
for (j = 0; j < 100; j++)
{
for (k = 0; k < 100; k++);
}
}
PORTC = 0x00;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 100; j++)
{
for (k = 0; k < 100; k++);
}
}
}
}

View File

@ -0,0 +1,35 @@
:100000000C9472000C9486000C9486000C9486006C
:100010000C9486000C9486000C9486000C94860048
:100020000C9486000C9486000C9486000C94860038
:100030000C9486000C9486000C9486000C94860028
:100040000C9486000C9486000C9486000C94860018
:100050000C9486000C9486000C9486000C94860008
:100060000C9486000C9486000C9486000C948600F8
:100070000C9486000C9486000C9486000C948600E8
:100080000C9486000C9486000C9486000C948600D8
:100090000C9486000C9486000C9486000C948600C8
:1000A0000C9486000C9486000C9486000C948600B8
:1000B0000C9486000C9486000C9486000C948600A8
:1000C0000C9486000C9486000C9486000C94860098
:1000D0000C9486000C9486000C9486000C94860088
:1000E0000C94860011241FBECFEFD1E2DEBFCDBF3E
:1000F00000E00CBF22E0A0E0B2E001C01D92A630FB
:10010000B207E1F70E9488000C940C010C940000E7
:100110008FEF87B988B918B82FEF28B91092050268
:100120001092040280910402909105020597A4F5B3
:10013000109201021092000280910002909101023F
:1001400084369105FCF41092030210920202809111
:100150000202909103028436910554F480910202C8
:100160009091030201969093030280930202EFCFD5
:100170008091000290910102019690930102809378
:100180000002DACF809104029091050201969093CB
:10019000050280930402C6CF18B81092050210928F
:1001A0000402809104029091050205970CF0B5CFEE
:1001B00010920102109200028091000290910102BF
:1001C00084369105FCF41092030210920202809191
:1001D0000202909103028436910554F48091020248
:1001E0009091030201969093030280930202EFCF55
:1001F00080910002909101020196909301028093F8
:100200000002DACF8091040290910502019690934A
:0C021000050280930402C5CFF894FFCFD4
: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)
delay designed:
Delay is implemented by running nested for-loops. We are using the fact that [5*100*100 = 50000] blank instructions induces approximately a delay of 0.06 seconds

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,105 @@
#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;
while(1)
{
//toggling pin 37
PORTC = 0x01;
// 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
:100110008FEF87B988B918B821E028B91092050285
:10012000109204028091040290910502843F914054
:1001300094F51092010210920002809100029091B9
:1001400001020A97F4F410920302109202028091C5
:100150000202909103020A9754F480910202909156
:10016000030201969093030280930202F0CF8091E4
:100170000002909101020196909301028093000287
:10018000DCCF8091040290910502019690930502C4
:1001900080930402C7CF18B810920502109204028F
:1001A0008091040290910502843F91400CF0B5CFFC
:1001B00010920102109200028091000290910102BF
:1001C0000A97F4F410920302109202028091020244
:1001D000909103020A9754F48091020290910302D5
:1001E00001969093030280930202F0CF8091000267
:1001F0009091010201969093010280930002DCCF5E
:1002000080910402909105020196909305028093DB
:080210000402C6CFF894FFCFF1
:00000001FF

View File

@ -0,0 +1,11 @@
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)
'Only' Pin PC0 is toggled to 1 by setting PORTC= 0x01
delay designed:
Delay is implemented by running nested for-loops. We are using the fact that [500*10*10 = 50000] blank instructions induces approximately a delay of 0.06 seconds

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,21 @@
#include <avr/io.h>
#define F_CPU 16000000//16MHz
int main(void)
{
DDRA=0xFF;//Port A Output
DDRB=0xFF;//Port B Output
PORTD=0xFF;//activate pull-up
while(1)
{
TCCR1A=0x00;//Normal mode
TCCR1B=0x41;//rising edge, no pre-scaler, no noise canceller
//while(TIFR1 && (1<<ICF1)==0);//
//TIFR1=(1<<ICF1);//clear ICF1
while(TIFR1 && 0x20 == 0x00);//waiting for ICF1 Flag to be set
//ICF1=0;//why not this command?
TIFR1=(1<<ICF1);
PORTA=ICR1L;//
PORTB=ICR1H;//
}
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9493000C94000060
:100100008FEF81B984B98BB921E490E2109280001D
:100110002093810086B396BB8091860082B980913E
:0A012000870085B9F3CFF894FFCFF4
:00000001FF

Binary file not shown.

View File

@ -0,0 +1,28 @@
Registers involved:
GPIO:
DDRA: Data Direction Register for Port A= 0xFF for output
DDRB: Data Direction Register for Port B= 0xFF for output
PORTD: Port D Data Register= set as 0xFF to activate pull up registers
Input Capture Unit(ICU):
TCCR1A: Timer/Counter 1 Control Register A = 0x00 for normal mode of opearation
TCCR1B: Timer/Counter 1 Control Register B = 0x41
Bit 7= ICNCn = ICU Noise Canceller= 0-Disabled
Bit 6= ICU Capture Edge select bit: when the ICESn bit is written to one, a rising (positive) edge will trigger the capture.
Bit [2:0] = 001 = Prescaler-1(i.e. no clock division)
TIFR1: Timer/Counter1 Interrupt Flag Register
Bit 5= ICF1= Timer/Counter Input Capture Flag 1
This flag is set when a capture event occurs on the ICP1 pin. When the Input Capture Register (ICR1) is set by the
WGM1[3:0] to be used as the TOP value, the ICF1 Flag is set when the counter reaches the TOP value.
ICR1L: Input Capture Register 1 Lower= stores the lower 8 bits of result
ICR1H: Input Capture Register 1 Higher= stores the higher 8 bits of result

View File

@ -0,0 +1,14 @@
Analysis using LEDs:
1)Determination of Time Constant:
The exact time constant cant be determined visually given that the persistence of vision for a human eye is around 60ms. This is the effect of the same principle used in movies, where frames are loaded at a speed higher than that which the human eye can perceive. The blinking of the LED was still perceived at a time period of around 200ms and then gradually it became more difficult to perceive the blinking. The theoretical time constant of an LED is somewhere around 100ms.
2)When frequency is set at 1 kHz, and duty cycle is varied.. the intensity of glow is proportional to the duty cycle. The blinking can't be observed as this frequency is higher than that which the human eye can perceive. The persistence of vision for a normal human eye is around 16 Hz = 0.0625 seconds = 62.5 ms.
3)Determination of internal resistance of the LED:
Output pin on the arduino gives an output voltage of around 5V
Resistance connected with the LED:
Current passing through the LED:
max current LED can tolerate:
Resistance offered within the board(if any):

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,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 @@
// self-designed PWM with inbuilt_delay for proper measure of frequency
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int i,j,k,l;
int p,q,duty_cycle,frequency;
int time;
float x,y;
int main (void) {
DDRC = 0xff;
PORTC = 0xff;
//Enter duty cycle in percentage(preferably integer)
int duty_cycle=50;
//Enter frequency in Hz(preferably integer)
int frequency=1;
//computing time-period in seconds
time=1000/frequency;
x=duty_cycle*time*0.01;
y=(100-duty_cycle)*time*0.01;
p=(int)x;
q=(int)y;
//while(1);
PORTC = 0x00;
//PORTC pins= pins 30-37
while(1)
{
PORTC = 0xff;
_delay_ms(1); //_delay_ms(p);
PORTC = 0x00;
_delay_ms(1); //_delay_ms(q);
}
}
//given that we need a compile-time constant for delay_ms, user-defined input can't be used in this program

View File

@ -0,0 +1,26 @@
:100000000C9472000C9486000C9486000C9486006C
:100010000C9486000C9486000C9486000C94860048
:100020000C9486000C9486000C9486000C94860038
:100030000C9486000C9486000C9486000C94860028
:100040000C9486000C9486000C9486000C94860018
:100050000C9486000C9486000C9486000C94860008
:100060000C9486000C9486000C9486000C948600F8
:100070000C9486000C9486000C9486000C948600E8
:100080000C9486000C9486000C9486000C948600D8
:100090000C9486000C9486000C9486000C948600C8
:1000A0000C9486000C9486000C9486000C948600B8
:1000B0000C9486000C9486000C9486000C948600A8
:1000C0000C9486000C9486000C9486000C94860098
:1000D0000C9486000C9486000C9486000C94860088
:1000E0000C94860011241FBECFEFD1E2DEBFCDBF3E
:1000F00000E00CBF22E0A0E0B2E001C01D92AA31F6
:10010000B207E1F70E9488000C94C0000C94000034
:100110008FEF87B988B988EE93E0909311028093AE
:10012000100289E29CE5ABE1B3EC8093040290936A
:100130000502A0930602B0930702809312029093E7
:100140001302A0931402B093150285E69FEF9093DB
:10015000010280930002909319028093180218B84C
:100160008FEF88B9EFE9FFE03197F1F700C00000A9
:1001700018B8EFE9FFE03197F1F700C00000F1CFC8
:04018000F894FFCF21
:00000001FF

View File

@ -0,0 +1,24 @@
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)
Variables Involved:
int i,j,k,l= counting variables if loops are to be used
int duty_cycle= duty cycle in percentage
int frequency= frequency in integer
int time= stores reciprocal of frequency
x,y= to store parameters to be used in delay functions
p,q= to store values of x and y in integer format
Note of caution:
This board generally cant handle floating point values, best to avoid them. Type-casting also may or may not work, generally good to avoid.
Note: This program gives an idea about how to process user-defined delay. But this value cant be used in the pre-defined delay function as it takes in inly compile-time constants. This user-defined delay can be used as a parameter in functions which arent pre-defined, but in those which are mostly self-designed
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,76 @@
// self-designed PWM with rough estimate of frequency
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
volatile int i,j,k,l;
volatile int p,q,duty_cycle,frequency;
float x,y;
//assuming 1 delay function covers 0.01 seconds
/*void delay(void)
{
for (i = 0; i < 1; i++)
{
for (j = 0; j < 100; j++)
{
for (k = 0; k < 100; k++);
}
}
}
*/
//assuming 1 delay function covers 0.0001 seconds
void delay(void)
{
for (i = 0; i < 1; i++)
{
for (j = 0; j < 10; j++)
{
for (k = 0; k < 10; k++);
}
}
}
int main (void) {
DDRC = 0xff;
PORTC = 0xff;
//Enter duty cycle in percentage(preferably integer)
int duty_cycle=10;
//Enter frequency in Hz(preferably integer)
int frequency=1;
x=duty_cycle*(1/frequency);//*(1/6);//1/6 is an adjusting factor
y=(10-duty_cycle)*(1/frequency);//*(1/6);
p=(int)x;
q=(int)y;
//while(1);
PORTC = 0x00;
//PORTC pins= pins 30-37
while(1)
{
//for(int i=1;i<11;i++)
//{
PORTC = 0xff;
for(l=0;l<p;l++)
{
delay();
}
PORTC = 0x00;
for(l=0;l<q;l++)
{
delay();
}//}
}
}

View File

@ -0,0 +1,38 @@
:100000000C9472000C9486000C9486000C9486006C
:100010000C9486000C9486000C9486000C94860048
:100020000C9486000C9486000C9486000C94860038
:100030000C9486000C9486000C9486000C94860028
:100040000C9486000C9486000C9486000C94860018
:100050000C9486000C9486000C9486000C94860008
:100060000C9486000C9486000C9486000C948600F8
:100070000C9486000C9486000C9486000C948600E8
:100080000C9486000C9486000C9486000C948600D8
:100090000C9486000C9486000C9486000C948600C8
:1000A0000C9486000C9486000C9486000C948600B8
:1000B0000C9486000C9486000C9486000C948600A8
:1000C0000C9486000C9486000C9486000C94860098
:1000D0000C9486000C9486000C9486000C94860088
:1000E0000C94860011241FBECFEFD1E2DEBFCDBF3E
:1000F00000E00CBF22E0A0E0B2E001C01D92A831F8
:10010000B207E1F70E94C6000C9421010C94000094
:1001100010920F0210920E0280910E0290910F0227
:100120001816190694F1109203021092020280919F
:100130000202909103020A97F4F410920D021092B9
:100140000C0280910C0290910D020A9754F4809158
:100150000C0290910D02019690930D0280930C0277
:10016000F0CF8091020290910302019690930302D6
:1001700080930202DCCF80910E0290910F020196D3
:1001800090930F0280930E02C7CF08958FEF87B927
:1001900088B980E090E0A0E2B1E4809304029093FB
:1001A0000502A0930602B09307021092100210926B
:1001B000110210921202109213028AE090E09093C2
:1001C000010280930002109217021092160218B8D2
:1001D000CFEFC8B910920B0210920A0220910A02C6
:1001E00030910B028091000290910102281739078B
:1001F00064F40E94880080910A0290910B0201969B
:1002000090930B0280930A02E9CF18B810920B0268
:1002100010920A0220910A0230910B02809116027C
:100220009091170228173907A4F60E948800809140
:100230000A0290910B02019690930B0280930A029E
:06024000E9CFF894FFCFA6
:00000001FF

View File

@ -0,0 +1,21 @@
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)
Variables Involved:
int i,j,k,l= counting variables if loops are to be used
int duty_cycle= duty cycle in percentage
int frequency= frequency in integer
int time= stores reciprocal of frequency
float x,y= to store parameters to be used in delay functions
int p,q= to store values of x and y in integer format
Note of caution:
This board generally cant handle floating point values, best to avoid them. Type-casting also may or may not work, generally good to avoid.
function designed: delay()
Delay is implemented by running nested for-loops. We are using the fact that [x] blank instructions induces approximately a delay of 1.2*10^(-6) seconds

View File

@ -0,0 +1,108 @@
# 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,15 @@
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0xFF;//Port B set as output
//DDRB |= (1 <<3);//Port B set as output
OCR0A= 0xBF;//75 percent of 255=duty cycle
TCCR0A = 0x83;//non-inverting pwm
TCCR0B = 0x03;//prescaler = 64
//output of pwm is at pin 13(OC0)
while(1);
}

View File

@ -0,0 +1,19 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9489000C9400006A
:100100008FEF84B98FEB87BD83E884BD83E085BD25
:06011000FFCFF894FFCFC1
:00000001FF

View File

@ -0,0 +1,15 @@
Registers involved:
GPIO:
DDRB: Data Direction Register for Port B= 0xFF for output
PWM Module:
OCR0A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC0A(pin 13) in this case] gets toggled
TCCR0A: Timer/Counter 0 Control Register A = 0x83
Bit [7:6]= COM0A-Compare Output Mode A = 10-Non-inverting PWM-Clear OC0A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for non-inverting fast PWM.
TCCR0B: Timer/Counter 0 Control Register B = 0x03
Bit [2:0] CS0[2:0]-Clock Select = 011- for prescaler=64 in order to obtain frequency of 1kHz

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,21 @@
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0xFF;//Port B set as output
OCR0A= 0xBF;//75 percent of 255=duty cycle
TCCR0A = 0x83;
TCCR0B = 0x03;//prescaler = 64 for 1kHz
//output at OC0A=pin 13
OCR2A= 0xBF;//duty cycle= 25 percent, value= 0.75*255
TCCR2A = 0xC3;//inverting PWM
TCCR2B = 0x04;//prescaler = 64 for 1 kHz
//output at OC2A=pin 10
while(1);
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9491000C94000062
:100100008FEF84B98FEB87BD93E894BD93E095BDE5
:100110008093B30083EC8093B00084E08093B100BF
:06012000FFCFF894FFCFB1
:00000001FF

View File

@ -0,0 +1,24 @@
Registers involved:
GPIO:
DDRB: Data Direction Register for Port B= 0xFF for output
PWM Module:
OCR0A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC0A(pin 13) in this case] gets toggled
TCCR0A: Timer/Counter 0 Control Register A = 0x83
Bit [7:6]= COM0A-Compare Output Mode A = 10-Non-inverting PWM-Clear OC0A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for non-inverting fast PWM.
TCCR0B: Timer/Counter 0 Control Register B = 0x03
Bit [2:0] CS0[2:0]-Clock Select = 011- for prescaler=64 in order to obtain frequency of 1kHz
OCR2A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC2A(pin 10) in this case] gets toggled
TCCR2A: Timer/Counter 2 Control Register A = 0xC3
Bit [7:6]= COM0A-Compare Output Mode A = 11-Inverting PWM-Clear OC2A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for fast PWM.
TCCR2B: Timer/Counter 2 Control Register B = 0x04
Bit [2:0] CS0[2:0]-Clock Select = 100- for prescaler=64 in order to obtain frequency of 1kHz

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,21 @@
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0xFF;//Port B set as output
OCR0A= 0x7F;//50 percent of 255=duty cycle
TCCR0A = 0x83;
TCCR0B = 0x03;//prescaler = 64 for 1kHz
//output at OC0A=pin 13
OCR2A= 0x87;//duty cycle= 47 percent, value= 0.53*255=135
TCCR2A = 0xC3;//inverting PWM
TCCR2B = 0x04;//prescaler = 64 for 1 kHz
//output at OC2A=pin 10
while(1);
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9492000C94000061
:100100008FEF84B98FE787BD83E884BD83E085BD29
:1001100087E88093B30083EC8093B00084E0809301
:08012000B100FFCFF894FFCFFE
:00000001FF

View File

@ -0,0 +1,34 @@
Registers involved:
GPIO:
DDRB: Data Direction Register for Port B= 0xFF for output
PWM Module:
OCR0A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC0A(pin 13) in this case] gets toggled
TCCR0A: Timer/Counter 0 Control Register A = 0x83
Bit [7:6]= COM0A-Compare Output Mode A = 10-Non-inverting PWM-Clear OC0A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for non-inverting fast PWM.
TCCR0B: Timer/Counter 0 Control Register B = 0x03
Bit [2:0] CS0[2:0]-Clock Select = 011- for prescaler=64 in order to obtain frequency of 1kHz
OCR2A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC2A(pin 10) in this case] gets toggled. The value given here is such that the duty cycle is 47 percent, a little less than 50 percent. This change in duty cycle is done in order to induce deadtime in the inverted signal.
TCCR2A: Timer/Counter 2 Control Register A = 0xC3
Bit [7:6]= COM0A-Compare Output Mode A = 11-Inverting PWM-Clear OC2A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for fast PWM.
TCCR2B: Timer/Counter 2 Control Register B = 0x04
Bit [2:0] CS0[2:0]-Clock Select = 100- for prescaler=64 in order to obtain frequency of 1kHz
The concept of Deadtime:
One of the main problems in pulse width modulated voltage source inverter (PWM-VSI) drives is the nonlinear voltage
gain caused by non-ideal characteristics of the power inverter.
The most important nonlinearity is caused by the necessary
blanking time between top and bottom switch to avoid inverter
leg shoot-through of the DC bus circuit. The type of the switch
and pre-driver characteristics determine amount of the
necessary blank time.

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,26 @@
//sinusoidal PWM
#define F_CPU 16000000//16Mhz
#define MS_DELAY 1000
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = 0xFF;//Port B set as output
//DDRB |= (1 <<3);//Port B(0:3) set as output
while(1)
{
for(int i=0;i<10;i++)
{
OCR0A= 0x00 + i*25;//75 percent of 255=duty cycle
TCCR0A = 0x83;//non-inverting pwm
TCCR0B = 0x03;//prescaler = 64
//output of pwm is at pin 13(OC0)
_delay_ms(500);
}
}
}

View File

@ -0,0 +1,20 @@
:100000000C9472000C947E000C947E000C947E0084
:100010000C947E000C947E000C947E000C947E0068
:100020000C947E000C947E000C947E000C947E0058
:100030000C947E000C947E000C947E000C947E0048
:100040000C947E000C947E000C947E000C947E0038
:100050000C947E000C947E000C947E000C947E0028
:100060000C947E000C947E000C947E000C947E0018
:100070000C947E000C947E000C947E000C947E0008
:100080000C947E000C947E000C947E000C947E00F8
:100090000C947E000C947E000C947E000C947E00E8
:1000A0000C947E000C947E000C947E000C947E00D8
:1000B0000C947E000C947E000C947E000C947E00C8
:1000C0000C947E000C947E000C947E000C947E00B8
:1000D0000C947E000C947E000C947E000C947E00A8
:1000E0000C947E0011241FBECFEFD1E2DEBFCDBF46
:1000F00000E00CBF0E9480000C9495000C9400005E
:100100008FEF84B993E823E080E087BD94BD25BDDF
:100110003FEF49E658E1315040405040E1F700C020
:0E0120000000875E8A3F89F7EFCFF894FFCF8B
:00000001FF

View File

@ -0,0 +1,20 @@
Registers involved:
GPIO:
DDRB: Data Direction Register for Port B= 0xFF for output
PWM Module:
OCR0A: Output Compare Register A=Value here is compared with the Timer value,and when the value matches, the specific pin[pin OC0A(pin 13) in this case] gets toggled
TCCR0A: Timer/Counter 0 Control Register A = 0x83
Bit [7:6]= COM0A-Compare Output Mode A = 10-Non-inverting PWM-Clear OC0A on Compare Match
Bit [1:0]= WGM[1:0]- Waveform Generation Mode=11- for non-inverting fast PWM.
TCCR0B: Timer/Counter 0 Control Register B = 0x03
Bit [2:0] CS0[2:0]-Clock Select = 011- for prescaler=64 in order to obtain frequency of 1kHz
The PWM runs in a loop with duty-cycle varying(i.e. changing value of OCR0A) such that the mean value follows a sinusoidal pattern. This function maybe helpful in AC generators.
inbuilt delay function used to induce a delay of 0.5 seconds before the duty cycle of the PWM changes

View File

@ -0,0 +1 @@
# ATMega_2560_Embedded_RnD_2

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

Binary file not shown.

View File

@ -0,0 +1,50 @@
//#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#define BAUDRATE 115200L
#define SERIAL_FORMAT_8N1 0x06
FILE* uart_init(void);
static int uart_putc(char c, FILE *stream);
static FILE outfile = FDEV_SETUP_STREAM(uart_putc, NULL, _FDEV_SETUP_WRITE);
int main(void)
{
stdout = uart_init();
DDRB |= (1<<DDB7);
while(1)
{
PORTB |= (1<<PORTB7);
_delay_ms(1000);
printf("hello\n");
PORTB &= ~ (1<<PORTB7);
_delay_ms(1000);
printf("world\n");
}
}
FILE* uart_init(void)
{
/* configure UART0 baudrate */
UBRR0H = 0;
UBRR0L = (uint8_t) (F_CPU / 4 / BAUDRATE - 1) / 2;
/* set UART0 control and status registers (UCSR0x) */
UCSR0A |= (1 << U2X0); /* double the transmission speed */
UCSR0B |= (1 << TXEN0);
UCSR0C = SERIAL_FORMAT_8N1;
return &outfile;
}
static int uart_putc(char c, FILE *stream)
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = (uint8_t)c;
return c;
}

Some files were not shown because too many files have changed in this diff Show More