* 22-11-09 Use LCD to move and flash text Images
Requirements: mplab 8.2 or above, MEO engineering board, PIC16-MCD2 simulation download, 1602 LCD screen
Chip configuration word, watchdog off, power-on delay on, power-down detection off, low-voltage programming off, 4 MXT mode oscillation
*/
# Include <pic18.h>
# Define Rs lata1 // RS data command selection terminal rs = 1 Data rs = 0 command
# Define RW lata2 // RW read/write selection terminal RW = 1 read RW = 0 write
# Define e lata3 // enable signal e = 1
// The data displayed in the first row
Const char eye [] = {'','', 'O ','', '','','','','',''};
// Data displayed in the second row
Const char mouth [] = {'','', W ','','', '','','','','',''};
Void Init (); // declare the I/O port initialization Function
Void LCD _init (); // declare the LCD initialization Function
Void write_eye (); // declare the function of displaying the eye address
Void write_mouth (); // declare the display mouth address Function
Void write (char X); // returns the 1-byte data function.
Void LCD _enable (); // declares the LCD display setting function.
Void delay (unsigned int X); // declares the latency function.
//************************************** **********************************
Int main ()
{
Int I = 0, j = 0;
While (1)
{
Int I = 0, j = 0;
Init (); // I/O port initial
LCD _init (); // LCD Initialization
// Write the address first and then the data
Write_eye (); // display the first row of data
// Display the second line
Portd = 0xc0; // set the display address of row 2nd
LCD _enable (); // enables write command
Write_mouth ();
Delay (10000 );
// Move the following data
For (I = 0; I <7; I ++)
{
Portd = 0x1c; // All characters on the display are shifted to the right until the rightmost
LCD _enable (); // enables write command
Delay (30000 );
If (I = 6)
{
For (j = 0; j <13; j ++) // move from rightmost to leftmost
{
Portd = 0x18; // All characters on the display are moved to the left until the leftmost
LCD _enable (); // enables write command
Delay (30000 );
}
}
}
}
}
// ******************************* Initialize I/O **** *****************************
Void Init ()
{
Adcon1 = 0x07; // set port A to a normal I/O port
Trisa = 0x00; // you can specify port A as the output.
Trisd = 0x00; // set the D port to output
}
// ******************************* LCD initialization ****** ***************************
Void LCD _init ()
{
Portd = 0x1; // clear the LCD screen
LCD _enable (); // enables write command
Portd = 0x38; // 8 digits, 2 rows, 5*7 Dots
LCD _enable (); // enables write command
Portd = 0x0c; // displayed on, no cursor
LCD _enable (); // enables write command
Portd = 0x06; // text does not move
LCD _enable (); // enables write command
Portd = 0x80; // open the display address of the first line
LCD _enable (); // enables write command
}
******* **************************
Void write_eye ()
{
Int I;
For (I = 0; I <0x10; I ++) // a total of 16 characters I <16 also
{
Write (Eye [I]); // query table to obtain data and call to write a byte data function for LCD display
}
}
// *************************** Display mouth address function ******** **********************
Void write_mouth ()
{
Int I;
For (I = 0; I <0x10; I ++) // a total of 16 characters
{
Write (Mouth [I]); // query table to obtain data and call to write a byte data function to send LCD display
}
}
// ************************** LCD display setting function ********* ***********************
Void LCD _enable ()
{
Rs = 0; // command
RW = 0; // write
E = 0; // lower the enabling Signal
Delay (5000); // keep the Enable message as below for a period of time
E = 1; // Enable write command
}
// ************************** Display the 1-byte data function ******* ************************
Void write (char X)
{
Portd = X;
Rs = 1; // data
RW = 0; // write
// The following is required, and the latency is also necessary.
E = 0; // lower the enabling Signal
Delay (5000); // keep the Enable message as below for a period of time
E = 1; // pull the high enable signal to establish the rising edge required for LCD operation
}
******** ***********************
Void delay (unsigned int X)
{
Int I;
I = X;
For (I = x; I> 0; I --){;}
}