การแสดงข้อความบนโมดูล LCD 16 x 2 อย่างง่ายด้วย PIC กับ LCD.C กับ CCS C Compiler  โค้ดโปรแกรม

/*******************************************************************************
* Workfile : EX0304_EasyLCD.c
* Purpose : LCD 4bit Mode
* Copyright : appsofttech co.,ltd.
* Author : Prajin Palangsantikul
* Email : prajin@appsofttech.com
* Compiler : CCS C Compiler
* Target : PIC16F877A
* Ref :
*******************************************************************************/

/*********************************************************************** NOTE */
/*
* * LCD 4 bit mode
* D0 = enable , D1 = rs , D2 = rw
* D4 = D4 , D5 = D5 , D6 = D6 , D7 = D7
* LCD pins D0-D3 are not used and PIC D3 is not used.
*/

/******************************************************************** Include */
/** Set PIC Device use here */
#include <16F877A.H> // PIC16F877A device

/** Set Configuration word & Oscillator here */
#fuses HS,NOWDT,NOPROTECT,NOLVP // Configuration word
#use delay(clock=20000000) // Change OSC here (default 20MHz)

#include <lcd.c> // module lcd

/*********************************************************************** Main */
void main()
{
int i;
lcd_init(); // LCD init

lcd_putc("\fLCD Ready...\n"); // use function lcd_putc()

delay_ms(1000);

printf(lcd_putc,"\f<< LCD line 1 >>"); // use function printf() + lcd_putc()
i = 2;
printf(lcd_putc,"\n<< LCD line %d >>",i);

}
/************************** End of $Workfile: $ ******************************/