skapunky

Codigo Termostato con LM35 y PIC18F4520

Feb 17th, 2012
2,440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pic 16 2.19 KB | None | 0 0
  1. // :::::::::::: DADO ELECTRóNICO ::::::::::::::::::::::::::::::::::
  2. // ::::::::: diseño y programación por Albert López. ::::::::::::::
  3. // ::::::::: http://utronic.blogspot.com/ :::::::::::::::::::::::::
  4.  
  5.  
  6. #include "C:\Users\Desktop\Termostato\Codigo fuente\main.h" //Indicar el PAth correcto para compilar
  7.  
  8. #define LCD_ENABLE_PIN PIN_D0
  9. #define LCD_RS_PIN PIN_D1
  10. #define LCD_RW_PIN PIN_D2
  11. #define LCD_TYPE 1
  12. #define RELE PIN_E0
  13.  
  14. #include <lcd.c>
  15.  
  16. Unsigned int temp;
  17. int x;
  18.  
  19.  
  20. void sensado_temp(){
  21.  
  22. temp= (2.0 * x*1000.0)/1024.0;  //Calibramos el sensado deacuerdo al error de lectura.
  23. }
  24.  
  25.  
  26.  
  27. void main()
  28. {
  29.   lcd_init();
  30.   lcd_putc("\utronic \n");
  31.   delay_ms(2000);
  32.   lcd_putc("\f");
  33.   lcd_putc("\Leyendo Temp...\n");
  34.   delay_ms(2000);
  35.   lcd_putc("\f");
  36.  
  37.    setup_adc_ports(AN0|VSS_VDD);
  38.    setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_6);
  39.    setup_psp(PSP_DISABLED);
  40.    setup_spi(SPI_SS_DISABLED);
  41.    setup_wdt(WDT_OFF);
  42.    setup_timer_0(RTCC_INTERNAL);
  43.    setup_timer_1(T1_DISABLED);
  44.    setup_timer_2(T2_DISABLED,0,1);
  45.    setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
  46.    setup_comparator(NC_NC_NC_NC);
  47.    setup_vref(FALSE);
  48. //Setup_Oscillator parameter not selected from Intr Oscillator Config tab
  49.  
  50.    // TODO: USER CODE!!
  51.    
  52. //:::::::::::: CONDICIONES INICIALES PUERTOS ::::::::::
  53.    set_tris_A(0xC0);
  54.    set_tris_C(0xff);
  55.    set_tris_B(0x00);
  56.    set_tris_D(0x00);
  57.    set_tris_E(0xC);  
  58.  
  59.    output_C (0xff);
  60.    output_B (0x00);
  61.    output_A (0xC0);
  62.    output_D (0x00);
  63.    output_E (0xC);
  64. //:::::::::::::::::::::::::::::::::::::::::::::::::::::
  65.  
  66.  
  67. //::::::::::::: CONDICIONES INICIALES DE VARIABLES ::::::::::::
  68. temp = 0;
  69. x = 0;
  70. //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  71.  
  72. while(1){
  73.  
  74.  set_adc_channel(0);  //seleccionamos canal 0
  75.  delay_ms(13);
  76.  x = read_adc();  //lectura del CAD
  77.  delay_us(13);
  78.  sensado_temp();
  79.  
  80.  
  81.  lcd_gotoxy(1,1);  //Situamos donde escribir en el LCD
  82.  printf(LCD_PUTC,"Temperatura  %u",temp); // Escribimos en el LCD
  83.  delay_ms(20);
  84.  
  85.    IF ((temp>=21) | (temp<=28)){  //Sensado de la temperatura por histéresis.
  86.    output_low(RELE);
  87.  
  88.    }
  89.    
  90.    IF ((temp<21) | (temp>28)){
  91.    output_high (RELE);
  92.  
  93.    }
  94. }
  95.  
  96. }
Add Comment
Please, Sign In to add comment