Enumerations | Functions

nRFgo LCD and joystick
[Libraries (LIB)]


Library for the nRF6350 LCD display and joystick module.

The 2 wire interface of the nRF24LE1 on the nRFgo Development Kit modules are routed to the IO port sharing pins with it. To enable connection to a nRFgo Display module fitted in the extension port of the nRFgo Motherboard the 2 wire interface of the mounted nRF24LE1 must also be routed to the 2 wire interface of the nRFgo Development Kit module. This is done by shorting the SDA and SCL solder bridges SB1 and SB2 found on the nRF24LE1 development kit

Enumerations

enum  lib_nrf6350_lcd_contrast_t { LCD_CONTRAST_LOW = 0x00, LCD_CONTRAST_MEDIUM = 0x02, LCD_CONTRAST_HIGH = 0x08 }
enum  lib_display_js_states_t {
  JS_BUTTON_NONE = 0, JS_BUTTON_PUSH = 1, JS_BUTTON_LEFT = 2, JS_BUTTON_RIGHT = 3,
  JS_BUTTON_UP = 4, JS_BUTTON_DOWN = 5
}

Functions

void lcd_init (void)
void lcd_write_string (char *text, uint8_t line, uint8_t pos)
void lcd_clear (void)
void lcd_set_contrast (lib_nrf6350_lcd_contrast_t contrast)
void lcd_set_instruction (uint8_t instr)
void lcd_on (void)
void lcd_off (void)
void js_get_value (int8_t *val)
_Bool js_button_pushed (void)
lib_display_js_states_t js_get_status (void)

Enumeration Type Documentation

Enum describing the contrast of lcd display.

Enumerator:
LCD_CONTRAST_LOW 
LCD_CONTRAST_MEDIUM 
LCD_CONTRAST_HIGH 

Definition at line 41 of file lib_display.h.

Enum describing the different states of the joystick.

Enumerator:
JS_BUTTON_NONE 
JS_BUTTON_PUSH 
JS_BUTTON_LEFT 
JS_BUTTON_RIGHT 
JS_BUTTON_UP 
JS_BUTTON_DOWN 

Definition at line 50 of file lib_display.h.


Function Documentation

void lcd_init ( void   )

Function to initialize the LCD display prior to writing.

Definition at line 35 of file lib_display.c.

{ 
  hal_w2_configure_master(HAL_W2_400KHZ);
  delay_us(100);
                      
  lcd_set_instruction(0x38);                      // Function set
  lcd_set_instruction(0x39);                      // Choose two-line mode
  lcd_set_instruction(0x14);                      // Internal OSC frequency
  lcd_set_contrast(LCD_CONTRAST_HIGH);            // Contrast set (low byte)
  lcd_set_instruction(0x5F);                      // Power/ICON control/
                                                  // Contrast set (high byte)
  lcd_set_instruction(0x6A);                      // Follower control
  delay_ms(200);

  lcd_on();                                       // Display ON
  lcd_clear();                                    // Clear display
  lcd_set_instruction(0x06);                      // Entry mode set    
}                                                                    
void lcd_write_string ( char *  text,
uint8_t  line,
uint8_t  pos 
)

Function for writing a text string on the LCD-display.

Parameters:
*textA pointer to the text string to be written
lineThe line the text should be written to
posThe start position of the text on the line

Definition at line 54 of file lib_display.c.

{
  char str[18];
  uint8_t buffer[2];
  uint8_t i;
  
  if(line == 0)
  { 
    line = 0x00;                                  // Upper row of LCD display
  }
  else
  {
    line = 0x40;                                  // Lower row of LCD display
  }

  if(pos > 15) pos = 16;                          // Write to visible positions

  buffer[0] = FUNC_SET;                           // Enter function setting
  buffer[1] = DDRAM_ADR + (pos + line);           // LCD adr counter set to pos
  hal_w2_write(LCD_ADDR, buffer, 2);              // Write the settings to the 
                                                  // LCD display
  for(i=0;i<17;i++)                               // Save text in a new string
  {                                               // with space for function
    str[i+1] = text[i];                           // setting
  }
  str[0] = DDRAM_WR;                                  // Enter function setting
  hal_w2_write(LCD_ADDR, (const uint8_t *)str, strlen(text) + 1); // Transmit string to LCD
}
void lcd_clear ( void   )

This function clears the contents of the LCD-display.

Definition at line 83 of file lib_display.c.

{ 
  uint8_t buffer[2];

  delay_ms(10);
  buffer[0] = FUNC_SET; 
  buffer[1] = 0x01;                               // Clear display
  hal_w2_write(LCD_ADDR, buffer, 2);
  delay_ms(10);   
}
void lcd_set_contrast ( lib_nrf6350_lcd_contrast_t  contrast )

This function adjust the contrast of the LCD-display, select between LCD_CONTRAST_LOW, LCD_CONTRAST_MEDIUM and LCD_CONTRAST_HIGH

Parameters:
contrastThe desired contrast of the lcd display

Definition at line 94 of file lib_display.c.

{
  uint8_t buffer[2];
 
  delay_ms(10);
  buffer[0] = FUNC_SET; 
  buffer[1] = 0x70 | contrast;                    // Contrast set (low byte)
  hal_w2_write(LCD_ADDR, buffer, 2);
  delay_ms(10);
}
void lcd_set_instruction ( uint8_t  instr )

This function writes instructions to the LCD display

Remarks:
See LCD datasheet.
Parameters:
instrThe desired instruction

Definition at line 105 of file lib_display.c.

{
  uint8_t buffer[2];
 
  delay_ms(10);
  buffer[0] = FUNC_SET; 
  buffer[1] = instr;                              // Instr. set
  hal_w2_write(LCD_ADDR, buffer, 2);
  delay_ms(10);
}
void lcd_on ( void   )

Function that turns ON the LCD-display

Definition at line 116 of file lib_display.c.

{
  uint8_t buffer[2];

  delay_ms(10);
  buffer[0] = FUNC_SET; 
  buffer[1] = 0x0C;                               // Display ON
  hal_w2_write(LCD_ADDR, &buffer[0], 2);
  delay_ms(10);
}
void lcd_off ( void   )

Function that turns OFF the LCD-display

Definition at line 127 of file lib_display.c.

{
  uint8_t buffer[2];
 
  delay_ms(10);
  buffer[0] = FUNC_SET; 
  buffer[1] = 0x08;                               // Display OFF
  hal_w2_write(LCD_ADDR, buffer, 2);
  delay_ms(10);
}
void js_get_value ( int8_t *  val )

This function gets the position of the joystick.

Parameters:
valpointer to a 2 byte array where the X,Y position is stored

< The value of bit 0

< The value of bit 0

< The value of bit 4

< The value of bit 4

< The value of bit 2

< The value of bit 2

< The value of bit 3

< The value of bit 3

Definition at line 138 of file lib_display.c.

{
  uint8_t js_data;
  uint8_t rx_buffer[1];

  hal_w2_read(JS_ADDR, rx_buffer, 1);             // Get data from the joystick
  js_data = (~rx_buffer[0] & 0x1D);               // Select the useful bits
 
  if((js_data & BIT_0) == BIT_0)                  // Check joystick position
  {
    val[X] = -1;
  }
  else if((js_data & BIT_4) == BIT_4)
  {
    val[X] = 1;
  } 
  else
  {
    val[X] = 0;
  }
  
  if((js_data & BIT_2) == BIT_2)
  {
    val[Y] = 1;
  }
  else if((js_data & BIT_3) == BIT_3)
  {
    val[Y] = -1;
  }
  else
  {
    val[Y] = 0;
  }
}
_Bool js_button_pushed ( void   )

This function checks if the joystick is pushed down

Returns:
True if joystick is pushed down, false if released

< The value of bit 1

< The value of bit 1

Definition at line 173 of file lib_display.c.

{
  uint8_t js_data;
  uint8_t rx_buffer[1];
 
  hal_w2_read(JS_ADDR, rx_buffer, 1);             // Get data from the joystick
  js_data = (~rx_buffer[0] & BIT_1);              // Mask button bit
         
  return (js_data == BIT_1);                      // Check if button is pushed
}
lib_display_js_states_t js_get_status ( void   )

This function gets the status of the joystick

Returns:
The status of the joystick as defined in the lib_display_js_states_t struct

Definition at line 184 of file lib_display.c.

{
  uint8_t js_data;

  hal_w2_read(JS_ADDR, &js_data, 1);              // Get data from the joystick
  js_data = ~js_data;   
  if( js_data & 0x02 ) return JS_BUTTON_PUSH;
  if( js_data & 0x01 ) return JS_BUTTON_LEFT;
  if( js_data & 0x10 ) return JS_BUTTON_RIGHT;
  if( js_data & 0x08 ) return JS_BUTTON_UP;
  if( js_data & 0x04 ) return JS_BUTTON_DOWN;
  return JS_BUTTON_NONE;
}