Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // :::::::::::: DADO ELECTRóNICO ::::::::::::::::::::::::::::::::::
- // ::::::::: diseño y programación por Albert López. ::::::::::::::
- // ::::::::: http://utronic.blogspot.com/ :::::::::::::::::::::::::
- #include "C:\Users\Desktop\Termostato\Codigo fuente\main.h" //Indicar el PAth correcto para compilar
- #define LCD_ENABLE_PIN PIN_D0
- #define LCD_RS_PIN PIN_D1
- #define LCD_RW_PIN PIN_D2
- #define LCD_TYPE 1
- #define RELE PIN_E0
- #include <lcd.c>
- Unsigned int temp;
- int x;
- void sensado_temp(){
- temp= (2.0 * x*1000.0)/1024.0; //Calibramos el sensado deacuerdo al error de lectura.
- }
- void main()
- {
- lcd_init();
- lcd_putc("\utronic \n");
- delay_ms(2000);
- lcd_putc("\f");
- lcd_putc("\Leyendo Temp...\n");
- delay_ms(2000);
- lcd_putc("\f");
- setup_adc_ports(AN0|VSS_VDD);
- setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_6);
- setup_psp(PSP_DISABLED);
- setup_spi(SPI_SS_DISABLED);
- setup_wdt(WDT_OFF);
- setup_timer_0(RTCC_INTERNAL);
- setup_timer_1(T1_DISABLED);
- setup_timer_2(T2_DISABLED,0,1);
- setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
- setup_comparator(NC_NC_NC_NC);
- setup_vref(FALSE);
- //Setup_Oscillator parameter not selected from Intr Oscillator Config tab
- // TODO: USER CODE!!
- //:::::::::::: CONDICIONES INICIALES PUERTOS ::::::::::
- set_tris_A(0xC0);
- set_tris_C(0xff);
- set_tris_B(0x00);
- set_tris_D(0x00);
- set_tris_E(0xC);
- output_C (0xff);
- output_B (0x00);
- output_A (0xC0);
- output_D (0x00);
- output_E (0xC);
- //:::::::::::::::::::::::::::::::::::::::::::::::::::::
- //::::::::::::: CONDICIONES INICIALES DE VARIABLES ::::::::::::
- temp = 0;
- x = 0;
- //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- while(1){
- set_adc_channel(0); //seleccionamos canal 0
- delay_ms(13);
- x = read_adc(); //lectura del CAD
- delay_us(13);
- sensado_temp();
- lcd_gotoxy(1,1); //Situamos donde escribir en el LCD
- printf(LCD_PUTC,"Temperatura %u",temp); // Escribimos en el LCD
- delay_ms(20);
- IF ((temp>=21) | (temp<=28)){ //Sensado de la temperatura por histéresis.
- output_low(RELE);
- }
- IF ((temp<21) | (temp>28)){
- output_high (RELE);
- }
- }
- }
Add Comment
Please, Sign In to add comment