Need to Send DATA to Port in Twr-K60 tower module to GLCD (NT7108C driver) in MQX

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

Need to Send DATA to Port in Twr-K60 tower module to GLCD (NT7108C driver) in MQX

743 Views
abhishekinamdar
Contributor II

     Need to Send DATA to PortB in Twr-K60 tower module to GLCD (NT7108C driver) in MQX programming, please go the following code do suggest appropriate API to send 8 bit data to the PortB in TWR‐K60D100M Tower Module. As in this tower the Port-B pin 2 and 3 are used for the capacitive touch input input, to send the 8 bit data to the port I need to mask the pin 2 & 3 and remaining pin (10 to 31) on the Port B and use 0 - 1, 4 - 9 (8 Pin) for parallel data transfer to the GLCD.

     Please go through below example code to send data to Port-B and suggest the appropriate API to do this particular task.

void LCD_Display() {

  uint8_t PORTB;                    //Please suggest appropriate API to Initialize the Port B for 8 bit DATA transfer

  lwgpio_init(&GLCD_CS1, LWGPIO_PORT_A | LWGPIO_PIN12, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);

  lwgpio_init(&GLCD_CS2, LWGPIO_PORT_A | LWGPIO_PIN13, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);

  lwgpio_init(&GLCD_RS, LWGPIO_PORT_A | LWGPIO_PIN14, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);

  lwgpio_init(&GLCD_RW, LWGPIO_PORT_A | LWGPIO_PIN15, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);

  lwgpio_init(&GLCD_RST, LWGPIO_PORT_A | LWGPIO_PIN6, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_LOW);

  lwgpio_init(&GLCD_EN, LWGPIO_PORT_A | LWGPIO_PIN17, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH);

  lwgpio_set_functionality(&GLCD_CS1, LWGPIO_MUX_A12_GPIO);

  lwgpio_set_functionality(&GLCD_CS2, LWGPIO_MUX_A13_GPIO);

  lwgpio_set_functionality(&GLCD_RS, LWGPIO_MUX_A14_GPIO);

  lwgpio_set_functionality(&GLCD_RW, LWGPIO_MUX_A15_GPIO);

  lwgpio_set_functionality(&GLCD_RST, LWGPIO_MUX_A16_GPIO);

  lwgpio_set_functionality(&GLCD_EN, LWGPIO_MUX_A17_GPIO);

  //Other Codes..

}

void GLCD_ON()

{

    //Activate both chips

    lwgpio_set_value(&GLCD_CS1, LWGPIO_VALUE_LOW);               //set the Chip select CS1 to low

    lwgpio_set_value(&GLCD_CS2, LWGPIO_VALUE_LOW);               //set the Chip select CS2 to low

    lwgpio_set_value(&GLCD_RS, LWGPIO_VALUE_LOW);                 //set the DATA or Instruction

    lwgpio_set_value(&GLCD_RW, LWGPIO_VALUE_LOW);                //set to Read or Write to the DATA line

    GLCD_Data = 0x3F;                                                                           //Send the 8 bit Data to the 32bit Port-B masking the Port Pin(2-3,10-31) 0xFFFFFFFF

    Enable_Pulse();

}

Regards

Abhi

0 Kudos
2 Replies

522 Views
soledad
NXP Employee
NXP Employee

Hello Abhishek,

Unfortunately the MQX LWGPIO driver has not an API like you need. However you can use code like a bareboard project, writing directly to the registers.


Have a great day,
Sol

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

0 Kudos

522 Views
abhishekinamdar
Contributor II

Hello Sol,

     Thanks for the replay, as you suggested I started wiriting the project directly. I created GLCD task in the MQX project and added the following code in the task (This is just the LCD task pasted, please find the MQX project attached below). There is no display, Please check what am I doing wrong.

Hardware Used:

1. TWR‐K60D100M (Only Evaluation Board)

2. LCD_Graphics_Datasheet_(Newhaven Display_NHD-12864AZ-FL-YBW)

3. MQX RTOS

4. CodeWarrior 10.5

Lcd_Aseem.c Task:

/* p3_2.c: Initialize and display "hello" on the LCD using 8-bit data mode.

* Data pins use Port B, control pins use Port A.

* Polling of the busy bit of the LCD status bit is used for timing.

*/

/*

* LCD_Assem.c

*

*  Created on: Nov 13, 2015

*      Author: in0ina

*/

/* p3_2.c: Initialize and display "hello" on the LCD using 8-bit data mode.

* Data pins use Port B, control pins use Port A.

* Polling of the busy bit of the LCD status bit is used for timing.

*/

#include "main.h"

#include <twrk60d100m.h>

#include <MK60D10.h>

#define RS 0x400     /* PTA2 mask (1<<10)*/

#define RW 0x800     /* PTA4 mask (1<<11)*/

#define EN 0x10000     /* PTA5 mask (1<<16)*/

#define add1 0x03     /* value to add */

#define add2 0xFC     /* value to add*/

void delayMs(int n);

void LCD_command(unsigned char command);

void LCD_command_noWait(unsigned char command);

void LCD_data(unsigned char data);

void LCD_init(void);

//void LCD_ready(void);

void data_line(unsigned char data);

void Lcd_Assem(void)

{

  _lwevent_create( &input_event, 0);/*The LW Event will have to be created; In this case we do want the flags to auto clear*/

  _lwevent_wait_ticks( &input_event, LCD_T, FALSE, 0); /*Input Task wait indefinitely until one of the event bits is set*/

    LCD_init();

    while(1)

    {

        LCD_command(1);         /* clear display */

        delayMs (500);

        LCD_command(0xC0);      /* set cursor at 2nd line */

        //LCD_data('h');          /* write the word on LCD */

        LCD_data('e');

        //LCD_data('l');

        //LCD_data('l');

        //LCD_data('o');

        delayMs (500);

       

        _sched_yield();

    }

}

void LCD_init(void)

{

  

  /*Command: "GPIOC_PSOR" literally means PORT SET OUTPUT REGISTER which SETS a pin high

  *Command: "GPIOC_PCOR" clears a pin, PORT CLEAR OUTPUT REGISTER which CLEARS a pin to the "low" state

  *Command: "GPIOC_PTOR" toggles a pin opposite of the current state

  * */

  SIM_SCGC5 |= 0x1000;     /* enable clock to Port B (SIM_SCGC5 = SIM_SCGC5_PORTA_MASK)*/

    PORTB_PCR0 = 0x100;      /* make PTB0 pin as GPIO (PORTB_PCR0 = PORT_PCR_MUX(1) | PORT_PCR_DSE_MASK)*/

    PORTB_PCR1 = 0x100;      /* make PTB1 pin as GPIO */

    //PORTB_PCR2 = 0x100;      /* make PTB2 pin as GPIO */

    //PORTB_PCR3 = 0x100;      /* make PTB3 pin as GPIO */

    PORTB_PCR4 = 0x100;      /* make PTB4 pin as GPIO */

    PORTB_PCR5 = 0x100;      /* make PTB5 pin as GPIO */

    PORTB_PCR6 = 0x100;      /* make PTB6 pin as GPIO */

    PORTB_PCR7 = 0x100;      /* make PTB7 pin as GPIO */

    PORTB_PCR8 = 0x100;      /* make PTB8 pin as GPIO */

    PORTB_PCR9 = 0x100;      /* make PTB9 pin as GPIO */

    GPIOB_PDDR = 0x3FF;       /* make PTB9-0 as output pins */

   

    //SIM_SCGC5 |= 0x0200;     /* enable clock to Port A */

    PORTB_PCR10 = 0x100;      /* make PTB10 (RS) pin as GPIO */

    PORTB_PCR11 = 0x100;      /* make PTB11 (RW) pin as GPIO */

    PORTB_PCR16 = 0x100;      /* make PTB16 (EN) pin as GPIO */

    GPIOB_PDDR |= 0x10C00;      /* make PTB16, 11, 10 as output pins */

    //delayMs(20);                /* initialization sequence */

    //LCD_command_noWait(0x30); /* LCD does not respond to status poll */

    //delayMs(5);

    //LCD_command_noWait(0x30);

    //delayMs(1);

    //LCD_command_noWait(0x30);

   

    LCD_command(0x30); /* LCD does not respond to status poll */

    delayMs(20);

    LCD_command(0x38);      /* set 8-bit data, 2-line, 5x7 font */

    delayMs(5);

    LCD_command(0x06);      /* move cursor right */

    delayMs(5);

    LCD_command(0x01);      /* clear screen, move cursor to home */

    delayMs(5);

    LCD_command(0x0F);      /* turn on display, cursor blinking */

}

/* This function waits until LCD controller is ready to

* accept a new command/data before returns.

*/

//void LCD_ready(void)

//{

//    char status;

//   

//    GPIOB_PDDR = 0;          /* PORTB input */

//    GPIOA_PCOR = RS;         /* RS = 0 for status */

//    GPIOA_PSOR = RW;         /* R/W = 1, LCD output */

//  

//    do {    /* stay in the loop until it is not busy */

//        GPIOA_PSOR = EN;     /* raise E */

//        delayMs(0);

//        status = GPIOB_PDIR; /* read status register */

//        GPIOA_PCOR = EN;

//        delayMs(0); /* clear E */

//    } while (status & 0x000);    /* check busy bit */

//   

//    GPIOA_PCOR = RW;         /* R/W = 0, LCD input */

//    GPIOB_PDDR = 0xFFF;       /* PORTB output */

//}

void LCD_command(unsigned char command)

{

//    LCD_ready(); /* wait until LCD is ready */

    GPIOB_PCOR = RS | RW;    /* RS = 0, R/W = 0 */

    data_line(command);

    GPIOB_PSOR = GPIOB_PDOR | EN;         /* pulse E */

    delayMs(0);

    GPIOB_PCOR = EN;

}

void LCD_command_noWait(unsigned char command)

{

    GPIOB_PCOR = RS | RW;    /* RS = 0, R/W = 0 */

    data_line(command);

    GPIOB_PSOR = GPIOB_PDOR | EN;         /* pulse E */

    delayMs(0);

    GPIOB_PCOR = EN;

}

void LCD_data(unsigned char data)

{

    //LCD_ready(); /* wait until LCD is ready */

  GPIOB_PCOR = RW;

  GPIOB_PDOR |= GPIOB_PDOR;

  GPIOB_PSOR = RS;         /* RS = 1, R/W = 0 */

    data_line(data);

    GPIOB_PSOR = GPIOB_PDOR | EN;         /* pulse E */

    delayMs(0);

    GPIOB_PCOR = EN;

}

void data_line(unsigned char data0)

{

  unsigned char data1 = data0 & add1;

  unsigned char data2 = data0 & add2;

  unsigned char data3 = data2 << 2;

  unsigned char data4 = data1 | data3;

  GPIOB_PDOR = GPIOB_PDOR | data4;

}

/* Delay n milliseconds

* The CPU core clock is set to MCGFLLCLK at 41.94 MHz in SystemInit().

*/

void delayMs(int n) {

    int i, j;

    for(i = 0 ; i < n; i++)

        for(j = 0 ; j < 7000; j++) { }

}

0 Kudos