[Icc-avr] #define problem

Michael Dipperstein MDipperstein at CalAmp.com
Mon Sep 24 15:43:00 PDT 2007


Why not just:

#define ATMega8

#if defined ATMega8
#include <iom8v.h>
#endif

In fact the Makefile generated by the IDE should put something like 
-DATMega8 in the parameters passed to the compiler for you.

I've done things like this before:
#if defined ATMega88
#include <iom88v.h>
#elif defined ATMega48
#include <iom48v.h>
#elif defined ATMega168
#include <iom168v.h>
#elif defined ATMega8
#include <iom8v.h>
#endif

-Mike

-----Original Message-----
From: icc-avr-bounces at imagecraft.com
[mailto:icc-avr-bounces at imagecraft.com] On Behalf Of Sylvain Bissonnette
Sent: Monday, September 24, 2007 4:22 PM
To: Discussion list for ICCAVR and ICCtiny Users. You do NOT
needtosubscribeto icc-announce if you are a member of this.
Subject: [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