// LCD.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" // for WRITE_PORT_UCHAR #include "..\cesysgen\ddk\inc\ceddk.h" #define MAX_LOADSTRING 100 // CONSTANTS FOR LCD SCREEN ///////////////////////////////////////////////////// #define PORT_DATA 0x3E0 #define PORT_CONTROL 0x3E1 /* enable is clocked high then low */ #define LCD_ENABLE_HIGH 0x02 #define LCD_ENABLE_LOW 0x00 /* RS line is low for command, high for characters */ #define LCD_RS_HIGH 0x01 #define LCD_RS_LOW 0x00 #define LCD_CURSOR_POS 0x80 /* delays for setup & data hold times... 40us and 1.64ms */ #define LCD_STARTUP_DELAY 50 #define LCD_CONTROL_DELAY 2 #define LCD_DATA_DELAY 1 const unsigned char LCD_init_string[] = { 0x33, /* 8-bit, 1 row, 5x7 dots */ 0x01, /* clear display */ 0x0c, /* display on, cursor off, blink off */ 0x06, /* increment cursor pos, no display shift */ 0x00 /* end of array marker */ }; // Borland -> MS C conversion #define outportb(a,b) WRITE_PORT_UCHAR((PUCHAR) a, (UCHAR) b) #define delay(a) Sleep(a) // CONSTANTS FOR LCD SCREEN ///////////////////////////////////////////////////// // FUNCTIONS FOR LCD SCREEN ///////////////////////////////////////////////////// void LCD_put_data(unsigned char c) { outportb(PORT_CONTROL, LCD_RS_HIGH | LCD_ENABLE_HIGH); delay(LCD_DATA_DELAY); outportb(PORT_DATA, c); delay(LCD_DATA_DELAY); outportb(PORT_CONTROL, LCD_RS_HIGH | LCD_ENABLE_LOW); delay(LCD_DATA_DELAY); } void LCD_put_control(unsigned char c) { outportb(PORT_CONTROL, LCD_RS_LOW | LCD_ENABLE_HIGH); delay(LCD_CONTROL_DELAY); outportb(PORT_DATA, c); delay(LCD_CONTROL_DELAY); outportb(PORT_CONTROL, LCD_RS_LOW | LCD_ENABLE_LOW); delay(LCD_CONTROL_DELAY); } __declspec( dllexport ) void LCD_put_data_string(unsigned short s[]) { unsigned short *tempptr; tempptr = s; LCD_put_control(LCD_CURSOR_POS); while(*tempptr != 0x00) { LCD_put_data((char) *tempptr); tempptr++; /* go to next char */ } } __declspec( dllexport ) void LCD_init(void) { const unsigned char *tempptr; delay(LCD_STARTUP_DELAY); outportb(PORT_CONTROL, LCD_RS_LOW | LCD_ENABLE_LOW); tempptr = LCD_init_string; while(*tempptr != 0x00) { LCD_put_control(*tempptr); tempptr++; /* go to next char */ } } // FUNCTIONS FOR LCD SCREEN ///////////////////////////////////////////////////// BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }