The www.seattlerobotics.org/WorkshopRobot and my www.barello.net/ARC have a
suite of sample programs from very simple to relatively complex, that you
can use to get started. WinAvr has some samples and a great FAQ that covers
many start-up issues with AVR & C.
Programming one CPU family is pretty much the same as another. The
peripherals seem to be the biggest thing that changes. The overall
architecture might affect how one structures assembly, but fortunately there
are pretty good C compilers for all modern chip sets - and you can learn a
lot from how the compiler assembles for a particular target.
Your example, below, would be trivial in C (not optimal for AVR, but don't
worry about that now):
char cMyTable[] = {0,1,2,3,...255}; // Put in your own numbers, of course
int main(void)
{
DDRB = 0xFF; // Port B output
DDRD = 0x00; // port D input, with pull-ups
PORTD = 0xFF;
while (1)
{
PORTB = cMyTable[PIND];
}
}
Most AVRs have limited number of external interrupt lines. Some of the
newer ones have "interrupt on pin change" which might work well for your
example. Probably the simplest is to set up a periodic timer and poll from
there. You need to read the particulars for your compiler (BASCOM/WinAvr,
etc) to see how to set up the interrupt handler. They are pretty simple
once you have a sample to look at. The data sheets will have everything
else you need: register initialization & calculations needed to figure out
the interrupt rate.
Cheers!
-----------
Larry Barello
www.barello.net
| -----Original Message-----
| From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf
| Of Ted Smith
| Sent: Tuesday, December 20, 2005 4:00 AM
| To: AVR-Chat@yahoogroups.com
| Subject: [AVR-Chat] I cant get started
|
| Hi, I'm probably the oldest living active programmer in Australia and
| have decided to have a go at AVRmega16's before I die - hopefully
| using Bascom basic.
| I have done a lot with VB6 and assembly with the old 6502's 25 years
| ago but can't find anywhere any concise info on how to structure the
| AVR programs and integrating the various sub-routines, interrupts etc.
| It all seems so disjointed and every article I have found so is
| written by someone who assumes I know what they know. (Like Microsoft
| help screens of the past)
| Can anyone point me to a good step by step starting guide on how to
| compose a simple program to say accept a few switch inputs and output
| to a few leds while displaying information from the EEprom on an LCD
| depending on what switch is pressed?
| With the old 6502 I would have used interrupt routines for the
| switches and had a loop polling the inputs and simply written to
| output port addresses with an indexed address looking up data
| depending on the switch number.
| I can't seem to rationalise this to the AVR or is it done another way?
| Thanks Ted SmithMessage
RE: [AVR-Chat] I cant get started
2005-12-20 by Larry Barello
Attachments
- No local attachments were found for this message.