REPLY FROM THREAD CREATOR
Hello again. I forgot to mention that I have more than enough pins and prefer to keep things simple by using 8 bit mode.
errakeshphillia I am indeed stuck on this small problem and I'm running out of time. Need assistance ASAP! I have pasted my lcd.h file here after my code. I cannot understand how the compiler knows which pins are the data ports and RS, WR and EN pins. I took a wild guess in simply using the #define (pin/port) but somehow I don't think its that easy. Or is it. Have a look.
======================================================================================================
This is what I think the code should look like.
======================================================================================================
#include <AT89X52.h>
#include <lcd.h> // I have a lcd.h file that I will include after this main code.
#define LCD_data P2
#define LCD_RS P3_0
#define LCD_EN P3_1
void main (void)
{
LCD_Init();
LCD_Data_Wr(posX, posY, data);
}
======================================================================================================
I think I'me leaving out fundamental points.
I am running OSC frequency at 11.0592Hz.
======================================================================================================
This is my lcd.h file copy, pasted.
======================================================================================================
/*+++++++++++++++++++++++++++++++LCD Routines+++++++++++++++++++++++
/*************************************************
* Programmer : AJJ Mouton *
* Keil uVision Compiler *
* Intialiation of LCD *
*************************************************/
#include <absacc.h>
#include <AT89X52.h>
#define DataAddr 0x6001
#define CommAddr 0x6000
#define Time5ms 94
#define Time20ms 376
#define Time1s 18807
const unsigned char clear[17]=" ";
/********************************
Delay Routine
********************************/
void Delay(unsigned long TimeCnt){
unsigned long Cntr;
for (Cntr = 0; Cntr < TimeCnt; Cntr++){;}
}
/***************************************
LCD write Command from LCD.C
**************************************/
void LCD_Command_Wr(unsigned char Command){
XBYTE[CommAddr] = Command;
Delay(Time5ms); // Delay 5ms
}
/******************************************************
Initialise LCD Display on Data Bus from LCD.C
RW must be grounded RS connected to A0
******************************************************/
void Init_LCD(void){
unsigned char Teller;
Delay(Time20ms); // 20 msec
for(Teller = 0; Teller < 3; Teller++)
{
LCD_Command_Wr(0x30); // Function set
}
LCD_Command_Wr(0x3C);
LCD_Command_Wr(0x08); // Display off
LCD_Command_Wr(0x01); // Display clear
LCD_Command_Wr(0x06); // Entry mode set
LCD_Command_Wr(0x0C); //Display on
Delay(Time20ms); // Delay 20ms
}
/****************************************************
Write a Single ASCII Character to a 16x2 LCD Display
Y = line 0 or 1
X = Position 0 to 15 on the line
Ch = ASCII character to be written on LCD
****************************************************/
void LCD_Data_Wr(unsigned char X, unsigned char Y, unsigned char Ch){
unsigned char Offset;
switch (Y){
case 0:
Offset = 0x00;
break;
case 1:
Offset = 0x40;
}
LCD_Command_Wr((Offset + X) | 0x80); // Position the cursor
XBYTE[DataAddr] = Ch; // Write ASCII data to the display
Delay(Time5ms); // Delay 5 ms
}
/***************************************************
Write an 8 or 16 bit Variable to a 16x2 LCD Display
Y = line 0 or 1
X = Position 0 to 15 on the line
VarSize: Byte = 1, Word = 2
***************************************************/
void LCD_Variable_Wr(char Digits, char X, char Y, unsigned int Var){
unsigned char Offset=0, Cntr=0, SizeOffset=0, Temp=0;
unsigned int Val=0, VarIn;
char DispArr[5];
VarIn = Var;
switch (Y){
case 0:
Offset = 0x00;
break;
case 1:
Offset = 0x40;
break;
default:
Offset = 0x40;
break;
}
LCD_Command_Wr((Offset + X) | 0x80); // Position the cursor
for (Cntr = 5; Cntr > 0; Cntr--){
Val = Var%10;
Var = Var/10;
Temp = (char)Val;
DispArr[Cntr-1] = (Temp) + 0x30; // Determine BCD value and convert to ASCII
}
if(Digits == 1){SizeOffset = 4;} //1 character
if(Digits == 2){SizeOffset = 3;} //2 characters
if(Digits == 3){SizeOffset = 2;} //3 characters
if(Digits == 4){SizeOffset = 1;} //4 characters
if(Digits == 5){SizeOffset = 0;} //5 characters
for (Cntr = SizeOffset; Cntr < 5; Cntr++){
XBYTE[DataAddr] = DispArr[Cntr]; // Write ASCII data to the display
Delay(Time5ms); // Delay 5 ms
}
}
//***********************************************
void ClearScreen(void){
unsigned char i;
for(i=0;i<16;i++) //Clear screen
LCD_Data_Wr(i,0,clear);
for(i=0;i<16;i++) //Clear screen
LCD_Data_Wr(i,1,clear);
}
//+++++++++++++++++++++LCD END++++++++++++++++++
======================================================================================================