Wednesday, July 21, 2010

Interfacing Wintek WD-C2401P LCD with Microchip PIC

 Wintek WD-C2401P LCD panel is a 24x1 character display. The code for using the LCD was written for microchip PIC 16F88 but should work with all other micro controllers.

Pinout for the WD-C2401P

Pin #NameFunction
1VssGround ( 0v)
2Vdd+5 volts
3ResetWhen this pin is low it resets the LCD. You can either tie this pin to a pin on your microcontroller so you can reset the LCD before initializtion, or just tie it high. I had a couple of times where I couldn't init the LCD without first resetting it, so I'd recommend putting it under micro control, or some other powerup controller. The reset low time should be at least 10ms. The time after reset before you start commanding the LCD should also be at least 10 ms.
4RSRegister Select. This pin determines whether the data you're about to write is a command or a data byte. Commands do interesting stuff to the LCD, like set the number of lines or contrast. Data is what actually gets put on the screen, or in the custom character registers. High means Data, Low means command
5Read/WriteSet this pin high to read from the display. Set this pin low to write to it. If you don't need to update the display super fast you can save an I/O line by just tying it to ground. Wait at least a millisecond between each command and data, though, since you can't query the busy status without read capability.
6EEnable. This line works to clock in data and commands. See the protocol section below.
7DB0Least Significant Data Bit
8DB1
9DB2
10DB3
11DB4
12DB5
13DB6
14DB7

 Details of soldering the pins are available at http://www.serialwombat.com/parts/lcd111.htm


lcd_wintek_wdc2401p.h:

#define E_LO  PORTA &= ~0x80;  //RA7
#define E_HI  PORTA |=0x80
#define RS_HI  PORTA |=0x40 //RA6
#define RS_LO  PORTA &= ~0x40
#define RESET_LO PORTA &= ~0x04
#define RESET_HI PORTA |= 0x04
#define LCD_DATA PORTB

#define DELAY10MS __delay_ms(10)
#define DELAY1MS __delay_ms(1)
#define DELAY5MS __delay_ms(5)
#define DELAY20MS __delay_ms(20)
#define DELAY90MS __delay_ms(90)
#define DELAY0_5MS __delay_us(500)
#define DELAY5US __delay_us(5)

void LCDInitialize();
void LCDWriteChar(char c);
void LCDClockByte(char c); //Called internally do not use
void LCDClearScreen();
void LCDWriteString(char *s);
void LCDResetChar(); //Return back to first address


lcd_wintek_wdc2401p.c:

#include "lcd_wintek_wdc2401p.h"

void LCDInitialize()
{

 DELAY90MS;
 RESET_LO;
 DELAY20MS;
 RESET_HI;
 DELAY20MS;
 
 //Initialize Sequence
 E_LO;
 DELAY5US;
 RS_LO;
 DELAY1MS;
 LCDClockByte(0x1C); //Turn on the lcd driver power
 LCDClockByte(0x14); //Turn on the character display
 LCDClockByte(0x28); //Set two display lines (The hd66717 considers
     //12 characters to be a line. Our 24 character display is
     //actually two 12-character lines right next to each other).    
 LCDClockByte(0x4F); //Set to darkest contrast
 LCDClockByte(0xE0); //Set the data address to the first character
 DELAY5MS;
}

void LCDClockByte(char c)
{
 DELAY1MS;
 LCD_DATA = c;
 E_HI;
 DELAY5US;
 E_LO;
}

void LCDWriteChar(char c)
{ 
 RS_HI;
 LCDClockByte(c);
}
void LCDResetChar()
{
 RS_LO;
 LCDClockByte(0x02);

}
void LCDWriteString( char *s)
{
 unsigned char c,i,end_flag=0;
 DELAY1MS;
 LCDResetChar();
 DELAY1MS;
 for(i=0;i< 24;i++) {
 
  c = (s[i] == 0x00)?'-':s[i];
  
  if(s[i] == 0x00 || end_flag == 1){
   c = ' ';
   end_flag = 1;
  } else {
   c = s[i];
  }
  LCDWriteChar(c);  
 }
} 

void LCDClearScreen()
{
 RS_LO;
 LCDClockByte(0x01);
}


main.c: (Sample Usage)
#include "lcd_wintek_wdc2401p.h"
main() {
 //Make sure you setup the pins on the micro controller for output
       // and designate the pins properly in the include file. 
 char s[]="abcdefghijklmnop";
 LCDInitialize();
 LCDClearScreen(); 
 LCDWriteString(s);
}

YDLidar (lidar) X4 API in golang

YDLidar X4 This is a demo of the YDLidar using a golang API. The software supplied with the device only contains the drivers in C++ an...