Ik ben momenteel bezig met het aansturen van een 2x16 LCD met behulp van een ATMEGA8515 microcontroller.
Heeft er misschien iemand de initialistie van een LCD in C-code?
greetz!
#pragma bit LCD_E @ PORTD.7 //LCD Enable control
#pragma bit LCD_RS @ PORTD.6 //LCD Register Select
//RS=0 --> Commands
//RS=1 --> Characters
/////////////////////////////////////////////////////////////////////
//Delay Short (1 mSec)
/////////////////////////////////////////////////////////////////////
void Delay_Short(char millisec)
{
OPTION=2; //Prescaler Timer0 = 1:8
//Timer0 Internal Clock Source
do {
TMR0=0;
while(TMR0<125);//125*8=1000
}
while (--millisec>0);
}
/////////////////////////////////////////////////////////////////////
//Write Character to LCD
/////////////////////////////////////////////////////////////////////
void LCD_Ch(char Character)
{
LCD_RS=1; //Write Characters
Delay_Short(1); //Delay
PORTB=Character; //Write Character to LCD
LCD_E=1; //Clock
Delay_Short(1); //Delay
LCD_E=0; //Clock
Delay_Short(1); //Delay
}
/////////////////////////////////////////////////////////////////////
//Write Command to LCD
/////////////////////////////////////////////////////////////////////
void LCD_Comm(char Command)
{
LCD_RS=0; //Write Commando
Delay_Short(1); //Delay
PORTB=Command; //Write Character to LCD
LCD_E=1; //Clock
Delay_Short(1); //Delay
LCD_E=0; //Clock
Delay_Short(1); //Delay
}
/////////////////////////////////////////////////////////////////////
//LCD Initialisation
/////////////////////////////////////////////////////////////////////
void LCD_Init()
{
Delay_Short(5); //Delay
LCD_Comm(56); //Sets interface data length (8bit), number of Display Line (2) and Character Font(5x7dots), x, x.
Delay_Short(3); //Delay
LCD_Comm(1); //Clear Display and Return Cursor to Home position
Delay_Short(3); //Delay
LCD_Comm(12); //Display On, Cursor off, Blink off
Delay_Short(3); //Delay
}Alsjeblieft.
Marcel
AVR C tutorial http://expand.xs4all.nl/avr
Met Google had je diverse complete libraries kunnen vinden. Sommige zijn qua code nogal compiler afhankelijk. Het is dus handig om even te vermelden welke compiler je gebruikt. Ik zelf gebruik de library van Peter Fleury, die is geschreven voor AVRGCC.
De code van JuuL is zo te zien voor een andere compiler.