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? 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. 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:
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 1281jgmdesign - Jul 23, 2008 - 01:59 PM Post subject: RE: Sample Codes for ATmega128/1
Another question...
What development software/hardware are you using?
Jimstu_san - Jul 23, 2008 - 05:51 PM Post subject: RE: Sample Codes for ATmega128/1
Okay, you asked for it... 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.)
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;