PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > English forum on PICs

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

English forum on PICs Forum for foreigners -only English in this forum - Do not need to register or login

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 30-07-2006, 12:49 PM   #6
BêBop
Nhập môn đệ tử
 
Tham gia ngày: Jul 2006
Nơi Cư Ngụ: Sưon South Kỏea
Bài gửi: 6
:
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
}
BêBop vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến

Similar Threads
Ðề tài Người gửi Chuyên mục Trả lời Bài mới
Về mạch nạp Microchip PICKit2 và PIC16F84A linhbx Bootloaders - Programmers - Debuggers - Emulators 7 12-12-2006 11:39 AM
Xin file hex bootloader của PIC16F84A hanhluckyly Tiny Bootloader 1 18-10-2006 09:36 PM
8 wire stepper motor briantk_1988 Cơ cấu chấp hành (Actuator) 3 30-09-2006 11:51 PM
One wire voi PIC16F84A briantk_1988 Các ngôn ngữ lập trình khác (CCS C, HT PIC,...) 13 26-07-2006 08:16 PM


Múi giờ GMT. Hiện tại là 02:07 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam