Skip to content

Instantly share code, notes, and snippets.

@JHeld07
Created October 7, 2015 18:04
Show Gist options
  • Save JHeld07/b51315a2dd15ffe0426c to your computer and use it in GitHub Desktop.
Save JHeld07/b51315a2dd15ffe0426c to your computer and use it in GitHub Desktop.
#include <18f4520.h>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOLVP
#include "../Library/18f4520ptr.h"
#include "../Library/modifiedlcd.h"
float Vres=6.0/1023.0;
float Voltage;
float Vmin=3;
#INT_AD
void int_ad_isr(){
Voltage=*Q*Vres-Vmin;
}
main(){
lcd_init();
ADCON0->ADON=1;
ADCON0->CHSx=0;
ADCON1->PCFGx=8;
*TRISA=0x0F; // A0 input
ADCON2->ADFM=1; //RJ
//Enable References
ADCON1->VCFG0=1;
ADCON1->VCFG1=1;
//Interupt Setup
PIE1->ADIE=1;
INTCON->GIE=1;
INTCON->PEIE=1;
while(1){
printf(lcd_putc,"\f %FV", Voltage);
delay_ms(300);
ADCON0->GODONE=1; //Go
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment