The ADC module of PIC18F4550 could read an analog input voltage up to 5 V DC with some DC offset. However, the outside analog voltage fed to the ADC could be greater than 5 V DC by adding a simple voltage divider circuit.
The voltage divider circuit is very simple, built by two resistors in this case. The output voltage from the divider circuit is smaller than the input according to the dividing factor. The factor created by picking up a different resistances of the selected's. The designer may decide and take a little math calculation using voltage divider theorem to get a specific division factor.
I don't show the overall process of math calculation here. You can see this post to get a full detail.
![]() |
The MCU reads the analog input voltage fed to RA0. |
PICC Source Code
#include<18f4550.h> | |
#device ADC=10 | |
/*Use high speed clock no PLL prescaler | |
no system clock post scaler */ | |
#fuses HS,PLL1,CPUDIV1 | |
#use delay(clock=20M) | |
#define LCD_ENABLE_PIN PIN_B2 | |
#define LCD_RS_PIN PIN_B0 | |
#define LCD_RW_PIN PIN_B1 | |
#define LCD_DATA4 PIN_B4 | |
#define LCD_DATA5 PIN_B5 | |
#define LCD_DATA6 PIN_B6 | |
#define LCD_DATA7 PIN_B7 | |
#include<lcd.c> | |
void adcConfig(void){ | |
//RA0 As Input | |
set_tris_a(0x01); | |
//Set RA0 To Analog | |
setup_adc_ports(AN0); | |
//Select ADC internal RC Clock | |
setup_adc(ADC_CLOCK_INTERNAL); | |
set_adc_channel(0); | |
delay_ms(10); | |
} | |
float getVoltage(void){ | |
int16 analogValue=read_adc(); | |
while(!adc_done()); | |
float voltage = (analogValue*5.0)/1024; | |
/*Voltage Divider*/ | |
voltage*=0.11; | |
/*Scale Up*/ | |
voltage*=100; | |
return voltage; | |
} | |
void main(){ | |
float voltage; | |
lcd_init(); | |
adcConfig(); | |
while(1){ | |
lcd_gotoXy(1,1); | |
printf(LCD_PUTC,"Voltage Reading"); | |
lcd_gotoXy(1,2); | |
voltage=getVoltage(); | |
printf(LCD_PUTC,"%0.2f Volts ",voltage); | |
delay_ms(250); | |
} | |
} |
Schematic Diagram
![]() |
Schematic Diagram |
Click here to download the zip file of this example.
If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.
![]() |
ATMega16 ATMega32 Experiment Board PCB from PCBWay |
Wow, I came to learn about Basic Series Digital Panel Meters, and your information is absolutely amazing! For more insights and if your are looking for the Top Basic Series Digital Panel Meters Manufacturer, check out Yokins! We specialize in reliable solutions to meet all your Digital Panel Meters. Keep up the great work!
ReplyDeleteVery great post. It's really very informative . After all I’ll be subscribing on your feed and I am hoping you write again very soon.And if you need more information aboutdigital panel meters Basic Series you can check out my page also. It will help you.
ReplyDeleteVery great post. It's really very informative . After all I’ll be subscribing on your feed and I am hoping you write again very soon.And if you need more information about digital panel meters basic series AC voltmeter you can check out my page also. It will help you.
ReplyDelete