Atmel AVR Microcontroller programming

Get help on programming - C++, Java, Delphi, etc.
Post Reply
User avatar
Prime
Registered User
Posts: 27729
Joined: 01 Mar 2004, 02:00
Location: Getting into trouble
Contact:

Atmel AVR Microcontroller programming

Post 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:
Last edited by Prime on 23 Apr 2010, 21:18, edited 1 time in total.
User avatar
Prime
Registered User
Posts: 27729
Joined: 01 Mar 2004, 02:00
Location: Getting into trouble
Contact:

Re: Atmel AVR Microcontroller programming

Post 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. :mrgreen:
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
Stuyvenstein
Registered User
Posts: 1
Joined: 12 Dec 2011, 23:00

Re: Atmel AVR Microcontroller programming

Post 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!
User avatar
Prime
Registered User
Posts: 27729
Joined: 01 Mar 2004, 02:00
Location: Getting into trouble
Contact:

Re: Atmel AVR Microcontroller programming

Post by Prime »

How far I have come! :lol:

Learning how to use SPI at the mo... alas my jtag programmer seems to have died :(
Impolitical
Registered User
Posts: 4
Joined: 28 Mar 2012, 16:57

Re: Atmel AVR Microcontroller programming

Post 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? :D
Post Reply