AVR Freaks

AVR studio 4 forum - Sample Codes for ATmega128/1

rienaomi - Jul 23, 2008 - 06:23 AM
Post subject: Sample Codes for ATmega128/1
Does someone know where I can find C codes for Atmega128/1 that I can revise and edit with? Wink
clawson - Jul 23, 2008 - 11:48 AM
Post subject: RE: Sample Codes for ATmega128/1
Codes to do what?!?!

Remember the quality of the answers you receive here is related to the quality of the question in the first place.
rienaomi - Jul 23, 2008 - 12:38 PM
Post subject: RE: Sample Codes for ATmega128/1
I want to find sample codes that I can experiment with in order to get ideas on how to program my atmega1281. Just the basic embedded C Programming codes.

My end goal is for my Atmega1281 is to communicate with an rf transceiver via spi and also involves communicating to a gps receiver via usart.

I just don't know where to start. Crying or Very sad
clawson - Jul 23, 2008 - 12:47 PM
Post subject: RE: Sample Codes for ATmega128/1
That makse no sense. A 1281 is a microcontroller. By it's very nature that means it controls something. You will have various input and output electronics connected to it and what you have connected then dictates the program that you need to run internally to read the inputs and drive the outputs. A computer program with no inputs and no outputs is completely pointless. If you have no external hardware attached then you might as well just write programs for the AVR Studio simulator and forget the electronics all together.

Now the usual "first step" folks often take is to put an LED (and a resistor!) on a pin of the AVR and see if you can make it flash or fade up/down (with PWM). You might also then add a button or two where you use them to speed up/slow down the flashing rate or something like that. But if you do things like this the code is not specific to the 1281. In fact the examples in the GCC manual:

http://www.nongnu.org/avr-libc/user-man ... demos.html

give some ideas for first steps.

So bottom line - first decide what you want the AVR to do.

You may also want to look at the book from www.smileymicros.com - while aimed at the mega169 on the Atmel Butterfly some of the ideas for "beginner programs" could easily be ported to a 1281
jgmdesign - Jul 23, 2008 - 01:59 PM
Post subject: RE: Sample Codes for ATmega128/1
Another question...
What development software/hardware are you using?

Jim
stu_san - Jul 23, 2008 - 05:51 PM
Post subject: RE: Sample Codes for ATmega128/1
Okay, you asked for it... Laughing My Complete List O' Newbie Links!

First of all, learn how to ask questions the smart way. Visit this site (There are translations into most languages, so not being able to read English is not an excuse.)


Beginner sites/topics:

AVR C tutorial

Embedded Electronics - Beginning with everything

A From-Scratch AVR Tutorial

Book: Arnie Aardvark's AVR Aperçu

Book and Dev Kits: Smiley Micros - Smiley frequently posts on this forum!

Arduino development board with a large community support

ZBasic microcontrollers, Basic programmed, AVRs inside


Learning C:

Programming Tutorial: C Made Easy

How C Programming Works

And don't forget books!

The C Programming Language is almost a necessity.

Absolute Beginners Guide To C

Writing Solid Code I personally recommend this. Lots of good tips.

Again, check out Smiley's book.


AVRFreaks Tutorials:

The AVR Tutorials forum of avrfreaks.net contains a lot of stuff for you:

[TUT] [SOFT] WinAVR Beginner's Quick Start Guide for ATMEGA128

[TUT] [SOFT] Setting Up AVRStudio to use GCC

[TUT] [HARD] AVR Programming Methods (Loading Code On Your AVR)

[TUT] [C] Bit manipulation (AKA "Programming 101 For Embedded Code")

[TUT] [C] Modularizing C Code: Managing large projects

[TUT] [C++] AVR C++ Micro How-To

Interrupt Handler Syntax, By Compiler

[TUT] [SOFT] Using the USART - Serial communications

[TUT] [SOFT] Using the USART - Interrupt driven serial comms

[TUT] [C] Newbie's Guide to AVR Timers

[TUT] [C] Creating an RTC using an internal counter/timer

[TUT] [C] Using the EEPROM memory in AVR-GCC

[TUT] [C] GCC and the PROGMEM Attribute

[TUT] [C] Newbie's Guide to the AVR ADC


Good stuff from the AVR-Libc Manual:

AVR-libc Manual: Index

AVR-libc Manual: Frequently Asked Questions

AVR-libc Manual: Memory, Malloc, and External SRAM

AVR-libc Manual: Delay Routines

AVR-libc Manual: Interrupts

AVR-libc Manual: How to Build a Library

AVR-libc Manual: Mixing C and Assembly


Other good topics:

BASCOM-AVR - Basic for AVR processors

KAVRCalc - Calculator of AVR-specific stuff

Introduction to the "Volatile" Keyword

GCC Optimization flags - what they mean

[TUT] [C] Creating an RTC using an internal counter/timer

[DIS] [ASM] Dirty Math Tricks: Adventures in Division by Ten

Mechanical Switch Debouncing

Care and Feeding Of Watchdog Timers

Atmel App Notes - all sorts of good topics here!

Porting code from IAR to Avr-GCC


These tutorials may not answer all your questions, but they will allow you to get further faster. You'll be able to ask better questions!


A list of RTOS links for AVR processors:

First off, check out the RTOS list in the Tuorials section: [TUT][SOFT] RTOS for AVR

All of the following are in the above tutorial

FreeRTOS: A Free RTOS for microcontrollers

AvrX: Real-Time Kernel for AVR processors

YAVRTOS: Yet Another Atmel AVR Real-Time Operating System

AVRAsmOS: A tiny OS for small AVRs

pc/OS RTOS Kernel (for larger AVR processors >= mega128)

uSmartX: Non-Preemptive Priority-based Multitask RTOS

Opex - good for smaller RAM, marked "beta"

uC/OS - Extensively tested, certified for avionics, but *not* cheap


Advanced Topics:

Linker Scripts

AVR Eclipse on Ubuntu 8.04

[MAN][HARD][SOFT] Hardware Random Number Generation

Charlieplexing: DIY, How-To

Charlieplexing: Reduced Pin-Count LED Display Multiplexing

How to use MMC/SDC (Attaching SD cards through the SPI)

FatFS File System Module for AVR

A Page O' AVR Links


That should hold ya for a while! Very Happy


As always, if you have a question that is not answered in one of the tutorials above, ask in the appropriate AVRFreaks community:

o AVR GCC forum - GCC specific questions, including WinAVR and Avr-libc (NOT AVRLib, the UART library - post those to the AVR Forum)

o AVR studio 4 forum - AVR Studio problems, not compiler related.

o AVR forum - non-GCC specific questions and general questions about AVR processors

o General Electronics forum - Questions about electronics other than AVRs; Relays, thermocouples, LCDs, LEDS, FETs, PLLs, resistors, and stuff like that.


Hope this helps!

Stu

PS: For lighter reading, here's "Real Programmers Don't Eat Quiche". This is one of the summarized-and-updated versions of the full treatise here.
ankarsvik - Nov 13, 2008 - 07:24 PM
Post subject: RE: Sample Codes for ATmega128/1
Hi,

Maybee someone really wants an example code for a ATmega128

This is led.c slightly changed from 8515 to mega128


Code:

/* Moving LED example

   CodeVisionAVR C Compiler
   (C) 2000-2007 HP InfoTech S.R.L.
   www.hpinfotech.ro

   Chip: ATmega128
   Memory Model: SMALL
   Data Stack Size: 128 bytes

   8 LEDs are connected between the PORTC
   outputs and +5V using 1K current
   limiting resistors
   The LEDs anodes are connected to +5V
   
   On the STK500 it's only necessary to
   connect the PORTC and LEDS headers
   together with a 10-wire cable
*/

// I/O register definitions for MEGA128
#include <mega128.h>


// quartz crystal frquency [Hz]
#define xtal 3686400
// moving LED frequency [Hz]
#define fmove 2

// the LED on PORTC output 0 will be on
unsigned char led_status=0xfe;

// TIMER1 overflow interrupt service routine
// occurs every 0.5 seconds

interrupt [TIM1_OVF] void timer1_overflow(void)
{
// preset again TIMER1
TCNT1=0x10000-(xtal/1024/fmove);
// move the LED
  led_status<<=1;
  led_status|=1;
  if (led_status==0xff) led_status=0xfe;
// turn on the LED
 PORTC=led_status;

}

void main(void)
{
// set the I/O ports
// all PORTC pins are outputs
DDRC=0xFF;

// turn on the first LED
PORTC=led_status;


TCCR1A=0x00;
TCCR1B=0x05;
TCNT1=0x10000-(xtal/1024/fmove);
TIFR = 0;
EIMSK = 0;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;

// global enable interrupts
#asm
    sei
#endasm

// the rest is done by TIMER1 overflow interrupts
while (1);
}

EW - Nov 13, 2008 - 08:44 PM
Post subject: Re: Sample Codes for ATmega128/1
rienaomi wrote:
Does someone know where I can find C codes for Atmega128/1 that I can revise and edit with? Wink


Code:
int main(void)
{
   return 0;
}

js - Nov 14, 2008 - 04:12 AM
Post subject: RE: Re: Sample Codes for ATmega128/1
Why is everyone responding to a 6 months old thread? Confused ..including me? Surprised
All times are GMT + 1 Hour
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits