HCS08 - MC9S08AW60 Output Array

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HCS08 - MC9S08AW60 Output Array

Jump to solution
791 Views
spforster13
Contributor I

I've been working the ARM mBed, but soon found out that I didn't have enough I/O pins and so I went over to the MC9S08AW60.  I am trying to use a similar code that I had running on the mBed but have encountered an issue around a 2D array with port values.   My issues is I am unsure how what the <type> should be for the array.  I have tried multiple things such as int, char etc and I haven't been able to get it to work.

 

The code I had working on the mBed is:

 

DigitalOut ledTable [5][5] =  {{(p6), (p11), (p16), (p25), (p30)},{(p7), (p12), (p17), (p24), (p29)},{(p8), (p13), (p18), (p23), (p28)},{(p9), (p14), (p19), (p22), (p27)},{(p10), (p15), (p20), (p21), (p26)}};  //defines the ports used on the mBed, table representation of this below

 

In this code I used the <type> for the array as DigitalOut, is there an equivalent on the MC9S08AW60?  As for far I have the rewritten the code for the same array to be used on the MC9S08AW60, but as I said I can't find a correct <type> to give the array, any help would be much appreciated.

 

<type????> ledTable[5][5] ; {

{PTBD_PTBD5, PTBD_PTBD6, PTBD_PTBD7, PTDD_PTDD0, PTDD_PTDD1} ,

{PTBD_PTBD0, PTBD_PTBD1, PTBD_PTBD2, PTBD_PTBD3, PTBD_PTBD4} ,

{PTED_PTED3, PTED_PTED4, PTED_PTED5, PTED_PTED6, PTED_PTED7} ,

{PTAD_PTAD6, PTAD_PTAD7, PTED_PTED0, PTED_PTED1, PTED_PTED2} ,

{PTAD_PTAD1, PTAD_PTAD2, PTAD_PTAD3, PTAD_PTAD4, PTAD_PTAD5}

};

Labels (1)
Tags (2)
0 Kudos
1 Solution
656 Views
kef2
Senior Contributor IV

I think MCU with addressable bits doesn't exist. Some compilers for Microchip MCU's support bit type and even bit addresses, but MCU still has bits packed into byte registers, and only bytes are addressable.

I think DigitalOut is some C++ class in ARM environment, Simon is using. I'm not familiar with S08 CW C++, I guess it is doable as well. But I doubt that using C++ on S08 and other tiny MCU's is the right idea. I would use C for the task like this:

typedef struct{
  volatile char *  adr;
  char mask;
} led;

const led ledTable[5][5] = {
{{&PTBD, PTBD_PTBD5_MASK}, {&PTBD, PTBD_PTBD6_MASK}, {&PTBD, PTBD_PTBD7_MASK},
  {&PTDD, PTDD_PTDD0_MASK}, {&PTDD, PTDD_PTDD1_MASK}  },

{{&PTBD, PTBD_PTBD0_MASK}, {&PTBD, PTBD_PTBD1_MASK}, {&PTBD, PTBD_PTBD2_MASK},
  {&PTBD, PTBD_PTBD3_MASK}, {&PTBD, PTBD_PTBD4_MASK}} ,

// {PTED_PTED3, PTED_PTED4, PTED_PTED5, PTED_PTED6, PTED_PTED7} ,

// {PTAD_PTAD6, PTAD_PTAD7, PTED_PTED0, PTED_PTED1, PTED_PTED2} ,

// {PTAD_PTAD1, PTAD_PTAD2, PTAD_PTAD3, PTAD_PTAD4, PTAD_PTAD5}

};

void SetLed( int i, int j, int value) {
    if(value)
        *ledTable[i][j].adr |= ledTable[i][j].mask;
    else
        *ledTable[i][j].adr &= ~ledTable[i][j].mask;
}

int GetLed( int i, int j) {
    if(*ledTable[i][j].adr & ledTable[i][j].mask)
       return 1;
    else
       return 0;
}

View solution in original post

0 Kudos
3 Replies
656 Views
Rick_Li
NXP Employee
NXP Employee

Hi Simon Forster,

There is no such a type for your array since HCS08 does not support a bit access.

The elements in your array are BITs of a byte register.

In the header file of MC9S08AW60, you will see the port data register are defined as a union and each pin is defined as PTxD_PTxDx. that is to say, the elements in your array has already defined, you can not use it in the array again!

hope it helps!

0 Kudos
657 Views
kef2
Senior Contributor IV

I think MCU with addressable bits doesn't exist. Some compilers for Microchip MCU's support bit type and even bit addresses, but MCU still has bits packed into byte registers, and only bytes are addressable.

I think DigitalOut is some C++ class in ARM environment, Simon is using. I'm not familiar with S08 CW C++, I guess it is doable as well. But I doubt that using C++ on S08 and other tiny MCU's is the right idea. I would use C for the task like this:

typedef struct{
  volatile char *  adr;
  char mask;
} led;

const led ledTable[5][5] = {
{{&PTBD, PTBD_PTBD5_MASK}, {&PTBD, PTBD_PTBD6_MASK}, {&PTBD, PTBD_PTBD7_MASK},
  {&PTDD, PTDD_PTDD0_MASK}, {&PTDD, PTDD_PTDD1_MASK}  },

{{&PTBD, PTBD_PTBD0_MASK}, {&PTBD, PTBD_PTBD1_MASK}, {&PTBD, PTBD_PTBD2_MASK},
  {&PTBD, PTBD_PTBD3_MASK}, {&PTBD, PTBD_PTBD4_MASK}} ,

// {PTED_PTED3, PTED_PTED4, PTED_PTED5, PTED_PTED6, PTED_PTED7} ,

// {PTAD_PTAD6, PTAD_PTAD7, PTED_PTED0, PTED_PTED1, PTED_PTED2} ,

// {PTAD_PTAD1, PTAD_PTAD2, PTAD_PTAD3, PTAD_PTAD4, PTAD_PTAD5}

};

void SetLed( int i, int j, int value) {
    if(value)
        *ledTable[i][j].adr |= ledTable[i][j].mask;
    else
        *ledTable[i][j].adr &= ~ledTable[i][j].mask;
}

int GetLed( int i, int j) {
    if(*ledTable[i][j].adr & ledTable[i][j].mask)
       return 1;
    else
       return 0;
}

0 Kudos
656 Views
spforster13
Contributor I

Thank you very much Edward,  I have now got my program working how I want it with the structure of the table you outlined along with *ledTable[i][j].adr |= ledTable[i][j].mask; and *ledTable[i][j].adr &= ~ledTable[i][j].mask; to turn them off.

0 Kudos