• Main Page
  • Modules
  • Index
  • File List
  • Globals

lib/display/lib_display.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 2494 $
00012  */ 
00013 
00018 #include "nrf24le1.h"
00019 #include <stdint.h>
00020 //#include <stdlib.h>
00021 #include <string.h>
00022 #include "nordic_common.h"
00023 #include "hal_delay.h"
00024 #include "lib_display.h"
00025 
00026 #define DDRAM_ADR     0x80      // Write to DDRAM AC
00027 #define DDRAM_WR      0x40      // Write to DDRAM
00028 #define FUNC_SET      0x00      // Enter LCD Function settings
00029 #define LCD_ADDR      0x3E      // LCD display adr
00030 #define JS_ADDR       0x3F      // Joystick adr
00031 
00032 #define X 0                     // Contents in joystick array
00033 #define Y 1
00034 
00035 void lcd_init(void)
00036 { 
00037   hal_w2_configure_master(HAL_W2_400KHZ);
00038   delay_us(100);
00039                       
00040   lcd_set_instruction(0x38);                      // Function set
00041   lcd_set_instruction(0x39);                      // Choose two-line mode
00042   lcd_set_instruction(0x14);                      // Internal OSC frequency
00043   lcd_set_contrast(LCD_CONTRAST_HIGH);            // Contrast set (low byte)
00044   lcd_set_instruction(0x5F);                      // Power/ICON control/
00045                                                   // Contrast set (high byte)
00046   lcd_set_instruction(0x6A);                      // Follower control
00047   delay_ms(200);
00048 
00049   lcd_on();                                       // Display ON
00050   lcd_clear();                                    // Clear display
00051   lcd_set_instruction(0x06);                      // Entry mode set    
00052 }                                                                    
00053 
00054 void lcd_write_string(char *text, uint8_t line, uint8_t pos)
00055 {
00056   char str[18];
00057   uint8_t buffer[2];
00058   uint8_t i;
00059   
00060   if(line == 0)
00061   { 
00062     line = 0x00;                                  // Upper row of LCD display
00063   }
00064   else
00065   {
00066     line = 0x40;                                  // Lower row of LCD display
00067   }
00068 
00069   if(pos > 15) pos = 16;                          // Write to visible positions
00070 
00071   buffer[0] = FUNC_SET;                           // Enter function setting
00072   buffer[1] = DDRAM_ADR + (pos + line);           // LCD adr counter set to pos
00073   hal_w2_write(LCD_ADDR, buffer, 2);              // Write the settings to the 
00074                                                   // LCD display
00075   for(i=0;i<17;i++)                               // Save text in a new string
00076   {                                               // with space for function
00077     str[i+1] = text[i];                           // setting
00078   }
00079   str[0] = DDRAM_WR;                                  // Enter function setting
00080   hal_w2_write(LCD_ADDR, (const uint8_t *)str, strlen(text) + 1); // Transmit string to LCD
00081 }
00082 
00083 void lcd_clear(void)
00084 { 
00085   uint8_t buffer[2];
00086 
00087   delay_ms(10);
00088   buffer[0] = FUNC_SET; 
00089   buffer[1] = 0x01;                               // Clear display
00090   hal_w2_write(LCD_ADDR, buffer, 2);
00091   delay_ms(10);   
00092 }
00093 
00094 void lcd_set_contrast(lib_nrf6350_lcd_contrast_t contrast)
00095 {
00096   uint8_t buffer[2];
00097  
00098   delay_ms(10);
00099   buffer[0] = FUNC_SET; 
00100   buffer[1] = 0x70 | contrast;                    // Contrast set (low byte)
00101   hal_w2_write(LCD_ADDR, buffer, 2);
00102   delay_ms(10);
00103 }
00104 
00105 void lcd_set_instruction(uint8_t instr)
00106 {
00107   uint8_t buffer[2];
00108  
00109   delay_ms(10);
00110   buffer[0] = FUNC_SET; 
00111   buffer[1] = instr;                              // Instr. set
00112   hal_w2_write(LCD_ADDR, buffer, 2);
00113   delay_ms(10);
00114 }
00115 
00116 void lcd_on(void)
00117 {
00118   uint8_t buffer[2];
00119 
00120   delay_ms(10);
00121   buffer[0] = FUNC_SET; 
00122   buffer[1] = 0x0C;                               // Display ON
00123   hal_w2_write(LCD_ADDR, &buffer[0], 2);
00124   delay_ms(10);
00125 }
00126 
00127 void lcd_off(void)
00128 {
00129   uint8_t buffer[2];
00130  
00131   delay_ms(10);
00132   buffer[0] = FUNC_SET; 
00133   buffer[1] = 0x08;                               // Display OFF
00134   hal_w2_write(LCD_ADDR, buffer, 2);
00135   delay_ms(10);
00136 }
00137 
00138 void js_get_value(int8_t *val)
00139 {
00140   uint8_t js_data;
00141   uint8_t rx_buffer[1];
00142 
00143   hal_w2_read(JS_ADDR, rx_buffer, 1);             // Get data from the joystick
00144   js_data = (~rx_buffer[0] & 0x1D);               // Select the useful bits
00145  
00146   if((js_data & BIT_0) == BIT_0)                  // Check joystick position
00147   {
00148     val[X] = -1;
00149   }
00150   else if((js_data & BIT_4) == BIT_4)
00151   {
00152     val[X] = 1;
00153   } 
00154   else
00155   {
00156     val[X] = 0;
00157   }
00158   
00159   if((js_data & BIT_2) == BIT_2)
00160   {
00161     val[Y] = 1;
00162   }
00163   else if((js_data & BIT_3) == BIT_3)
00164   {
00165     val[Y] = -1;
00166   }
00167   else
00168   {
00169     val[Y] = 0;
00170   }
00171 }
00172 
00173 bool js_button_pushed(void)
00174 {
00175   uint8_t js_data;
00176   uint8_t rx_buffer[1];
00177  
00178   hal_w2_read(JS_ADDR, rx_buffer, 1);             // Get data from the joystick
00179   js_data = (~rx_buffer[0] & BIT_1);              // Mask button bit
00180          
00181   return (js_data == BIT_1);                      // Check if button is pushed
00182 }
00183 
00184 lib_display_js_states_t js_get_status()
00185 {
00186   uint8_t js_data;
00187 
00188   hal_w2_read(JS_ADDR, &js_data, 1);              // Get data from the joystick
00189   js_data = ~js_data;   
00190   if( js_data & 0x02 ) return JS_BUTTON_PUSH;
00191   if( js_data & 0x01 ) return JS_BUTTON_LEFT;
00192   if( js_data & 0x10 ) return JS_BUTTON_RIGHT;
00193   if( js_data & 0x08 ) return JS_BUTTON_UP;
00194   if( js_data & 0x04 ) return JS_BUTTON_DOWN;
00195   return JS_BUTTON_NONE;
00196 } 

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2