void clear(void)
{
delay(5);
Select_InstructionRegister;                  // Declares information to follow as instruction
Data_Lcd(0x10);                              // Code to go to next line of LCD
Set_Enable;                                  //  --  Enable cycle  --
delay(5);                                    // |                    |
Clear_Enable;                                // |                    |  
delay(5);                                    //  --                --
}
void Lcd_Send(unsigned char a)
{
Select_DataRegister;                        // Declares information that follows as data and not instruction
Write_Lcd;                                  // Declared information is to be written
Data_Lcd(a);                                // Send the character passed to the function to LCD to write
Set_Enable;                                 // Sets enable,
delay(10);                                   // and then
Clear_Enable;                               // Clears it,
delay(10);                                   // to be ready for next character.
}
示例#3
0
void Clear_LCD(void)
{
	cli();						// Disable interrupts
	Select_InstructionRegister;	// Sets R/S pin on LCD low so the LCD knows we are giving it instructions, not characters
	Write_Lcd;					// R/W pin of LCD is set low so LCD knows we are writing to it, not reading from
	Data_Lcd(0x01);				// this is the command for completely clearing the display and returning the cursor to the home location
	Set_Enable;					// Sets the Enable pin HI on the LCD to clock in the data presented to the Data pins
	delay(1);					// delay 1 ms to let things settle
	Clear_Enable;				// Clears Enable by seting it back low.
	delay(1);					// delay 1 ms to let things settle
	sei();						// re-enable interrupts
}
示例#4
0
/*----------------------------------------------------------------
 -----------------SEND A CHARACTER TO LCD-------------------------
 -----------------------------------------------------------------*/
void Lcd_Send(unsigned char a)
// by now you have see most of my comments regarding these lines of code because they were used above
// nothing really changes here except we have a function which has a character input, which means you
// feed in characters from your strings using a for loops and it will clock them into the LCD

{
	cli();					//disable interrupts
	Select_DataRegister;	// Sets R/S pin on LCD HI so the LCD knows we are giving it characters, not instructions
	Write_Lcd;				// R/W pin of LCD is set low so LCD knows we are writing to it, not reading from
	Data_Lcd(a);			// put ASCII hex code for the given letter/character out on PORTB for the LCD data pins. The ASCII hex codes are handled in the compiler, nice!
	Set_Enable;				// Sets the Enable pin HI on the LCD to clock in the data presented to the Data pins
	delay(1);				// delay 1 ms to let things settle
	Clear_Enable;			// Clears Enable by seting it back low.
	delay(1);				// delay 1 ms to let things settle
	sei();					// re-enable interrupts
}
示例#5
0
void Set_Cursor(unsigned char position)
{
	/*
		Possible locations:
		-------------------
		   Top Display Row |80|81|82|83|84|85|86|87|88|89|8A|8B|8C|8D|8E|8F|
		Bottom Display Row |C0|C1|C2|C3|C4|C5|C6|C7|C8|C9|CA|CB|CC|CD|CE|CF|
	*/
	cli();						// Disable interrupts
	Select_InstructionRegister; // Sets R/S pin on LCD low so the LCD knows we are giving it instructions, not characters
	Write_Lcd;					// R/W pin of LCD is set low so LCD knows we are writing to it, not reading from
	Data_Lcd(position);			// have the AVR push a cursor location for the LCD out of PORTB to the LCD's data pins - this will move the cursor to the 88 position to overwrite previous number
	Set_Enable;					// Sets the Enable pin HI on the LCD to clock in the data presented to the Data pins
	delay(1);					// delay 1 ms to let things settle
	Clear_Enable;				// Clears Enable by seting it back low.
	delay(1);					// delay 1 ms to let things settle
	sei();						// re-enable interrupts
}
void Init_Lcd(void)
{
char init[10];
int i;
init[0] = 0x01;                          // Initialises the display
init[1] = 0x38;                          // 8 - Bit Operation, 2 Line Display,5*8 Dot Character Font
init[2] = 0x0e;                          // Turns on display and cursor
init[3] = 0x06;   // Entry Mode Set 
init[4] = 0x80;                          // Sets DDRAM address to beginning of screen
Select_InstructionRegister;

Write_Lcd;
delay(15);

for(i=0;i<5;i++)
     {Data_Lcd(init[i]);
     Set_Enable;
     delay(10);
     Clear_Enable;}
}
示例#7
0
/*------------FUNCTION TO INITIATE LCD -----------------------------
 Initializes the LCD with the instruction commands we want to use for writing
 to the display. You can do alot here, but you want to avoid having to clear the
 display too frequenlty because it can cause flicker, its better over over write.
 There's alot of cool stuff you can mess with here.
 Check out these 2 sites for more instruction code
 http://www.dinceraydin.com/lcd/commands.htm
 http://ouwehand.net/~peter/lcd/lcd0.shtml
 -----------------------------------------------------------------*/
void Init_Lcd(void) {
	char init[4];
	int i;

	init[0] = 0x0C; // turn off cursor  - 0x0E blinking underline  - 0x0F blinking block
	init[1] = 0x38; //  Use LCD in 8bit mode with both lines of the display
	init[2] = 0x06; //  entry mode set - increment cursor position to write left to right with no character shifting
	init[3] = 0x80; //  home ddram position 0x80 - 0x8F
	//   Top Display Row |80|81|82|83|84|85|86|87|88|89|8A|8B|8C|8D|8E|8F|
	//Bottom Display Row |C0|C1|C2|C3|C4|C5|C6|C7|C8|C9|CA|CB|CC|CD|CE|CF|

	cli(); // disable interrupts
	Select_InstructionRegister;
	Write_Lcd;
	for (i = 0; i < 4; i++) // same story, set LCD in instruction mode and clock in command data
	{
		Data_Lcd(init[i]);
		Set_Enable;
		delay(1);
		Clear_Enable;
		delay(1);
	} // end for
	sei(); // re-enable interrupts
} //end function