HC12: Best way to declair periperails

cancel
Showing results for 
Search instead for 
Did you mean: 

HC12: Best way to declair periperails

911 Views
Contributor I
I have external ram decleared as so
 
BatteryRAM      = NO_INIT       0x200000'G TO 0x3FFFFF'G;  // CS1
 
Bat_RAM              INTO  BatteryRAM;

#pragma DATA_SEG __GPAGE_SEG Bat_RAM
 char cExt_RAM[56];
#pragma DATA_SEG DEFAULT
 
do I do somethings simalar for a peripheral or is there a better way.
 
Daniel

Message Edited by CrasyCat on 2007-04-13 01:47 PM

Labels (1)
Tags (1)
0 Kudos
2 Replies

43 Views
Contributor I
Sorry but dont understand.
 
You have setup a structure to access indervidual buts within a internal register.
 
I are wonting to address a external device memory mapped to CS0 on the MC9S12xDP512 processor.
 
ie at address 400000 and another device at 400002 etc
 
Daniel
0 Kudos

43 Views
Senior Contributor II
Hi Daniel,
 
Your method is very suitable and will allow you to re-use your peripherals easily on other devices.
The only thing I would change is not to declare one ARRAY but instead create an union so it's easy for you to access within your code: you can call via bit or byte with the register name instead of a name and same index.
See some exmple below of what I use:
 
Code:
typedef union uCOPCTL{             tU08 byte;   struct    {      tU08 cr     :3;      /*cop timer rate select */      tU08 coprstp:1;      /*cop runs in stop mode */      tU08 copswai:1;      /*cop stops in wait mode */      tU08 wrtmask:1;      /*Write Mask for WCOP and CR[2:0] Bit */      tU08 rsbck  :1;      /*cop stops in active bdm */      tU08 wcop   :1;      /*window cop enable */    }bit;}tCOPCTL;#define CR0     0x01  /*bit masks */#define CR1     0x02#define CR2     0x04#define COPRSTP 0x08#define COPSWAI 0x10#define WRTMASK 0x20#define RSBCK   0x40#define WCOP    0x80typedef struct           {  volatile tCOPCTL  ctl;      /* COP control register */  volatile tU08     armcop;   /* COP timer arm/reset register */}tCOP;

 
and declare it in a periph.h
 
Code:
extern volatile tCOP     COP      @0x003E;    /* COP */

 
Cheers,
Alban.