Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

displaying decimal point on LCD using 18f5420

Status
Not open for further replies.

stereovestro

New Member
hey there

i really need help with this.
im programming pic 18f4520 as volt ampmeter. as of now, i could display the voltage up to 12v without decimal point on the LCD. e.g 8.45v is = to 845v on the LCD screen.

i really need to put the decimal point so that the reading would be more accurate.
here' my code.
im using mplab v7.6 c18

#include <p18f4520.h>
#include <delays.h>
#include <stdlib.h>
float result;
void Init_LCD(void);

void W_ctr_4bit(char);
void W_data_4bit(char);

#define LCD_DATA PORTD
#define LCD_RW PORTAbits.RA2
#define LCD_RS PORTAbits.RA3
#define LCD_E PORTAbits.RA1

unsigned char LCD_TEMP, i;
char MESS[16]= "VOLTAGE display";
char MESS2[12]= " . v 0.6A";
char MESS3[2]= ".";



unsigned char Buf[6];

void InterruptHandlerLow(void);
unsigned int a;
float temp,result;
#pragma code InterruptVectorLow= 0x018
void InterruptVectorLow(void) {
_asm
goto InterruptHandlerLow

_endasm
}
#pragma code
#pragma interruptlow InterruptHandlerLow
void InterruptHandlerLow()
{
if(PIR1bits.TMR1IF){
Delay10TCYx(1);
ADCON0bits.GO=1;
while(ADCON0bits.DONE);
temp = (ADRESH * 256.0) + ADRESL; //Make as 16-bit WORD
result = 500.0 * temp / 1024.0; // or result = 0.48828125 * temp;
a = (unsigned int)(result + 0.5);

//result>>=4;

W_ctr_4bit(0xc0);
for(i=0; i<11; i++)
{W_data_4bit(MESS2);
}
W_ctr_4bit(0x42);
for(i=0; i<1; i++)
{W_data_4bit(MESS3);
}


W_ctr_4bit(0xc0);
itoa(result,MESS);
i=0;
while(MESS)
{
W_data_4bit(MESS);
i++;}
TMR1H=0x0b;
TMR1L=0xdc;
PIR1bits.TMR1IF=0;
}

}
void main()
{
TRISD=0;
TRISA=0b11110001;
TRISB=0b11110000;
ADCON0=0b00000001;
ADCON1=0b00001110;
ADCON2=0b10000100;

INTCONbits.GIE=0;
Init_LCD();
for(i=0;i<15;i++)
{
W_data_4bit(MESS);
}
PORTB=0b00000110;
RCONbits.IPEN=1;
IPR1bits.TMR1IP=0;
TMR1H=0x0b;
TMR1L=0xdc;
T1CON=0b11110001;
PIR1bits.TMR1IF=0;
PIE1bits.TMR1IE=1;
INTCONbits.GIEL=1;
INTCONbits.GIE=1;
while(1);
}
void Init_LCD()
{
Delay1KTCYx(15);
W_ctr_4bit(0x03);
Delay1KTCYx(5);
W_ctr_4bit(0x02);
W_ctr_4bit(0b00101000);
W_ctr_4bit(0b00001100);
W_ctr_4bit(0b00000110);
W_ctr_4bit(0b00000001);
}
void W_ctr_4bit(char x)
{
LCD_RW=0;
LCD_RS=0;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
}


void W_data_4bit(char x)
{
LCD_RW=0;
LCD_RS=1;
LCD_TEMP=x;
LCD_TEMP>>=4;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
LCD_TEMP=x;
LCD_TEMP &=0x0f;
LCD_E=1;
LCD_DATA=LCD_TEMP;
Delay1KTCYx(1);
LCD_E=0;
Delay1KTCYx(1);
}

any help would be appreciated
 
Status
Not open for further replies.

Latest threads

Back
Top