SV: [Icc-avr] #define problem
Bengt Ragnemalm
benra at imt.liu.se
Mon Sep 24 23:23:31 PDT 2007
I use a file named "devicelist.h" that I include in all my files. This file
have all the #ifdef... for the various AVR's. With this method I never have
to change my drivers at the release of a new AVR. Also if I change the AVR I
will not have to bother about updating any includes.
In all project files:
#include <devicelist.h>
...
Example of "devicelist.h":
...
#ifdef ATMega8
#include <iom8v.h>
#endif
#ifdef ATMega8515
#include <iom8515v.h>
#endif
#ifdef ATMega8535
#include <iom8535v.h>
#endif
#ifdef ATMega88
#include <iom88v.h>
#endif
...
The file is not so big so to spare you from writing it I include the entire
file content her. It is not complete with all AVR's though. Just copy and
paste to create your own devicelist.h
/*
Project: Library file
File name: devicelist.h
Description: Selects the application specific io-file
Author: Bengt Ragnemalm
Date: 1.2 2005-03-15 Bengt Ragnemalm
History: 1.2 2005-03-15 Names updated to support
defines created by IDE.
1.1 2005-01-13 All
currently supported devices added
1.0 2000-10-16
Usage: This file is used in all files and will
automaticly select the correct
io include file.
*/
#ifdef ATtiny13
#include <iot13v.h>
#endif
#ifdef ATtiny2313
#include <iot2313v.h>
#endif
#ifdef ATtiny22
#include <iot22v.h>
#endif
#ifdef ATtiny26
#include <iot26v.h>
#endif
#ifdef ATMega48
#include <iom48v.h>
#endif
#ifdef ATMega8
#include <iom8v.h>
#endif
#ifdef ATMega8515
#include <iom8515v.h>
#endif
#ifdef ATMega8535
#include <iom8535v.h>
#endif
#ifdef ATMega88
#include <iom88v.h>
#endif
#ifdef ATMega16
#include <iom16v.h>
#endif
#ifdef ATMega161
#include <iom161v.h>
#endif
#ifdef ATMega162
#include <iom162v.h>
#endif
#ifdef ATMega16
#include <iom16v.h>
#endif
#ifdef ATMega165
#include <iom165v.h>
#endif
#ifdef ATMega168
#include <iom168v.h>
#endif
#ifdef ATMega169
#include <iom169v.h>
#endif
#ifdef ATMega32
#include <iom32v.h>
#endif
#ifdef ATMega323
#include <iom323v.h>
#endif
#ifdef ATMega64
#include <iom64v.h>
#endif
#ifdef ATMega103
#include <iom103v.h>
#endif
#ifdef ATMega128
#include <iom128v.h>
#endif
#ifdef AT90S2313
#include <io2313v.h>
#endif
#ifdef AT90S2323
#include <io2323v.h>
#endif
#ifdef AT90S2333
#include <io2333v.h>
#endif
#ifdef AT90S2343
#include <io2343v.h>
#endif
#ifdef AT90S4414
#include <io4414v.h>
#endif
#ifdef AT90S4433
#include <io4433v.h>
#endif
#ifdef AT90S4434
#include <io4434v.h>
#endif
#ifdef AT90S8515
#include <io8515v.h>
#endif
#ifdef AT90S8534
#include <io8534v.h>
#endif
#ifdef AT90S8535
#include <io8535v.h>
#endif
#ifdef AT94K05
#include <ioat94kv.h>
#endif
#ifdef AT94K10
#include <ioat94kv.h>
#endif
#ifdef AT94K40
#include <ioat94kv.h>
#endif
#ifdef AT86RF401
#include <iorf401v.h>
#endif
#ifdef AT43USB320
#include <ioUSB320v.h>
#endif
#ifdef AT43USB355
#include <ioUSB355v.h>
#endif
#ifdef CAN128
#include <ioCAN128v.h>
#endif
/Bengt
> -----Ursprungligt meddelande-----
> Från: icc-avr-bounces at imagecraft.com [mailto:icc-avr-
> bounces at imagecraft.com] För Sylvain Bissonnette
> Skickat: den 25 september 2007 01:22
> Till: Discussion list for ICCAVR and ICCtiny Users. You do NOT
> needtosubscribetoicc-announce if you are a member of this.
> Ämne: [Icc-avr] #define problem
>
> Hi,
>
> Is there a way to do
>
> #define MEGATYPE "Mega8"
>
> #if (MEGATYPE == "Mega8")
> #include "iom8v.h"
> #endif
>
> Thanks for your time
> Sylvain Bissonnette
>
>
> ----- Original Message -----
> From: "Sylvain Bissonnette" <sbissonnette at microsyl.com>
> To: "Discussion list for ICCAVR and ICCtiny Users. You do NOT
> needtosubscribetoicc-announce if you are a member of this."
> <icc-avr at imagecraft.com>
> Sent: Tuesday, August 14, 2007 9:09 PM
> Subject: [Icc-avr] From ASM to C
>
>
> > Hi,
> >
> > Long time ago Richard had give me this code (Thanks for!) but I want
> to
> > port if in C and I don't have any
> > knowleage of ASM. Any help will be usefull for me.
> >
> > Thanks
> > Sylvain Bissonnette
> >
> >
> > .if MEGATYPE64 | MEGATYPE128
> > SPMCR = 0x68
> > .else
> > SPMCR = 0x57
> > .endif
> >
> > ;-----------------------------------------
> >
> > ; void write_page (unsigned int adr, unsigned char function);
> > ; bits 8:15 adr addresses the page...(must setup RAMPZ beforehand!!!)
> > _write_page::
> > XCALL __WAIT_SPMEN__
> > movw r30, r16 ;move address to z pointer (R31 = ZH, R30 =
> ZL)
> > STS SPMCR, R18 ;argument 2 decides function
> > SPM ;perform pagewrite
> > RET
> >
> > ;-----------------------------------------
> >
> > ; void fill_temp_buffer (unsigned int data, unsigned int adr);
> > ; bits 7:1 in adr addresses the word in the page... (2=first word,
> > 4=second word etc..)
> > _fill_temp_buffer::
> > XCALL __WAIT_SPMEN__
> > movw r30, r18 ;move adress to z pointer (R31=ZH R30=ZL)
> > movw r0, r16 ;move data to reg 0 and 1
> > LDI R19, 0x01
> > STS SPMCR, R19
> > SPM ;Store program memory
> > RET
> >
> > ;-----------------------------------------
> >
> > ;unsigned int read_program_memory (unsigned int adr ,unsigned char cmd);
> > _read_program_memory::
> > movw r30, r16 ;move adress to z pointer
> > SBRC R18, 0 ;read lockbits? (second argument = 0x09)
> > STS SPMCR, R18 ;if so, place second argument in SPMEN
> register
> > .if MEGATYPE128
> > ELPM r16, Z+ ;read LSB
> > ELPM r17, Z ;read MSB
> > .else
> > LPM r16, Z+
> > LPM r17, Z
> > .endif
> > RET
> >
> > ;-----------------------------------------
> >
> > ;void write_lock_bits (unsigned char val);
> > _write_lock_bits::
> > MOV R0, R16
> > LDI R17, 0x09
> > STS SPMCR, R17
> > SPM ;write lockbits
> > RET
> >
> > ;-----------------------------------------
> >
> > _enableRWW::
> > XCALL __WAIT_SPMEN__
> > LDI R27,0x11
> > STS SPMCR,R27
> > SPM
> > RET
> >
> > ;-----------------------------------------
> >
> > __WAIT_SPMEN__:
> > LDS R27,SPMCR ; load SPMCR to R27
> > SBRC R27,0 ; check SPMEN flag
> > RJMP __WAIT_SPMEN__ ; wait for SPMEN flag cleared
> > RET
> >
> > ;-----------------------------------------
> >
> > _______________________________________________
> > Icc-avr mailing list
> > Icc-avr at imagecraft.com
> > http://dragonsgate.net/mailman/listinfo/icc-avr
> >
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
More information about the Icc-avr
mailing list