Chảo,
I hope this works, but if you have any questions, I'll keep watching here...
first the driver
Code:
////////////////////////////////////////////////////////////////////////////
//// Library for a 2 wire LCD interface using an 74hc174 ////
//// ////
//// ////
////////////////////////////////////////////////////////////////////////////
#ifndef LCD_clk
#define LCD_data PIN_B2
#define LCD_clk PIN_B1
#endif
void LCDInit(void) { // Initialize the LCD I/O Pins
Dlay = RTC +20;
while (Dlay != RTC);
LCDNybble(0x003, 0); // send init command
Dlay = RTC + 6; // wait > 5 mSec for
while (Dlay != RTC); // LCD to accept cmd
LCDNybble(0x003, 0); // send init command
Dlay = RTC + 1; // wait > 160 uSec for
while (Dlay != RTC); // LCD to accept cmd
LCDNybble(0x003, 0); // send init command
Dlay = RTC + 1; // wait > 160 uSec for
while (Dlay != RTC); // LCD to accept cmd
LCDNybble(0x002, 0); // send init command 0000 0010
Dlay = RTC + 6; // wait > 5 msec for
while (Dlay != RTC); // LCD to accept cmd
LCDByte(0x028, 0); // step 6, set operating 0010 1000
LCDByte(0x008, 0); // step 7, display off 0000 1000
LCDByte(0x001, 0); // step 8, clear display 0000 0001
LCDByte(0x006, 0); // step 9, shift 0000 0110
LCDByte(0x00E, 0); // step 10, display on 0000 1110
} // End LCDInit
void LCDNybble(char Nybble, char RS) { // Send Nybble to LCD
int i; // removed unsigned from before int
output_low(PIN_B2); //Data = 0; // Clear the '174
for (i = 0; i < 6; i++) { // Repeat for six bits
//Clock = 1; Clock = 0; // Write the "0"s into the '174
output_high(PIN_B1);
output_low(PIN_B1);
} // endfor
//Data = 1; // Output the "AND" Value
output_high(PIN_B2);
//Clock = 1; Clock = 0;
output_high(PIN_B1);
output_low(PIN_B1);
// Data = RS; // Output the RS Bit Value
if (RS>0)output_high(PIN_B2);
else output_low(PIN_B2);
//Clock = 1; Clock = 0;
output_high(PIN_B1);
output_low(PIN_B1);
for (i = 0; i < 4; i++) { // Output the Nybble
if ((Nybble & 0x008) != 0)
// Data = 1; // Output the High Order Bit
output_high(PIN_B2);
else
//Data = 0;
output_low(PIN_B2);
//Clock = 1; Clock = 0; // Strobe the Clock
output_high(PIN_B1);
output_low(PIN_B1);
Nybble = Nybble << 1; // Shift up Nybble for Next Byte
} // endfor
// Data = 1; Data = 0; // Toggle the "E" Clock Bit
output_high(PIN_B2);
output_low(PIN_B2);
} // End LCDNybble
void LCDByte(char myByte, char RS) { // Send Byte to LCD
int LBDlay;
LCDNybble((myByte >> 4) & 0x00F, RS); // Send High Nybble
LCDNybble(myByte & 0x00F, RS); // Send Low Nybble
if ((myByte < 4) && (RS == 0)) // type of instruction
LBDlay = RTC + 6;
else
LBDlay = RTC + 2;
while (LBDlay != RTC); // command to complete wait
} // End LCDByte
void send_c(char myByte) { // Send Byte to LCD
int LBDlay;
char RS = 1;
LCDNybble((myByte >> 4) & 0x00F, RS); // Send High Nybble
LCDNybble(myByte & 0x00F, RS); // Send Low Nybble
if ((myByte < 4) && (RS == 0)) // type of instruction
LBDlay = RTC + 6;
else
LBDlay = RTC + 2;
while (LBDlay != RTC); // command to complete wait
} // End send_c
void SecondLine(void) {
LCDByte(0xC0, 0);
} // end SecondLine
void Home(void) {
LCDByte(0x02, 0);
} // end Home
void ClearLCD(void) {
LCDByte(0x01, 0);
} // end ClearLCD
then a test program
Code:
#if defined(__PCM__)
#include <16F84A.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B6, rcv=PIN_B7)
#endif
#include "LCDHG.C"
#include <STDIO.h>
#include <string.h>
#define CDCLK Pin_B1
//#define LCDDAT Pin_B2
void main() {
int x, y, c;
x = 0x01;
y = 0x01;
c = 0x55;
// char *c;// = "H";
// char string[20];
//c="H";
lcd_init();
lcd_gotoxy(x, y);
lcd_putc("\f");
lcd_putc(0x55);
while(1) {
;
} // end while
}