Sample code of Dio and Port driver for S12ZVMC familiar

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

Sample code of Dio and Port driver for S12ZVMC familiar

1,246 Views
huuhuynhchi
Contributor III

Dear all,

I will use S12ZVMC256 for my project in next time. At the present, I'm trying to implement the driver for its but I have some difficulties with Dio and Port driver. Hopeful, if anybody have ever used this microcontroller or had experience about this, could you please give me some advices or sample code of S12Z familiar belongs to Dio and Port. Thank you very much.

Labels (1)
Tags (3)
1 Reply

648 Views
RadekS
NXP Employee
NXP Employee

Hi Huu,

Unfortunately, I am not aware of any GPIO driver for S12(X)(Z) MCUs.

The behavior of pins is pretty clear and configuring is simple (just updating registers), that any driver is not necessary in most of the cases.

However, since there isn’t unified port register structure for all ports, the port driver does not look so simple.

Here is simple example code how it could look:

In header file:

#define uint16_t volatile unsigned int

#define uint8_t volatile unsigned char

/*! @brief GPIO pin direction selection*/

typedef enum _port_dir {

    kPortInput    = 0U, /**/

    kPortOutput   = 1U /**/

} port_dir_t;

void set_pin_direction(uint8_t *port_name, uint8_t pin, port_dir_t _pin_dir);

In C file:

void set_pin_direction(uint8_t *port_name, uint8_t pin, port_dir_t _pin_dir)

{

uint8_t *port;

uint8_t DDR_register_ptr=2;             //DDR registers position - port E and AD registers are 16bit, other ports have 8bit registers

port=(uint8_t*) port_name;    // get base address of the port  

if ((port==&PTE)|(port==&PTADH))

  {

    DDR_register_ptr=4;

  }

if (_pin_dir)

   {

   port[DDR_register_ptr] |= 1<<pin;  //set to output pin

   }

else

   {

   port[DDR_register_ptr] &= ~(1<<pin); //set to input pin

   }

}

void main(void) {

  for(;;) {

      set_pin_direction(&PTT, 3, kPortOutput);

      set_pin_direction(&PTT, 3, kPortInput);

      set_pin_direction(&PTE, 1, kPortOutput);

      set_pin_direction(&PTE, 1, kPortInput);

   

  } /* loop forever */

}

Note:Similar way we could define also functions for pull-device enable/disable, pull-device direction=interrupt edge selection, port interrupt enable/disable, Full/Reduced drive strength, Enable/Disable digital input buffer at port AD, Read pin value,...

Note: This example does not cover situation of missing feature at specific port - it does not report errors.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------