Page 1 of 1
Atmel AVR Microcontroller programming
Posted: 22 Apr 2010, 23:53
by Prime
So I got my grubby paws on a handful of skt500 boards and want to learn how to program microcontrollers and make cool things.
Does anyone have any reference guides, how to's, recommended reading for me?
I think it programs in assembler or C so some help in this direction would also be appreciated.
Thanks.
Edit:
Useful Resources.
Basic Info:
Projects:
Re: Atmel AVR Microcontroller programming
Posted: 23 Apr 2010, 20:05
by Prime
Right, got a C compiler and a basic tut for it. Will try find and post the links.
Something fun I just programmed.
I used an existing template and played with the parameters in the while loop.
Code: Select all
// File: led.c
// Description: Simple C program for the ATMEL AVR uC (ATMEGA16 or ATMEGA8515 chip)
// This program lets the user turn on LEDs by pressing the switches on STK500 board
// Date modified: 23 April 2010
#include <avr/io.h> // avr header file for IO ports
int main(void){
unsigned char i; // temporary variable
DDRD = 0x00; // set PORTD for input
DDRB = 0xFF; // set PORTB for output
PORTB = 0x00; // turn ON all LEDs initially
while(1){
// Read input from PORTD.
// This port will be connected to the 8 switches
i = PIND+1;
i = PIND-1;
// Send output to PORTB.
// This port will be connected to the 8 LEDs
PORTB = i;
}
return 1;
}
8 LED's; 8 switches.
The first LED is on. Pressing the first button switches the second one one and switches the first off; IE it shifts the state to the right.
If you press and hold buttons 1,2 and 3; only LED 4 lights. if you press it's corresponding button, LED 4 and LED 5 switch states.
http://www.elec.uow.edu.au/avr/index.php
Re: Atmel AVR Microcontroller programming
Posted: 12 Dec 2011, 23:24
by Stuyvenstein
If you're using AVR Studio 5 (which I would recommend coz it's based on MS Visual Studio 2010) then you'll be coding in c. here is some code to make a led change status every second with the delay feature.
connect led's to portb of your avr, compile and program your avr with the following code and voila!
Code: Select all
#ifndef F_CPU
#define F_CPU 16000000UL //yout oscillator frequency
#endif
#include <avr/io.h>
#include <util/delay.h> //need to include this for the _delay to work
int main(void)
{
DDRB=0xFF; // PORTB data direction = all output
PORTB=0x00; // PORTB all off (low)
while(1)
{
PORTB=0xFF; // PORTB all high
_delay_ms(1000);
PORTB=0x00; // PORTB all low
_delay_ms(1000);
}
}
Have fun!
Re: Atmel AVR Microcontroller programming
Posted: 26 Dec 2011, 17:37
by Prime
How far I have come!
Learning how to use SPI at the mo... alas my jtag programmer seems to have died
Re: Atmel AVR Microcontroller programming
Posted: 28 Mar 2012, 18:36
by Impolitical
Hi
http://forums.trossenrobotics.com/forum.php has a pretty nice section about micro-controller programming. Also, it's robots, how much more could you possibly want?