You arrive to the point where the value of i is o.
i >= 0 is true.
You try to decrement with i--. Perhaps, you are expecting a negative number. But i is unsigned, so you get 255.
It keep decrementing until you get to zero. Then everything repeats again.
If i were signed, then the loop would make 9 iterations.
The following code does not have this ill ...
You are using a resistor voltage divider to power your MCU. Bad. Bad bad. You need a proper regulator. Or a USB (IE 5v) power supply. Heck, use 3 AA batteries instead of a 9v if you don't have a regulator. The ATMega line can take what, 2.5 to 5v normal range? You have nothing that really depends on a full 5v, no clock sensitive/dependent code....
Before reflashing any Atmel AVR MCU you need to erase it. Erase procedure by default clears FLASH, EEPROM and lock bits. There are 2 ways to solve your issue:
Read EEPROM, erase all, program all including your backed-up EEPROM.
Set EESAVE fuse bit. In this case EEPROM will not be erased during Erase procedure. But you will need to clear this flag some day ...
Wow, that's pretty crazy. Those programs are almost identical. Just for easier comparison, the first program, with the assignment in main, has the assembly (with comments):
0: 20 9a sbi 0x04, 0 ; Set Bit of IO for DDRB
2: 28 9a sbi 0x05, 0 ; Set Bit of IO for PORTB
4: 00 c0 rjmp .+0 ; Relative JuMP of 0 bytes ...
To answer the first question, the bootloader is needed because your program is built in such a way that it depends on the bootloader residing at the reset address of the processor, and then having the bootloader jump to your program. It's a function of how the linker script and the run-time code is set up for the Arduino environment.
I don't know the ...
I am not sure what your level of experience with ATmegas is (though reading the datasheet is a good sign!), so I'll start with something very basic, skip down if this is useless:
The term "programmer" in this context can refer to two different things:
Software. In your case it is avrdude.
Hardware. The piece of hardware that sits between the software ...
If you turn on verbose output in the preferences of the IDE, you can see the full command line that the IDE uses to run avrdude.
The verbose output will also let you see what temporary directory is being used for the hex file, so you can grab it.
No, it does not matter. There are several cases:
The LED works: in this case the resistor will limit the current flow, and does not matter if it is before or after, since it is connected serial.
The LED does not work:
Electricity flows through the LED: it would go through the resistor anyway, either if it is before or after the LED.
Electricity does not ...
SOLVED IT! For some reason the AVR ships with the lock bits enabled!? According to the datasheet this is how it is specified. Erasing the chip disables the lock bits and enabled me to program the fuses.
ARM microcontroller development is a little more complex. But, only really because DIP packages are generally not available.
If you're willing to use a development board, ARM development can be even easier.
The mbed is an ARM microcontroller on a breadboardable DIP shaped board.
The C/C++ compiler is web based and the board appears as a USB mass storage ...
a) either buy an LPC1114 (DIP28W), solder an ARM chip onto an appropriate DIP bereakout board, or buy a ready-made header board
b) connect the appropriate pins to an appropriate programmer. for most LPC chips an usb-to-3v3-serial converter will do
c) compile your program using an appropriate toolchain. Codesourcery is my favourite. Forget about asm, switch ...
Have a look at mbed. It uses an online IDE, so you're not restricted to Windows; any platform which offers a browser will do. You simply drag your compiled code to the mbed controller which appears as a USB storage device on your computer.
Software to install: zero. Hardware requirements: a USB port.
From you script it looks like you are using an STK500 board. You can use the STK500 to do high voltage programming with the attiny chips, so you can always reset the mcu to the factory defaults.
There are certain things you won't be able to fix with your script, for example if you set DWEN or disable the reset functionality, you won't be able to use the ISP ...
From the documentation:
Specify the bit clock period for the JTAG interface or the ISP
clock (JTAG ICE only). The value is a floating-point number in
microseconds. The default value of the JTAG ICE results in about
1 microsecond bit clock period, suitable for target MCUs running
at 4 MHz clock and above. ...
You are using IDE 1.0.1. Most probably the problem is with the stk500v2 protocol used for uploading to Arduino Mega. It's changed to more reliable 'wiring' protocol in v.1.0.2.
You shouldn't downgrade but upgrade to a latest version. http://arduino.cc/en/main/software
I believe this could be accomplished from the commandline as below (and thus could easily be turned into a script). This is not a fully tested answer, and I will update it as progress happens, either via my testing or others' verification.
First get avrdude (minimum files: avrdude.conf, avrdude.exe, and libusb0.dll).
Then from the commandline, run ...
Assuming everything is hooked up correctly, target microcontroller is turned on, then...
ISP mkII is running too fast for target device. (shouldn't be a problem out of the box I dont think, but if the target is running slower it can be. The -B flag can be used to slow it down, I'm not sure how it works with the mk2, though.
Target has no clock - fuses have ...
The ATmega16A is a revision of the ATmega16. According to the AVRdude documentation, the part number for the ATmega16 is "m16" (but you can also use the full part name).
Try atmega16 or m16 and leave off the "a".
Disabling the reset means game over for serial programming because it is used to enter ISP mode.
ATmega without reset can be accessed only by a programmer which can do high-voltage parallel programming, such as the AVR Dragon. If that micro is soldered in a circuit, it is highly inconvenient method and usually not worth the effort.
Assuming you already have a binary file for flashing, this page may help you. All you need to do is:
Connect the Arduino with loaded ArduinoISP sketch to the target chip
Run AVRDude. Make sure to specify a programmer type. Also note that ArduinoISP will work at lower serial speeds. Example:
avrdude -p m328p -P /dev/ttyACM0 -c avrisp -b 19200 -U flash:w:...
when i burn it on the kit it doesn't work .
what is the wrong with this code ??
Who knows? Could be anything. You haven't told us how you know it doesn't work. But that is not relevant, I will tell you why. I will not address your particular code in my answer more than this: It is too big.
It seems to me that this is your first project tested on ...
To light the LED, using the resistor to define the current, it doesn't matter which order they go in.
There may be some other non-electrical reasons for preferring one over the other in specific circumstances.
For instance, if you connect the LED directly to the PSU +ve, then accidentally shorting the LED to ground, as you might do with an untidy ...
Found the solution, which is of course dead simple once you know...
In Zadig, you can select the driver. Default selected is (in my case) the WinUSB driver. When I select the libusb driver, and install that driver, it works like a charm.
avrdude -vvv -c USBasp -p m32u4 -u -U flash:w:Duroduino.ino.hex:i
avrdude: Version 6.3, compiled on Feb 17 2016 ...
CKSEL typically stands for clock select. There are several choices that can be selected via an internal multiplexer-- some for test, others for alternate sources.
Since you are using a xtal, you can provide the code to select that option: which are in the first 2 rows of p 26.
You can use 3 bottom rows of table 4 for a crystal. Each is tuned to a ...
I think Dave Tweed is right about the binary being compiled for use with the Arduino bootloader.
I use the following bash script to program ATtiny's and I often use single Arduino libraries. I cannot test your specific setup, but if you change the various variables it just might work.
After reading up on the information Kevin provided in his answer I read a document called "AVR32006 : Getting started with GCC for AVR32". In this document there was a particular section which got me thinking about what Kevin said about the vector table.
The linking process needs information about code and data memory
location. Using a linker script ...
The avrdude write command (-U) knows an 'immediate' mode (see the manual), which allows you to specify the bytes to be written directly.
The syntax is like
avrdude -U eeprom:w:0xff:m
But this mode doesn't allow you to specify the address of the byte to be written, so I presume it will start writing at address zero. This works great for fuses (where ...
It seems likely that you have inadvertently changes the fuses to one of:
Different clock speed or clock source
Disable SPI programming
To recover this you need to use a "high-voltage" programmer that involves holding /RESET at +12V whilst specific sequences of commands are sent through most of the other pins. This may be difficult with your "...