วันศุกร์ที่ 19 มีนาคม พ.ศ. 2553

งานเข้านิดหน่อย


ช่วงนี้งานมันเยอะเหลือเกิน งานไหลมาเทมา ถ้าเปลี่ยนงานเป็นเงินล่ะก็ อิอิ คงรวยน่าดู มีคนถามเรื่อง lcd16x4 เข้ามา ก็เลยจัดไปสักหน่อย อันไหนช่วยกันได้ก็ช่วยกัน ช่วยไม่ได้ก็ตัวใครตัวมัน 555 +++
ขอขอบคุณ Libraly By PCM Programmer

เอ้าแจกโค๊ด

ไพล์หลักครับ
/**
#include <16f877a.h>
#fuses HS, NOWDT, NOPROTECT,NOLVP
#use delay(clock = 20000000)
#include "Flex_LCD416.c"

void main()
{

lcd_init();
printf(lcd_putc, "\f");
delay_ms(500);

while(true)
{
lcd_gotoxy(7,1);
printf(lcd_putc, "TEST");
lcd_gotoxy(5,2);
printf(lcd_putc, "LCD 16x4");
lcd_gotoxy(8,3);
printf(lcd_putc, "By");
lcd_gotoxy(5,4);
printf(lcd_putc, "nont_peet");
delay_ms(1000);
}
}
**/

Libraly Flex_LCD416.c

/**
// Flex_LCD416.c

// These pins are for my Microchip PicDem2-Plus board,
// which I used to test this driver.
// An external 20x4 LCD is connected to these pins.
// Change these pins to match your own board's connections.

#define LCD_DB4 PIN_D3
#define LCD_DB5 PIN_D4
#define LCD_DB6 PIN_D5
#define LCD_DB7 PIN_D6

#define LCD_RS PIN_D0
#define LCD_RW PIN_D1
#define LCD_E PIN_D2

/*
// To prove that the driver can be used with random
// pins, I also tested it with these pins:
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_B1
#define LCD_DB6 PIN_C5
#define LCD_DB7 PIN_B5

#define LCD_RS PIN_E2
#define LCD_RW PIN_B2
#define LCD_E PIN_D6
*/

// If you want only a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line. Doing so will save one PIC
// pin, but at the cost of losing the ability to read from
// the LCD. It also makes the write time a little longer
// because a static delay must be used, instead of polling
// the LCD's busy bit. Normally a 6-pin interface is only
// used if you are running out of PIC pins, and you need
// to use as few as possible for the LCD.
#define USE_RW_PIN 1


// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x10
#define LCD_LINE_4_ADDRESS 0x50

// These are the line addresses for LCD's which use
// the Hitachi HD66712U controller chip.
/*
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x20
#define LCD_LINE_3_ADDRESS 0x40
#define LCD_LINE_4_ADDRESS 0x60
*/


//========================================

#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines(or more)

int8 lcd_line;

int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << retval_0 =" retval.0" retval_1 =" retval.1" retval_2 =" retval.2" retval_3 =" retval.3" retval =" 0;" retval_0 =" input(LCD_DB4);" retval_1 =" input(LCD_DB5);" retval_2 =" input(LCD_DB6);" retval_3 =" input(LCD_DB7);" high =" lcd_read_nibble();" low =" lcd_read_nibble();">> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------

void lcd_init(void)
{
int8 i;

lcd_line = 1;

output_low(LCD_RS);

#ifdef USE_RW_PIN
output_low(LCD_RW);
#endif

output_low(LCD_E);

// Some LCDs require 15 ms minimum delay after
// power-up. Others require 30 ms. I'm going
// to set it to 35 ms, so it should work with
// all of them.
delay_ms(35);

for(i=0 ;i < i="0;" address =" LCD_LINE_1_ADDRESS;" address =" LCD_LINE_2_ADDRESS;" address =" LCD_LINE_3_ADDRESS;" address =" LCD_LINE_4_ADDRESS;" address =" LCD_LINE_1_ADDRESS;" lcd_line =" 1;" value =" lcd_read_byte();">

ไม่มีความคิดเห็น:

แสดงความคิดเห็น