Usb pic18f4550 :: Adc voltmeter

ADC Example : 0-5V Volt Meter

Compiler : Microchip C18 C Compiler

Kit : Bootloader USB PIC18F4550

Project : 0-5V Voltmeter


LCD Details

Hardware connection : connect POT1 and RA0

LCD Hardware connection

Voltmeter output

lcd volt display

Source Code

/*  SOURCE : WWW.ROMUX.COM
    AUTHOR : romux team     */ 
    
    
#include < p18F4550.h>
#include < stdlib.h>
#include < delays.h>
#include "bootlcd.h"

void low_isr(void);
void high_isr(void);

#pragma code low_vector=0x2018
void interrupt_at_low_vector(void)
{
  _asm GOTO low_isr _endasm
}
#pragma code 

#pragma code high_vector=0x2008
void interrupt_at_high_vector(void)
{
  _asm GOTO high_isr _endasm
}
#pragma code 

#pragma interruptlow low_isr
void low_isr (void)
{
  
 return;
}

#pragma interrupt high_isr
void high_isr (void)
{
 return;
}


void DelayFor18TCY( void )
{
 Delay10TCYx(2);        // 5us delay
 return;
}
void DelayPORXLCD (void)
{
  Delay1KTCYx(75); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 20MHz) / 4
                   // Cycles = 75,000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(25); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 20MHz) / 4
                   // Cycles = 25,000
  return;
}

void display_lcd (unsigned int intval)
{
	unsigned int volt;
	char out[10];

	volt = intval /  131 ;
    while(BusyXLCD());              // Wait if LCD busy
	SetDDRamAddr(0x00); 
	putrsXLCD("RAW : ");
	ltoa(intval, out);
	putsXLCD(out);
	putrsXLCD("     ");
    while(BusyXLCD());              // Wait if LCD busy
	SetDDRamAddr(0x40);  // select 2 line
	putrsXLCD("Volt : ");
	itoa(volt, out);
    while(BusyXLCD());              // Wait if LCD busy

	if(volt>99)
	{
		WriteDataXLCD(out[0]);
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD('.');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD(out[1]);
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD(out[2]);
	}else if(volt>9)
    {
		WriteDataXLCD('0');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD('.');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD(out[0]);
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD(out[1]);
	}
     else
	{
		WriteDataXLCD('0');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD('.');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD('0');
    	while(BusyXLCD());              // Wait if LCD busy
		WriteDataXLCD(out[0]);
	}

	putrsXLCD("V     ");
}



void main( void )
{
  char temdata;
  
  unsigned int current_ad_value;
  TRISAbits.TRISA0 = 1;
  /* FOSC/32 clock select , left alignment*/
  ADCON2bits.ADCS0 = 1;
  ADCON2bits.ADCS1 = 1;
  ADCON2bits.ADCS2 = 1;
  ADCON2bits.ADFM = 0;

  /* interal ref */
  ADCON1 = 0b00000000;
  /* Turn on the ADC */
  ADCON0bits.ADON = 1;

  OpenXLCD();     // configure external LCD

  while(1)
  {
         /* Give the ADC time to get ready. */
      Delay100TCYx (2);
      /* start the ADC conversion */
      ADCON0bits.GO = 1;
      while (ADCON0bits.GO);
      current_ad_value = ADRES;
	  display_lcd(current_ad_value);
      Delay10KTCYx (200);
  }

}


Bootlcd.h details







anonymous   said:
6 years ago

when i compile this following error generate
Using Hi-tec compiler
Error [141] C:\\Documents and Settings\Administrator\My Documents\My Music\LCD 1\LCD code.c; 5.22 can't open include file " p18F4550.h": No such file or directory


Points :   0


physics   said:
6 years ago

@rightbk

hi

did u rebuild c18 compiler...

see details : http://romux.com/bootloader/usb-pic18f4550/bootloader-details

|
Points :   0


rightbk   said:
6 years ago

Hello everybody!
I like this project so much,I used the project, MPLAB 8.4 C18, but I have occured a problem, that is not display value Volt, when i change value of VR (AN0), result didn't change.

Anybody Could help me, pl?

|
Points :   0




Post Your Comments Here :
 


User Login

Username :


Password :