// tab space = 4 /***********************************************************************/ /* */ /* FILE :128x128NewHaven_lcd.c */ /* DATE :April 8, 2011 */ /* DESCRIPTION :Functions to drive New Haven 128x128 LCD Display */ /* */ /* */ /***********************************************************************/ #include "128x128NewHaven_bsp.h" // Defines and prototypes //The next two includes are specific to the microprocessor being used to //interface with the display #include "sfr62p.h" // Special Function Registers defines for processor #include "62P_bsp.h" // Defines and prototypes for the processor board //Declare Variables unsigned char vopcode; unsigned char Ra_Rb; int i, col; long page; unsigned char g; //, a; _far char *m; char conv_buff[127]; unsigned char col_count; char char_con[2]; // This list of const char is used to display comman ASCII charaters const char char_space[] = {0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; const char char_pound[] = {0x07,0x00,0x28,0xFE,0x28,0xFE,0x28,0x00}; const char char_0[] = {0x07,0x00,0x7C,0xA2,0x92,0x8A,0x7C,0x00}; const char char_1[] = {0x07,0x00,0x00,0x84,0xFE,0x80,0x00,0x00}; const char char_2[] = {0x07,0x00,0x84,0xC2,0xA2,0x92,0x8C,0x00}; const char char_3[] = {0x07,0x00,0x42,0x82,0x8A,0x96,0x62,0x00}; const char char_4[] = {0x07,0x00,0x30,0x28,0x24,0xFE,0x20,0x00}; const char char_5[] = {0x07,0x00,0x4E,0x8A,0x8A,0x8A,0x72,0x00}; const char char_6[] = {0x07,0x00,0x78,0x94,0x92,0x92,0x60,0x00}; const char char_7[] = {0x07,0x00,0x02,0xE2,0x12,0x0A,0x06,0x00}; const char char_8[] = {0x07,0x00,0x6C,0x92,0x92,0x92,0x6C,0x00}; const char char_9[] = {0x07,0x00,0x0C,0x92,0x92,0x52,0x3C,0x00}; const char char_DQ[] = {0x05,0x00,0x0E,0x00,0x0E,0x00}; const char char_SQ[] = {0x04,0x00,0x0A,0x06,0x00}; const char char_COLN[] = {0x04,0x00,0x6C,0x6C,0x00}; const char char_DEG[] = {0x05,0x00,0x0E,0x0A,0x0E,0x00}; const char char_BS[] = {0x07,0x00,0x40,0x20,0x10,0x08,0x04,0x00}; const char char_BLK[] = {0x07,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00}; const char char_CHK[] = {0x07,0x00,0x40,0x80,0x60,0x18,0x04,0x00}; const char char_AMP[] = {0x07,0x00,0x64,0x92,0xF2,0x82,0x7C,0x00}; const char char_CLPREN[] = {0x05,0x00,0x82,0x44,0x38,0x00}; const char char_RA[] = {0x07,0x00,0x10,0x10,0x54,0x38,0x10,0x00}; const char char_A[] = {0x07,0x00,0xFC,0x22,0x22,0x22,0xFC,0x00}; const char char_B[] = {0x07,0x00,0xFE,0x92,0x92,0x92,0x6C,0x00}; const char char_C[] = {0x07,0x00,0x7C,0x82,0x82,0x82,0x44,0x00}; const char char_D[] = {0x07,0x00,0xFE,0x82,0x82,0x44,0x38,0x00}; const char char_E[] = {0x07,0x00,0xFE,0x92,0x92,0x92,0x82,0x00}; const char char_F[] = {0x07,0x00,0xFE,0x12,0x12,0x12,0x02,0x00}; const char char_G[] = {0x07,0x00,0x7C,0x82,0x92,0x92,0xF4,0x00}; const char char_H[] = {0x07,0x00,0xFE,0x10,0x10,0x10,0xFE,0x00}; const char char_I[] = {0x07,0x00,0x00,0x82,0xFE,0x82,0x00,0x00}; const char char_J[] = {0x07,0x00,0x40,0x80,0x82,0x7E,0x02,0x00}; const char char_K[] = {0x07,0x00,0xFE,0x10,0x28,0x44,0x82,0x00}; const char char_L[] = {0x07,0x00,0xFE,0x80,0x80,0x80,0x80,0x00}; const char char_M[] = {0x07,0x00,0xFE,0x04,0x18,0x04,0xFE,0x00}; const char char_N[] = {0x07,0x00,0xFE,0x08,0x10,0x20,0xFE,0x00}; const char char_O[] = {0x07,0x00,0x7C,0x82,0x82,0x82,0x7C,0x00}; const char char_P[] = {0x07,0x00,0xFE,0x12,0x12,0x12,0x0C,0x00}; const char char_Q[] = {0x07,0x00,0x7C,0x82,0xA2,0x42,0xBC,0x00}; const char char_R[] = {0x07,0x00,0xFE,0x12,0x32,0x52,0x8C,0x00}; const char char_S[] = {0x07,0x00,0x8C,0x92,0x92,0x92,0x62,0x00}; const char char_T[] = {0x07,0x00,0x02,0x02,0xFE,0x02,0x02,0x00}; const char char_U[] = {0x07,0x00,0x7E,0x80,0x80,0x80,0x7E,0x00}; const char char_V[] = {0x07,0x00,0x3E,0x40,0x80,0x40,0x3E,0x00}; const char char_W[] = {0x07,0x00,0x7E,0x80,0x70,0x80,0x7E,0x00}; const char char_X[] = {0x07,0x00,0xC6,0x28,0x10,0x28,0xC6,0x00}; const char char_Y[] = {0x07,0x00,0x0E,0x10,0xE0,0x10,0x0E,0x00}; const char char_Z[] = {0x07,0x00,0xC2,0xA2,0x92,0x8A,0x86,0x00}; const char char_a[] = {0x07,0x00,0x40,0xA8,0xA8,0xA8,0xF0,0x00}; const char char_b[] = {0x07,0x00,0xFE,0x90,0x88,0x88,0x70,0x00}; const char char_c[] = {0x07,0x00,0x70,0x88,0x88,0x88,0x40,0x00}; const char char_d[] = {0x07,0x00,0x70,0x88,0x88,0x90,0xFE,0x00}; const char char_e[] = {0x07,0x00,0x70,0xA8,0xA8,0xA8,0x30,0x00}; const char char_f[] = {0x07,0x00,0x10,0xfc,0x12,0x02,0x04,0x00}; const char char_g[] = {0x07,0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00}; const char char_h[] = {0x07,0x00,0xFE,0x10,0x08,0x08,0xF0,0x00}; const char char_i[] = {0x05,0x00,0x88,0xFA,0x80,0x00}; const char char_j[] = {0x06,0x00,0x40,0x80,0x88,0x7A,0x00}; const char char_k[] = {0x06,0x00,0xFE,0x20,0x50,0x88,0x00}; const char char_l[] = {0x05,0x00,0x82,0xFE,0x80,0x00}; const char char_m[] = {0x07,0x00,0xF8,0x08,0x30,0x08,0xF0,0x00}; const char char_n[] = {0x07,0x00,0xF8,0x10,0x08,0x08,0xF0,0x00}; const char char_o[] = {0x07,0x00,0x70,0x88,0x88,0x88,0x70,0x00}; const char char_p[] = {0x07,0x00,0xF8,0x28,0x28,0x28,0x10,0x00}; const char char_q[] = {0x07,0x00,0x10,0x28,0x28,0x30,0xF8,0x00}; const char char_r[] = {0x07,0x00,0xF8,0x10,0x08,0x08,0x10,0x00}; const char char_s[] = {0x07,0x00,0x90,0xA8,0xA8,0xA8,0x40,0x00}; const char char_t[] = {0x07,0x00,0x08,0x7E,0x88,0x80,0x40,0x00}; const char char_u[] = {0x07,0x00,0x78,0x80,0x80,0x40,0xF8,0x00}; const char char_v[] = {0x07,0x00,0x38,0x40,0x80,0x40,0x38,0x00}; const char char_w[] = {0x07,0x00,0x78,0x80,0x60,0x80,0x78,0x00}; const char char_x[] = {0x07,0x00,0x88,0x50,0x20,0x50,0x88,0x00}; const char char_y[] = {0x07,0x00,0x18,0xa0,0xa0,0xa0,0x78,0x00}; const char char_z[] = {0x07,0x00,0x88,0xC8,0xA8,0x98,0x88,0x00}; const char char_Exe[] = {0x03,0x00,0x9E,0x00}; const char char_Dol[] = {0x07,0x00,0x48,0x54,0xFE,0x54,0x24,0x00}; const char char_PerC[] = {0x07,0x00,0x46,0x26,0x10,0xC8,0xC4,0x00}; const char char_UpHat[] = {0x07,0x00,0x08,0x04,0x02,0x04,0x08,0x00}; const char char_Amp[] = {0x07,0x00,0x6C,0x92,0xAA,0x44,0x80,0x00}; const char char_Astr[] = {0x07,0x00,0x28,0x10,0x7C,0x10,0x28,0x00}; const char char_OpPren[] = {0x05,0x00,0x38,0x44,0x82,0x00}; const char char_Minus[] = {0x07,0x00,0x10,0x10,0x10,0x10,0x10,0x00}; const char char_UnScr[] = {0x07,0x00,0x80,0x80,0x80,0x80,0x80,0x00}; const char char_Plus[] = {0x07,0x00,0x10,0x10,0x7C,0x10,0x10,0x00}; const char char_Eq[] = {0x07,0x00,0x28,0x28,0x28,0x28,0x28,0x00}; const char char_Period[] = {0x04,0x00,0xC0,0xC0,0x00}; const char char_Ques[] = {0x07,0x00,0x04,0x02,0xA2,0x12,0x0C,0x00}; const char char_GRT[] = {0x06,0x00,0x82,0x44,0x28,0x10,0x00}; const char char_LT[] = {0x06,0x00,0x10,0x28,0x44,0x82,0x00}; const char char_Coma[] = {0x04,0x00,0xA0,0x60,0x00}; const char char_Semi[] = {0x04,0x00,0xAC,0x6C,0x00}; const char char_UP_DWN[] = {0x07,0x00,0x24,0x42,0xFF,0x42,0x24,0x00}; /***************************************************************************** Name: InitDisplay() Parameters: none Returns: none Description: Sets up I/O and performs a general hardware reset of the LCD *****************************************************************************/ void InitDisplay(void) { Init_LCD_IO(); WR_PIN = HIGH; // Set Write pin as high RST_PIN = HIGH; // end reset of display vopcode = 37; // adjust for contrast Ra_Rb=0x27; return; } /***************************************************************************** Name: Wait(int time) Parameters: time Long delay time Returns: none Description: This function provides a long pause based on "time" *****************************************************************************/ void Wait(int time) { unsigned long int i; unsigned long int j; for (i=0;i 127-1){ conv_buff[j-1] = NULL; break; } } k++; } OutputData(Start_Col,j, nor_inv); return; } /***************************************************************************** Name: DisplayChar() Parameters: position Start Position on Line (Column0-127) value Single character to be written to display. Returns: none Description: This function writes a single ASCII chatacter to the LCD display. Page must be set up before calling with PosSetUp() *****************************************************************************/ void DisplayChar(unsigned char Start_Col, char value, int nor_inv) { char n; //buffer to return bit map data unsigned char k =0; int j = 0; unsigned char b; char_con[0] = value; char_con[1] = NULL; while (char_con[k] != NULL){ char_conv(char_con + k); //upon return m has the address of the bitmap of the character col_count = *m; //get the count for columns for character for (b = 0;b != col_count;b++){ conv_buff[j++] = *(m+1+b); } k++; } OutputData(Start_Col,j,nor_inv); return; } /***************************************************************************** Name: OutputData() Parameters: position Start Position on Line (Column0-127) value Single character to be written to display. Returns: none Description: This function outputs data to be displayed to the LCD *****************************************************************************/ void OutputData(unsigned char Start_Col,int j,int nor_inv) { unsigned char a,pass; col = Start_Col; // set the starting column LCD_write_COLUMN(Start_Col); for( i=0;i> 4; //shift upper nibble 4 places to the right a = (a & 0x0F) + 0x10; //mask off upper nibble DI_PIN = LOW; EN_PIN = LOW; // Enable LCD DATA_PORT = (char) a; // Output data DisplayDelay(0); WR_PIN = LOW; // Enable Write WR_PIN = HIGH; // Disable Write EN_PIN = HIGH; // Disable LCD a = value & 0x0F; // Mask off upper nibble EN_PIN = LOW; // Enable LCD DATA_PORT = (char) a; // Output data DisplayDelay(0); WR_PIN = LOW; // Enable Write WR_PIN = HIGH; // Diasble Write EN_PIN = HIGH; // Disable LCD return; } /***************************************************************************** Name: clear_display() Parameters: start line (0-15) and end line (0-15) Returns: none Description: Routine to clear the LCD display. To clear the entire display - clear_display(0,15). i.e. To just clear lines 4 and 5 - clear_display(4,5) *****************************************************************************/ void Clear_Display(int start, int end) { int page; int col; if (end >15) // end page cannot be more than 15 end = 15; if (start > end) // start page cannot be less than end page start = end; page = start; // set the start page col = 0; // set the column counter to 0 PosSetUp(page, col); do{ if (col == 128) { // has the column count reacted 128? col = 0; // if so then set col counter to 0 page++; // increment page counter if (page > end) // if gone past last page, break break; else PosSetUp(page, col); // else point LCD to next page, col } LCD_write_Data(SPACE, NORMAL); // write a space to current LCD location col++; // increment column counter }while (page < end+1); // as long as we have not gone past the end page return; } /***************************************************************************** Name: Display_Grapic() Parameters: pointer to string which contains formatting info and data. The data is 8 pixels high, with the LSB at the top and the MSB at the bottom of the column of 8 pixels. This example is of a pirate ship and requires 4 lines (each 8 pixels high) and is 40 pixels (columns) wide. const char pirate_ship [] = { 0x04, // number of lines of data 12,60,40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0xc0, 0xc0,0x40,0xc0,0xc0,0xc0,0xc0,0xc0,0x40, 0xc0,0xc0,0xc0,0xc0,0xc0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 13,60,40,0x00,0x00,0xc0,0xc0,0xc0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x7f, 0x7f,0x5f,0x6e,0x75,0x7b,0xf5,0x6e,0x5f, 0x7f,0x7f,0x7f,0x7f,0x7f,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 14,60,40,0x00,0x00,0x00,0x00,0x3f,0xc2,0x0a,0x02, 0x0a,0x02,0x4a,0x02,0x04,0x48,0x10,0x10, 0x50,0x10,0x10,0x50,0x10,0x1f,0x50,0x10, 0x10,0x50,0x10,0x10,0x50,0x10,0x90,0x50, 0x30,0x10,0x08,0x04,0x00,0x00,0x00,0x00, 15,60,40,0x02,0x02,0x02,0x02,0x02,0x02,0x03,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02 }; Returns: none Description: Displays graphics anywhere on the display *****************************************************************************/ void Display_Graphic(_far char *lcd_string) { int x,y,z,a,b,c,d; x = z = 0; y = lcd_string[x++]; // number of lines do{ a = lcd_string[x++]; //get page number b = lcd_string[x++]; //get start column number PosSetUp(a,b); c = lcd_string[x++]; //get number of data bytes for (d = 0;d': m = char_GRT; break; case '<': m = char_LT; break; case ',': m = char_Coma; break; case ';': m = char_Semi; break; case 0x84: m = char_UP_DWN; } return(m); } /***************************************************************************** Name: Init_LCD_IO() Parameters: None Returns: None Description: Sets up I/O ports for LCD Display These commands are specific to the microprocessor used. They are placed seperate so to ease the transistion to another processor. *****************************************************************************/ void Init_LCD_IO(void) { // Setup for a Renesas M16C/M62P M30622F8P Processor prc2 = HIGH; // Enable writes to protected registers DATA_PORT = DATA_PORT_DDR_VALUE_OUT; // output 0xff to dataport prc2 = HIGH; // Enable wirtes to protected registers DATA_PORT_DDR = DATA_PORT_DDR_VALUE_OUT; // setup data port of output EN_PIN_DDR = OUTPUT; // Set Enable pin to output EN_PIN = HIGH; // Set Enable pin to high RST_PIN_DDR = OUTPUT; // Set Reset pin to output RST_PIN = HIGH; // Set Reset pin to high DisplayDelay(20); // 20ms delay RST_PIN = LOW; // Set Reset to low DSP_PWM_DDR = OUTPUT; // Set display backlight PWM to output DSP_PWM = HIGH; // Set display backlight to high DI_DDR = OUTPUT; // Set Data/Instruction pin to output DI_PIN=HIGH; // Set D/I pin as high WR_PIN_DDR = OUTPUT; // Set Write pin to output return; } /***************************************************************************** Name: DisplayDelay() Parameters: 1ms = 1 10ms = 10 Returns: none Description: DisplayDelay routine for LCD display. *****************************************************************************/ void DisplayDelay(unsigned long int units){ unsigned long int counter = units * 0x100; while(counter--){ _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); _asm ("NOP"); } return; }