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.

plz help me with this code

Status
Not open for further replies.

armpicc2000

Newbie level 1
Joined
Oct 30, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Activity points
1,311
hi frenz

I hav pasted a code below to display varying adc values in lcd....... but i cannot display the values.........plz help to debug the code

#if defined(__PCM__)
#include <16F877A.H>
#fuses NOWDT,NOPROTECT,NOLVP
#use delay(clock=6144000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
#build (reset=0x200,interrupt=0x204)
#org 0x004,0x1ff
{}

#endif

#define rs PIN_E0
#define en PIN_E1
#define b1 0.014662756598240469208211143695015
#define adc pin_a1

//int i;

void lcd_init();
//void enable();

float f1;
char str1[20];
unsigned char *str;
//float f2=19.99;
//char bat1[6];
//char b2[6];

//void cname();
void bvolt();
void lcd_print(char *str1);
void lcd_write(unsigned char);
//void pvolt();
float adc_channel1();

unsigned int hi1,lo1;
unsigned int16 fin1;
float volt1;

#byte ADCON1 = 0x9f
#byte ADCON0 = 0x1f
#byte ADRESL = 0x9e
#byte ADRESH = 0x1e
#BYTE PIR1 = 0X0c
#byte PIE1 = 0x8C
#bit ADIF = 0x0C.6

void main()
{

//delay_ms(50);
lcd_init();
str=0x1A0;
//while(1)
{
// lcd(); // lcd config
// output_high(RS); // data mode
// cname();
//delay_ms(250);
// lcd();
// output_high(RS); // data mode
// pvolt();
//delay_ms(250);
//adc_channel1();
//output_high(RS); // data mode
bvolt();
//delay_ms(250);
}

}



/*void lcd()
{
output_low(RS); // command pin_e0 is set as low that is 0.
output_b(0x01); // clear screen
enable(); // pin_e1 is disabled and then enabled
output_b(0x02); // return to home
enable();
output_b(0x06); // increment cursor
enable();
output_b(0x0E); // cursor blinking
enable();
output_b(0x80); // lcd's 1st line
enable();
//output_b(0x3C); // 4 line lcd config
// enable();

}*/

/*void enable()
{
output_low(E);
delay_ms(100);
output_high(E);
}*/

/*void cname()
{
char cname[]="SAFE World";
for(i=0;cname!='\0';i++)
{
delay_ms(500);
output_b(cname);
enable();
}
} */

void bvolt()
{

strcpy(str,"BATT VOLT");
delay_ms(500);
lcd_print(str);

delay_ms(500);

f1=adc_channel1();

sprintf(str,"\f%f",f1);
delay_ms(500);
lcd_print(str);
delay_ms(500);
}

//char bvolt[]="BATT VOLT = ";
/* for(i=0;bvolt!='\0';i++)
{
delay_ms(500);
output_b(bvolt);
enable();
}
//f1=adc_channel1();
for(i=0;bat1!='\0';i++)
{
delay_ms(500);
sprintf(bat1,"%f",f1);
delay_ms(500);
output_b(bat1);
enable();
}
}*/

/*void pvolt()
{
char pvolt[]="PAN VOLT = ";
for(i=0;pvolt!='\0';i++)
{
delay_ms(500);
output_b(pvolt);
enable();
}

for(i=0;b2!='\0';i++)
{
sprintf(b2,"%f",f2);
delay_ms(500);
output_b(b2);
enable();
}
}*/



float adc_channel1()
{
ADCON0=0xCD;
ADCON1=0xC0;
PIE1=0x40;
PIR1=0x40;
delay_ms(50);

while(ADIF!=1);
{hi1 = ADRESH;
lo1 = ADRESL;}
ADIF=0;



//fin=(hi<<8) | lo;
fin1=make16(hi1,lo1);
//printf("\n\n10 bit value = %2x",fin);
//printf("\n\ndecimalvalue = %ld",fin);

volt1=(float)(fin1*b1);
//v1=volt/1000;
//v2=volt%1000;
printf("\n\n %f",volt1);
output_float(adc);
delay_ms(500);
return volt1;
}

void lcd_print(char *str1)
{

output_low(rs);
lcd_write(0x01);
output_high(rs);

while(*str1!=0)
{
lcd_write(*str1);
str1++;
}
}

void lcd_write(unsigned char a)
{
output_b(a);
output_high(en);
delay_ms(1);
output_low(en);
delay_ms(1);
}

void lcd_init(void)
{

output_low(rs);
//lcd_nibble_write(0x20);
lcd_write(0x01);
lcd_write(0x02);
lcd_write(0x06);
lcd_write(0x0e);
lcd_write(0x3c);
lcd_write(0x80);
output_high(rs);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top