You are on page 1of 3

Explorer1332_LCD_customCFile.c sprintf(buffer, "Voltage:%.

2f ",
v);
Lcd_Set_Cursor(2,1);
#include "explorer16_lcd.h" Lcd_Write_String(buffer);
}

void LCD_StartUp(){

unsigned int a;

// TRISB &= ~(1 << 15); // RS void PrintTemperature(double temp){


// TRISD &= ~(1 << 4); // EN
char buffer[17];
// TRISE &= ~(1 << 4); // D4 sprintf(buffer, "Temp:%.2f\xDF%C ",
// TRISE &= ~(1 << 5); // D5 temp);
// TRISE &= ~(1 << 6); // D6 Lcd_Set_Cursor(1,1);
// TRISE &= ~(1 << 7); // D7 Lcd_Write_String(buffer);
}
Lcd_Init();
Lcd_Clear();
void PrintCPU(double CPU_Load){
Lcd_Set_Cursor(1,1);
Lcd_Write_String(" LCD DEMO"); char buffer[17];
Lcd_Set_Cursor(2,1); sprintf(buffer, "%CPU load: %.2f%% ",
Lcd_Write_String(" Explorer 16/32"); CPU_Load);
__delay_ms(3000); Lcd_Set_Cursor(2,1);
Lcd_Clear(); Lcd_Write_String(buffer);
Lcd_Set_Cursor(1,1); }
Lcd_Write_String("Press S4 button");
Lcd_Set_Cursor(2,1); explorer16_lcd.c
Lcd_Write_String("to switch mode"); #include "explorer16_lcd.h"
__delay_ms(5000);
Lcd_Clear();
Lcd_Set_Cursor(1,1); /* Ports must be declared as output: */
Lcd_Write_String("Move POT slider"); /* #define RS LATBbits.LATB15 */
Lcd_Set_Cursor(2,1); /* #define EN LATDbits.LATD4 */
Lcd_Write_String("to inc. voltage"); /* */
__delay_ms(5000); /* #define D4 LATEbits.LATE4 */
} /* #define D5 LATEbits.LATE5 */
/* #define D6 LATEbits.LATE6 */
/* #define D7 LATEbits.LATE7 */
void PrintMinutes(unsigned int minutes){
void LCD_Initilisation() {
char buffer[17];
sprintf(buffer, "Up time:%02u:",
minutes); __delay_ms(200);
Lcd_Set_Cursor(1,1); Lcd_Init();
Lcd_Write_String(buffer); }
}

void PrintSeconds(unsigned int seconds){ void LCD_Write_xy( char* buffer ,


unsigned int x, unsigned int y){
char buffer[17]; Lcd_Set_Cursor(y,x);
sprintf(buffer, "%02u ", seconds); Lcd_Write_String((char*) buffer);
Lcd_Set_Cursor(1,12); }
Lcd_Write_String(buffer);
} void LCD_Write( char* buffer ){
Lcd_Write_String((char*) buffer);
void PrintVoltage(double v){ }

char buffer[17];
RS = 0;
// ------------ LCD Functions Header --- D4 = 0;
---------------- D5 = 0;
#ifndef LCD_H D6 = 0;
#define LCD_H D7 = 0;

#include <MCHP_modelInclude.h> // // Initialization for Truly LCD


with Novatek chip (Explorer 16/32
/* Define Interface Pins */ development board)
/* Theses PORT must be defined as output // // Use twice the FunctionSet
*/ instruction "Lcd_Cmd(0x02),
/* Within the Simulink C Function Call Lcd_Cmd(0x08)" to overcome the issue with
block */ Explorer 16/32 reset
// __delay_ms(50);
// Lcd_Cmd(0x02); // Function Set
//Define Interface Pins // Lcd_Cmd(0x08); // Function Set
#define RS LATBbits.LATB15 (N=1:2 or 4 lines Mode, F=0:5x7 dots)
#define EN LATDbits.LATD4 // __delay_ms(10);
// Lcd_Cmd(0x02); // Function Set
#define D4 LATEbits.LATE4 // Lcd_Cmd(0x08); // Function Set
#define D5 LATEbits.LATE5 (N=1:2 or 4 lines Mode, F=0:5x7 dots)
#define D6 LATEbits.LATE6 // __delay_us(50);
#define D7 LATEbits.LATE7 // Lcd_Cmd(0x00); // Display ON/OFF
Control
/* #define LCD_COMMAND_CLEAR_SCREEN // Lcd_Cmd(0x0C); // Display control
0x01 */ (D=1:Display On, C=0:Cursor OFF,
/* #define LCD_COMMAND_RETURN_HOME B=0:Blink OFF)
0x02 */ // __delay_us(50);
/* #define LCD_COMMAND_ENTER_DATA_MODE // Lcd_Cmd(0x00); // Clear Display
0x06 */ // Lcd_Cmd(0x01); // Clear Display
/* #define LCD_COMMAND_CURSOR_OFF // __delay_ms(3);
0x0C */ // Lcd_Cmd(0x00); // Entry Mode Set
/* #define LCD_COMMAND_CURSOR_ON // Lcd_Cmd(0x02); // Entry Mode Set
0x0F */ (I/D=1:increment mode, S=0:entire shift
/* #define LCD_COMMAND_MOVE_CURSOR_LEFT OFF)
0x10 */
/* #define LCD_COMMAND_MOVE_CURSOR_RIGHT
0x14 */ //New Raystar LCD init routine
/* #define LCD_COMMAND_SET_MODE_8_BIT //Step 1
0x38 */ __delay_ms(100);
/* #define LCD_COMMAND_ROW_0_HOME //Step 2
0x80 */ Lcd_Cmd(0b0011);
/* #define LCD_COMMAND_ROW_1_HOME __delay_ms(5);
0xC0 */ //Step 3
Lcd_Cmd(0b0011);
void Lcd_Cmd(char a) __delay_us(100);
{ //Step 4
EN = 0; Lcd_Cmd(0b0011);
RS = 0; __delay_us(100);
D4 = (a & 1)>>0; //Step 5
D5 = (a & 2)>>1; Lcd_Cmd(0b0010);
D6 = (a & 4)>>2; __delay_us(100);
D7 = (a & 8)>>3; //Step 6
EN = 1; Lcd_Cmd(0b0010);
__delay_us(1); Lcd_Cmd(0b1000);
EN = 0; __delay_us(60);
__delay_us(1); //Step 7
} Lcd_Cmd(0b0000);
Lcd_Cmd(0b1000);
//Initialization routine for the LCD __delay_us(60);
void Lcd_Init(){ //Step 8
EN = 0; Lcd_Cmd(0b0000);
Lcd_Cmd(0b0001); z = temp>>4;
__delay_ms(4); y = temp & 0x0F;
//Step 9 Lcd_Cmd(z);
Lcd_Cmd(0b0000); Lcd_Cmd(y);
Lcd_Cmd(0b0110); __delay_us(60);
__delay_us(60); }
// Step 10: Initialization ends, but else if(a == 3)
the display is OFF, so turn it ON with {
next cmd temp = 0x94 + b - 1;
//Step 11 z = temp>>4;
Lcd_Cmd(0b0000); y = temp & 0x0F;
Lcd_Cmd(0b1100); Lcd_Cmd(z);
__delay_us(60); Lcd_Cmd(y);
__delay_us(60);
} }
else if(a == 4)
//Clear entire display and sets DDRAM {
address 0 in address counter. temp = 0xD4 + b - 1;
void Lcd_Clear(){ z = temp>>4;
Lcd_Cmd(0x0); y = temp & 0x0F;
Lcd_Cmd(0x1); Lcd_Cmd(z);
__delay_us(2000); Lcd_Cmd(y);
} __delay_us(60);
}
}
//Sets DDRAM address 0 in address
counter. Also returns display from being
//shifted to original position. DDRAM void Lcd_Write_Char(char a)
contents remain unchanged. {
void LCD_Return_Home(){ char temp;
Lcd_Cmd(0x0); char y;
Lcd_Cmd(0x2);
__delay_us(2000); temp = a&0x0F;
} y = a&0xF0;
RS = 1;
void Lcd_Shift_Right(){ EN = 0;
Lcd_Cmd(0x01); D4 = ((y>>4) & 1)>>0;
Lcd_Cmd(0x0C); D5 = ((y>>4) & 2)>>1;
__delay_us(60); D6 = ((y>>4) & 4)>>2;
} D7 = ((y>>4) & 8)>>3;
EN = 1;
__delay_us(50);
void Lcd_Shift_Left(){ EN = 0;
Lcd_Cmd(0x01); __delay_us(50);
Lcd_Cmd(0x08); D4 = (temp & 1) >> 0;
__delay_us(60); D5 = (temp & 2) >> 1;
} D6 = (temp & 4) >> 2;
D7 = (temp & 8) >> 3;
//Set DDRAM address EN = 1;
void Lcd_Set_Cursor(char a, char b) __delay_us(50);
{ EN = 0;
char temp,z,y; __delay_us(50);
if(a == 1) }
{
temp = 0x80 + b - 1; void Lcd_Write_String(char *a)
z = temp>>4; {
y = temp & 0x0F; int i;
Lcd_Cmd(z); for(i=0; a[i]!='\0'; i++)
Lcd_Cmd(y); Lcd_Write_Char(a[i]);
__delay_us(60); }
}
else if(a == 2)
{ #endif
temp = 0xC0 + b - 1;

You might also like