Re. A/D converter display on LCD

Status
Not open for further replies.

Thread Starter

Ebuka

Joined Dec 8, 2010
10
Am having problems getting my A/D conv. value display on my LCD the cursor goes through the first line but nothing visible shown. Am using a 16X2 LCD.

I have included the schematics Pls do have time look at my codes

#include <REGX52.H>
#include <Stdio.h>

Thanks..


#define LCD_data P2 // Data will be sent to/recieved from the LCD throught this port P2
#define LCD_rs P1_0 // 0 = Instruction input 1 = Data input
#define LCD_rw P1_1 //0 = Write to LCD module 1 = Read from LCD module
#define LCD_en P1_2 // Enable Signal

#define ADC_port P2 // A/D converter port
#define rd P1_3
#define wr P1_4
#define cs P1_5
#define intr P1_6
#define OUTPUT P3 // A/D value moved here.

// Function Declerations....

void LCD_Power_on(void);
void LCD_Busy(void);
void LCD_Get_signal(unsigned char signal);
void LCD_Send_signal(unsigned char signal);
void LCD_Send_String(unsigned char *signal);
void LCD_Initialize(void);

void convert();
void read();
unsigned int ADC_value;

// The main loop....

void main (void)
{
int i;
unsigned int a,b,c,d,e,f,g,h;
unsigned int convertr[9];


LCD_Busy();
convert();
LCD_Busy();
read();
LCD_Power_on(); // 15ms delay
OUTPUT = ADC_value;





a = 1.5; b = 4.9; c = 9.2; d = 6.5; e = 4; f = 6.4; g = 8; h = 12;

convertr[0] = ((OUTPUT + 1) * a) / 16 ; //round to 0
convertr[1] = ((OUTPUT + 1) * b) / 16 ; //round to 1
convertr[2] = ((OUTPUT + 1) * c) / 16 ; //round to 1
convertr[3] = ((OUTPUT + 1) * d) / 16 ; //round to 1
convertr[4] = ((OUTPUT + 1) * e) / 16 ; //round to 0
convertr[5] = ((OUTPUT + 1) * f) / 16 ; //round to 1
convertr[6] = ((OUTPUT + 1) * g) / 16 ; //round to 1
convertr[7] = ((OUTPUT + 1) * h) / 16 ; //round to 1

LCD_Initialize();
for(i=0;i<9;i++)
{
LCD_Busy();
LCD_Get_signal(convertr);


LCD_Busy();

LCD_Send_signal(convertr);// Set CGRAM adress,data is Avaible from uC
}
LCD_data = convertr;
scanf("%s",LCD_data);


}
/// End of main loop

void LCD_Power_on(void)
{
int a;
for(a=0;a<25000;a++);
}

void LCD_Busy(void)
{
unsigned char i,j;
for(i=0;i<100;i++)
for(j=0;j<255;j++);
}
/* to get your signal you have to enable the LCD pins to read and more*/
void LCD_Get_signal(unsigned char signal)
{
LCD_data = signal; //Function set: 2 Line, 8-bit, 5x8 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_Busy(); //Wait for LCD to process the command
}

void LCD_Send_String(unsigned char *signal)
{
while(*signal) //till string ends
LCD_Send_signal(*signal++); //send characters one by one
}

void LCD_Send_signal(unsigned char signal)
{
LCD_data = signal; //Function set: 2 Line, 8-bit, 5x8 dots
LCD_rs = 1; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_Busy(); //Wait for LCD to process the command
}
void LCD_Initialize(void)
{
LCD_data = 0x38; //Function set: 2 Line, 8-bit, 5x8 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_Busy(); //Wait for LCD to process the command
LCD_data = 0x0F; //Display on, Curson blinking command
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_Busy(); //Wait for LCD to process the command
LCD_data = 0x01; //Clear LCD
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_Busy(); //Wait for LCD to process the command
LCD_data = 0x06; //Entry mode, auto increment with no shift
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in data register
LCD_en = 1; //Enable H->L
LCD_en = 0; //Enable H->L
LCD_Busy();
}

void convert()
{
cs = 0;
wr = 0;
cs = 1;
wr = 1;
while( intr == 1);
}
void read()
{
cs = 0;
rd = 0;
ADC_value = ADC_port;
cs = 1;
rd = 1;

}
 

Attachments

Status
Not open for further replies.
Top