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.

PIC18F45k20 C18 display a result of CAN in LCD

Status
Not open for further replies.

servntes

Newbie level 6
Joined
Apr 12, 2010
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,395
Hi,
I use a PIC18F452k0 in C18 and i want to display a result of CAN in LCD en Decimal
I need your help, !!!
 

PIC18F4520 C18 display a result of CAN in LCD

which result?
could you post your actual code and circuit?
have you a working LCD hardware/firmware?

or just binary-to-decimal convert problem?
 

Re: PIC18F4520 C18 display a result of CAN in LCD

Kurenai_ryu said:
which result?
could you post your actual code and circuit?
have you a working LCD hardware/firmware?

or just binary-to-decimal convert problem?

I want to display o voltage in the LCD !!! this voltage is the result of ADC, using AN0 analogu pin,

this is my code :

Code:
#include <p18f45k20.h>
#include <stdio.h>

#define LCD_DATA   	 PORTD
#define LCD_RS       PORTCbits.RC0
#define LCD_E        PORTCbits.RC1

void main (void);
void PImain (void);
void Initialize(void);
void a2d_conversion(void);
void lcd_init(void);
void lcd_command(unsigned char);
void lcd_affiche(unsigned float);
void lcd_goto(unsigned char);
void lcd_delay(void);



#pragma code

/*************************
 * Definition des Variables
 *************************/
	float conversion;
	double U0; 	
	double U1;
	double prop;
	double integ;
	char error0; 
	char error1;
	int Yc;
	char Co;
	char M; 
	unsigned char kp;
	unsigned char ki;
	unsigned char delay;

/*********************
 * Fonction principal
 ********************/

void main()
{
	
 kp=8;
 ki=2;
 Co=98;

 TRISD=0;
 ADCON1=0x0E;
 ADCON0=0x01;
 ADCON2=0x00;

  lcd_init(); 
  lcd_affiche('Y'); 
  lcd_affiche('c'); 
  lcd_affiche('=');
   	
while(1)
{
 delay = 0x01;

 ADCON0bits.ADON = 1; 

	while (delay != 0)
		{
			delay -= 1;
		}

 ADCON0bits.GO = 1;

	while (ADCON0bits.GO)
		{
			//pas de opcode;		
		}

 Yc = ADRESH ;	
 conversion=(5*Yc)/1024;
 lcd_goto(3);
 
[b] // display result of ADC in LCD[/b]  
}
}
/******************************************
 * Initialisation de l’afficheur LCD 1x16
 ******************************************/

void lcd_init(void)
{
 TRISC=0;
 TRISD=0;
 lcd_command(0x30);	 	//accès 8 bits, 1 ligne de 16 C,
 lcd_command(0x01); 	//reset l'afficheur
 lcd_command(0x0C); 	//affichage ON - curseur ON 
 lcd_command(0x06); 	//deplacement du curseur vers la droite
}

/******************************************
 * configuration de l’afficheur LCD 1x16
 ******************************************/

void lcd_command(unsigned char comand) 
{
  LCD_RS = 0;
  LCD_DATA = comand;
  LCD_E = 1;
  lcd_delay();
  LCD_E = 0;
}

/*********************
 * afficher sur LCD
 *********************/

void lcd_affiche(unsigned float affich) 
{
 LCD_RS = 1;
 LCD_DATA=affich;
 LCD_E = 1;
 lcd_delay();
 LCD_E = 0;
}

/*******************************
 * choisir une Position sur LCD
 *******************************/

void lcd_goto(unsigned char pos)
{
	TRISC = 0;
	TRISD = 0;	
	LCD_RS = 0;
	lcd_command(0x80+pos);
}

/*************************
 * Temporisation pour LCD
 *************************/

void lcd_delay(void)
{
int i=0;
for (i=0;i<250;i++);
}


my circuit :


**broken link removed**

Added after 12 minutes:

I want to display a result of ADC

in my circuit :
When I vary the potentiometer [0 volts, 5 volts], which connected the pin AN0, I want to display the result on LCD en décimal .
 

ok, so you have a working lcd, and a adc value (properly scaled at 'float conversion') you need a 'float' to 'ascii' convertion...

mmm... it's kinda difficult you know? maybe using the 'printf' or 'sprintf' from C18... mmm... should check that... checking... too bad! it doesn't implement "%f"... maybe converting from float to int...

if you need ( or are planning) to implement this convertion from scratch... say, how many digits do you need? (0.0 to 4.9 or 0.000 to 4.999) that way you can implement something like this...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n*=10.0;
  i=(int)(n);
  lcd_affiche(0x30|i);
 }
}

and place it where you marked!

Code:
 conversion=(5.0*Yc)/1024.0;
 lcd_goto(3);
 
 // display result of ADC in LCD
 print_float(conversion);

Added after 6 minutes:

sorry! I think you should use ADRES (and not ADRESH) if you want the 10 bit value...
 

Kurenai_ryu said:
ok, so you have a working lcd, and a adc value (properly scaled at 'float conversion') you need a 'float' to 'ascii' convertion...

mmm... it's kinda difficult you know? maybe using the 'printf' or 'sprintf' from C18... mmm... should check that... checking... too bad! it doesn't implement "%f"... maybe converting from float to int...

if you need ( or are planning) to implement this convertion from scratch... say, how many digits do you need? (0.0 to 4.9 or 0.000 to 4.999) that way you can implement something like this...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n*=10.0;
  i=(int)(n);
  lcd_affiche(0x30|i);
 }
}

and place it where you marked!

Code:
 conversion=(5.0*Yc)/1024.0;
 lcd_goto(3);
 
 // display result of ADC in LCD
 print_float(conversion);

Added after 6 minutes:

sorry! I think you should use ADRES (and not ADRESH) if you want the 10 bit value...


Thanks a lot !!

I change the code but we have anthor error

when I vary the potentiomtre betwen [ 0 volt , 5 volt ], the value dosn't display correctly in LCD

and the value displaying in the LCD when I vary the potentiometre, betwen 0.000 and 0.555

exp :

**broken link removed**

**broken link removed**

**broken link removed**

 

mmmm its true! i'm sorry I made the code right here, so i couldn't check it closely....

my correction would be...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n-=i; //hope it's enought...
  n*=10.0;
  i=(int)(n);
  lcd_affiche(0x30|i);
 }
}

or the classic...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n*=10.0;
  i=((int)(n))%10;//just the digit!
  lcd_affiche(0x30|i);
 }
}

hope some of this quick changes will help...
 

Kurenai_ryu said:
mmmm its true! i'm sorry I made the code right here, so i couldn't check it closely....

my correction would be...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n-=i; //hope it's enought...
  n*=10.0;
  i=(int)(n);
  lcd_affiche(0x30|i);
 }
}

or the classic...

Code:
void print_float(float n){
 int i,j;
 i=(int)n; //first integer digit  //assuming its from 0.0 to 5.0
 lcd_affiche(0x30|i);
 lcd_affiche('.');
 for(j=0;j<3;j++){
  n*=10.0;
  i=((int)(n))%10;//just the digit!
  lcd_affiche(0x30|i);
 }
}

hope some of this quick changes will help...

Thanks a lot !!

I have testing the two code :

but we have the same problem :|

First code :

the same problem I had such as at the beginning

seconde code:

the same problem I had such as at the beginning
 

ok ok, time to get serious, i'll download your code, and test it troughtfully....

wait a little time...

Added after 28 minutes:

ok, it's done (at least for a 0 - 5v value!)
I changed the Yc variable definition (from signed char to unsigned int)
modified ADC configuration
mostly to get an 0-1023 16-bit ansnwer on Yc
so it's scaled to 0.0 to 5.0 on conversion.

added a temporal variable to check conversion value on isis, forgot to get rid of it... do it!

have fun!
 

Kurenai_ryu said:
ok ok, time to get serious, i'll download your code, and test it troughtfully....

wait a little time...

Added after 28 minutes:

ok, it's done (at least for a 0 - 5v value!)
I changed the Yc variable definition (from signed char to unsigned int)
modified ADC configuration
mostly to get an 0-1023 16-bit ansnwer on Yc
so it's scaled to 0.0 to 5.0 on conversion.

added a temporal variable to check conversion value on isis, forgot to get rid of it... do it!

have fun!

thank you very much
cordially
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top