Skip to content

Instantly share code, notes, and snippets.

@chukitow
Last active September 10, 2015 22:34
Show Gist options
  • Save chukitow/f4f55b8624a001542b04 to your computer and use it in GitHub Desktop.
Save chukitow/f4f55b8624a001542b04 to your computer and use it in GitHub Desktop.
#include <18F4520.h>
#device adc = 10
#fuses XT, PUT, NODEBUG , NOBROWNOUT , NOPROTECT , NOLVP
#use delay(clock=16000000)
#use rs232(baud=9600, bits = 8 , parity = N ,xmit=PIN_C6, rcv=PIN_C7)
void read_adc_chanel();
float adc_sensor_1 = 0;
float adc_sensor_2 = 0;
boolean trigger_timer0 = false;
#INT_TIMER0
void isr_timer(){
trigger_timer0 = true;
set_timer0(3036);
}
void main(){
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
set_timer0(3036);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
while(true){
if(trigger_timer0){
read_adc_chanel();
}
}
}
void read_adc_chanel(){
set_adc_channel(0);
delay_ms(20);
adc_sensor_1 = (read_adc() * 0.4887);
set_adc_channel(1);
delay_ms(20);
adc_sensor_2 = (read_adc() * 0.4887);
trigger_timer0 = false;
printf("Sensor 1 %2.2f \r", adc_sensor_1);
printf("Sensor 2 %2.2f \r", adc_sensor_2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment