electronics forum

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

C coding help in MPLAB C18


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> C coding help in MPLAB C18
Author Message
engr.waqas



Joined: 21 Jul 2009
Posts: 22
Location: karachi


Post18 Aug 2009 14:34   

mplab c18 lcd


I am putting analog input from 0 to 5 v in PIC 18.
Now the A/D result is saved in a register "result" type int.
Now i want to convert the values stored in "result" to ASCII and then to display on LCD.
I have Vref of A/D as 5 volt and using in 10 bit mode.
I want LCD to show fractional values too like 4.5 etc
can anyone give me its coding??
Back to top
nikhil_damle



Joined: 15 Dec 2005
Posts: 103
Helped: 2


Post18 Aug 2009 15:48   

double to ascii c18


please go through the data sheet of the of the target processor and see the equation for the analog to digital conversation. the result in the ADC resister can be converted to the voltage and displayed on the LCD depending on the LCd the diaplay code will change
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1187
Helped: 113
Location: Oberon


Post18 Aug 2009 18:01   

mplab c18 code


Code:

#include <stdio.h>

char buffer[8];

void convert(void)
  {
  int result;
  double voltage;

  voltage = (double)(result * 5.0 / 1024.0);
  sprintf(buffer, "%0.1f", voltage);
  }
Back to top
engr.waqas



Joined: 21 Jul 2009
Posts: 22
Location: karachi


Post19 Aug 2009 6:05   

double to int mplab


Dear Btbass
thanks a lot for your response but now i have problem that LCD data lines are connected to port D(D0 to D7).Now when i use the following code to send data stored in buffer[] i get syntax error.
PORTD=buffer[];
so how can i send the value stored in buffer[] to PORT D.
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1187
Helped: 113
Location: Oberon


Post19 Aug 2009 16:52   

c18 lcd için printf


buffer is an array of char.
If you just want one decimal place, try

PORTD = buffer[0];
PORTD = buffer[1];
PORTD = buffer[2];
PORTD = buffer[3]; /* Will contain NULL */

or you could do it in a loop.
Back to top
Google
AdSense
Google Adsense




Post19 Aug 2009 16:52   

Ads




Back to top
Prabakaran



Joined: 22 Jan 2007
Posts: 160
Helped: 5
Location: Chennai(India)


Post19 Aug 2009 18:10   

mplab c18 lcd printf


Dear engr.waqas

Use the following code to convert the ADC Count to get the Exact voltage Levels

Value = ReadADC(Channel Number)

value = (value * 5.00)/1024;

u get the value in decimal absoultue value. If u want in floating variables

Declare value as float

use this step
value = Readadc(channel number)
value = (value * 5)/1024;
printf("%f",value);

U get the value in floating point.
Check out this. If u need more i help u

Regards
Prabakaran
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 -> C coding help in MPLAB C18
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Req. MPLAB C18 help for a beginner (6)
mplab c18 error (1)
MPLAB C18 error (1)
mplab-c18 question .. (5)
RTC(MPLAB IDE/C18 compiler) (2)
PIC16F programming with MPLAB-C18 compiler (1)
Hitech picc18 VS. MPLAB C18 what is the better? (7)
Does MPLAB C18 support PIC 16 and 17 family? (3)
ADC on 18F4525 coded in C langage under MPLAB (C18) (1)
KS0108 GLCD Driver, LIB for mplab c18 (1)


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