#include <pic1687x.h>
#include "delay.c"
#define LCD_RS RA2 //Register Select
#define LCD_EN RA3 //Enable
#define LCD_CS RA5 //Chip Enable (Attivo a 0)
#define LCD_D0 RB0 //LCD Data 0
#define LCD_D1 RB1 //LCD Data 1
#define LCD_D2 RB2 //LCD Data 2
#define LCD_D3 RB3 //LCD Data 3
#define LCD_D4 RB4 //LCD Data 4
#define LCD_D5 RB5 //LCD Data 5
#define LCD_D6 RB6 //LCD Data 6
#define LCD_D7 RB7 //LCD Data 7
int x;
int row, col;
void LCD_STROBE();
void ins_reg (int byte)
{
PORTB = byte;
LCD_RS = 1; //Write Instruction
LCD_CS = 0; //Chip Enable
LCD_STROBE();
LCD_CS= 1; //Chip Disable
}
void data_reg (int byte)
{
PORTB = byte;
LCD_RS = 0; //Write Data
LCD_CS = 0; //Chip Enable
LCD_STROBE();
LCD_CS= 1; //Chip Disable
}
void Command (int reg_addr, int data_addr)
{
ins_reg(reg_addr);
data_reg(data_addr);
}
void LCD_STROBE ()
{
LCD_EN = 0;
DelayMs(1);
LCD_EN = 1;
}
const unsigned char Text_Screen[16][41]=
{"01234567890123456789012345678901 00 6789", // 00
"012345678 901 01 6789", // 01
"012345678 40 col by 16 lines 901 02 6789", // 02
"012345678 of 5x7 text 901 03 6789", // 03
"012345678 built-in font 901 04 6789", // 04
"012345678 901 05 6789", // 05
"01234567890123456789012345678901 06 6789", // 06
"01234567890123456789012345678901 07 6789", // 07
"01234567890 678901 08 6789", // 08
"01234567890 ABCDEFGHIJKLM 678901 09 6789", // 09
"01234567890 NOPQRSTUVWXYZ 678901 10 6789", // 10
"01234567890 abcdefghijklm 678901 11 6789", // 11
"01234567890 nopqrstuvwxyz 678901 12 6789", // 12
"01234567890 678901 13 6789", // 13
"01234567890123456789012345678901 14 6789", // 14
"01234567890123456789012345678901 15 6789"}; // 15
main()
{
DelayMs(250);
TRISA = 0;TRISB = 0; //Port A & B Set as OutPut
LCD_CS = 1; //Chip Disable
LCD_EN = 1;
LCD_RS = 1;
PORTB = 0b00000000; //DB0 - DB7 all at low level
DelayMs(250);
// START INIT ***
Command(0,60); //Mode Control 00111100
Command(1,117); //Character Pitch 01110101
Command(2,39); //Number of Char.
Command(10,0); //Cursor low address setting
Command(11,0); //Cursor hiigh address setting
//Send data command
PORTB = 0b00001100; //write code "0CH"
LCD_RS = 1;
LCD_CS = 0; //Chip Enable
DelayMs(20);
LCD_STROBE();
LCD_RS = 0;
DelayMs(20);
for(row=0;row<=15;row++)
for(col=0;col<=39;col++)
{
PORTB = Text_Screen[row][col];
DelayMs(20);
LCD_STROBE();
}
LCD_CS = 1;
while(100);
}