Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

analog signal to digital problem(program)

Status
Not open for further replies.

desmond

Member level 1
Joined
Nov 24, 2006
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,538
Hi all

I am using C to do my project...my equation of vout is 5/(1+(z/4.7)).......why i cant read the value on LCD ???
Could anyone can help me ???

void display_LCD_number(unsigned char number)
{
unsigned char x,y,i=2;
int z;
z=(int) number;
z=z<<1;


y=5/(1+(z/4.7));
gotoxy(2,0);
write_LCD_data(int2char[y]);


gotoxy(2,1);
display_LCD_string(".");


y=5/(1+(z/4.7));
gotoxy(2,2);
write_LCD_data(int2char[y]);



y=5/(1+(z/4.7));
gotoxy(2,3);
write_LCD_data(int2char[y]);


gotoxy(2,4);
display_LCD_string("V");

}
 

hi, you should initialise the ADC module and read the value from the ADC result register (this is not present in your program given). also not specified about the microcontroller (if you are using it) and the compiler
 

Here is my full program.......


#include <REGX51.H>
#define TIMER0_COUNT 0xDC11
/* LCD command */
#define DISPLAY_ON 56
#define CURSOR_OFF 12
#define CURSOR_RIGHT 6
#define CLEAR 1
#define CURSOR_HOME 2
#define GOTO_LINE_2 192
#define GOTO_LINE_1 128
/* LCD control lines */
#define ENABLE 1
#define DISABLE 0
#define READ 1
#define WRITE 0
#define COMMAND 0
#define DATA 1
#define rs P3_5
#define rw P3_4
#define enable P3_3
#define adc_in P0
#define adc_rd P2_0
#define adc_wr P2_1
static unsigned timer0_tick;
const char int2char[]="0123456789";
void delay_2ms(void) {
unsigned char i,j;
for (i=0;i<3;i++)
for(j=0;j<255;j++)
;
}
void write_LCD_command(unsigned command)
{
rw=WRITE;
rs=COMMAND;
enable=ENABLE;
P1=command;
enable=DISABLE;
rs=1;
rw=1;
delay_2ms();
}
void write_LCD_data(unsigned LCDdata)
{
rw=WRITE;
rs=DATA;
enable=ENABLE;
P1=LCDdata;
enable=DISABLE;
rs=0;
rw=1;
delay_2ms();
}
void set_LCD(void)
{
write_LCD_command(DISPLAY_ON);
write_LCD_command(CURSOR_OFF);
write_LCD_command(CURSOR_RIGHT);
}
void clear_LCD()
{
write_LCD_command(CLEAR);
write_LCD_command(CURSOR_HOME);
}
display_LCD_string(char *p)
{
while(*p)
{
write_LCD_data(*p);
p++;
}
}
void gotoxy(unsigned x,unsigned y)
{
if(x==1)
write_LCD_command(GOTO_LINE_1+y);
else
write_LCD_command(GOTO_LINE_2+y);
}
void display_LCD_number(unsigned char number)
{
unsigned char x,y,i=2;
int z;
z=(int) number;
z=z<<1;

x=z;
y=x;
gotoxy(2,0);
write_LCD_data(int2char[y]);


gotoxy(2,1);
display_LCD_string(".");


x=z;
y=x;
gotoxy(2,2);
write_LCD_data(int2char[y]);



x=z;
y=x;
gotoxy(2,3);
write_LCD_data(int2char[y]);


gotoxy(2,4);
display_LCD_string("V");

}
static void timer0_isr(void) interrupt 1 using 1
{
TR0=0;
TL0=(TIMER0_COUNT & 0x00FF);
TH0=(TIMER0_COUNT >> 8);
TR0=1;
timer0_tick++;
if (timer0_tick==200) {
adc_wr=0;
timer0_tick=0;
adc_wr=1;
}
}
static void int0_isr(void) interrupt 0 using 0
{
unsigned char voltage;
adc_in=0xFF;
adc_rd=0;
voltage=adc_in;
voltage=voltage <<1;
adc_rd=1;
gotoxy(2,0);
display_LCD_number(voltage);
}
static void timer0_initialize(void)
{
EA=0;
timer0_tick=0;
TR0=0;
TMOD &= 0XF0;
TMOD |=0x01;
TL0=(TIMER0_COUNT & 0x00FF);
TH0=(TIMER0_COUNT >> 8);
PT0=0;
ET0=1;
TR0=1;
EA=1;
}
void main (void) {
set_LCD();
clear_LCD();
display_LCD_string("Output Voltage =");
timer0_initialize();
IT0=1;
EX0=1;
while(1);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top