Skip to content

Instantly share code, notes, and snippets.

@chukitow
Created May 29, 2014 19:00
Show Gist options
  • Select an option

  • Save chukitow/499d8d51ba8882c7625e to your computer and use it in GitHub Desktop.

Select an option

Save chukitow/499d8d51ba8882c7625e 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=4000000)
#use rs232(baud=9600, bits = 8 , parity = N ,xmit=PIN_C6,rcv=PIN_C7)
#include <ds1307.c>
float temperatura;//Variable que almacenara la temperatura;
boolean timerFired=false;//bandera para disparar el timer
/*DS 1307*/
int segundos=0;
int minutos=0;
int horas=0;
int dias=0;
int mes=0;
int year=0;
int dow=0;
#INT_TIMER0
void isr_timer()
{
timerFired = true;
set_timer0(3036);
}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
set_timer0(3036);
setup_adc(ADC_CLOCK_INTERNAL); //Modificamos el clock interno del ADC
setup_adc_ports(ALL_ANALOG); //Establecemos el puerto RA0 como analogo
set_adc_channel(0); //Channel 0 correspondiente a RA0
while(true)
{
if(timerFired)
{
temperatura = (read_adc() * 0.4887);
printf("Temperatura %2.2f \r",temperatura);
timerFired=false;
getDate(dias,mes,year,dow);
getTime(horas,minutos,segundos);
printf("%i / %i / %i \r", dias , mes , year);
printf("%i : %i : %i \r\r" , horas , minutos ,segundos);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment