Skip to content

Instantly share code, notes, and snippets.

@JHeld07
Created October 9, 2015 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JHeld07/26ac63a2a87b778b6712 to your computer and use it in GitHub Desktop.
Save JHeld07/26ac63a2a87b778b6712 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/KeypadC1.h"
#include "../Library/modifiedlcd.h"
float Vres=5.0/1023.0;
float Voltage, Voltage1;
float Vmin=0;
#INT_AD
void int_ad_isr(){
Voltage=*Q*Vres-Vmin;
}
main(){
int16 press1, press2, VoltagePer;
lcd_init();
ADCON0->ADON=1;
ADCON0->CHSx=0;
ADCON1->PCFGx=0x0F;
*TRISA=0x0F; // port A input
*TRISB=0xF0;
*TRISC=0x00;
ADCON2->ADFM=1; //RJ
//Enable References
ADCON1->VCFG0=1;
ADCON1->VCFG1=1;
//Interupt Setup
PIE1->ADIE=1;
INTCON->GIE=1;
INTCON->PEIE=1;
INTCON2->RBPU=0;
while(1){
press1=(int16)KeyPress()-0x30; //Takes the ASCII value from the keypress and removes the hex value.
Voltage1=((Voltage/5)*100); // Converts voltage from pot to a % value.
if(press1<=9 && press1>=0){
press2=((press2*10)+press1);
if(press2>100){
press2=0;
}
}
printf(lcd_putc,"\f %2.0f", (Voltage1-press2));
printf(lcd_putc,"\n %1.2fV %lu", Voltage, press2);
ADCON0->GODONE=1; //Go
delay_ms(300);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment