electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

plz help me with this code


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> plz help me with this code
Author Message
armpicc2000



Joined: 30 Oct 2009
Posts: 1
Location: India


Post30 Oct 2009 11:59   

plz help me with this code


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[i]!='\0';i++)
{
delay_ms(500);
output_b(cname[i]);
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[i]!='\0';i++)
{
delay_ms(500);
output_b(bvolt[i]);
enable();
}
//f1=adc_channel1();
for(i=0;bat1[i]!='\0';i++)
{
delay_ms(500);
sprintf(bat1,"%f",f1);
delay_ms(500);
output_b(bat1[i]);
enable();
}
}*/

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

for(i=0;b2[i]!='\0';i++)
{
sprintf(b2,"%f",f2);
delay_ms(500);
output_b(b2[i]);
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<<Cool | 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);
}
Back to top
Google
AdSense
Google Adsense




Post30 Oct 2009 11:59   

Ads




Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> plz help me with this code
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
can someone plz help with this verilog code of mine? (5)
help me in this code plz (1)
what wrong in this VHDL code plz help me (3)
get headache with my asm code - plz help me! (8)
plz need help with this problem (4)
plz help me with this HFSS simulaton (2)
hi jian plz help me with this file using ie3d (20)
Help with this code (5)
need help with this code (1)
Need help with this code Urgently!!!!!!! (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS