Eliminar codigo temperatura y dejar timer en asm

Hola maestros estoy aprendiendo a "entender" la programacion en mplab con el famoso asm para luego pasarlo a hex. Un ingeniero me diseño un medidor de temperatura con sensor pt100 y timer,

pues bien yo intente eliminar toda la parte de temperatura pero me marca muchos errores a la hora de convertir a hex o mejor dicho "build"....
mi msn es gb@live.com.ar si me adieren al msn mejor

si me ayudan aqui pongo el codigo

Código:
/*                 
========================================================================================================================    
Software Versión PirometroV1_Debug23_Placa.c y PirometroV1 para el MPLAB -ultima versión de software que funciona bien -
Verson que funciona bien en PIC 16F873A I/SP
TIENE CAMBIADA LA ECUACION DE TEMPERATURA EN °C
Contiene:
* Botones aumenta, disminuye, temp y tiempo.
* Diplays 7 segmentos.
* Buzer
* Relé
* Led
Contiene las especificaciones del cliente V2:
* Al finalizar el conteo regresivo, suena el buzer 5 segundos
* Siempre se esta mostrando la temperatura actual
* Cuando se presiona cualquier boton suena un pitido
* Al presionar switch (bajar plancha) inicia el conteo regresivo
* Al soltar switch vuelve a mostrar la temperatura
Con boton tiempo se programa un tiempo y se lo guarda en memoria.
Con boton temp se programa una temperatura y se la guarda en memoria.
En modo programación titila el punto decimal del último digito.
Con boton aumenta y disminuye se cambian la temperatura y el tiempo deseado.
El tiempo se mide en segundos y se visualiza en min y seg.
Al oprimir programar una variable, al salir luego(se haya cambiado o no el valor de programación) queda mostrando esa variable. 
Osea, si queiro ver temp/tiempo presiono 2 veces program Temp/tiempo sin cambiar el valor seteado.
Posee manejo de A/D.
Posee antirebote con delays en la subrutina ppal. Al mantenerse presionado el boton de forma continua se acelera el seteo.
En el incio se muestra temperatura actual
Guarda en la EEPROM los valores de temp y tiempo seteados
Al finalizar suena el buzer 3 seg y se encende el LED hasta un nuevo conteo
Posee control de temperatura.   
Posee protección en caso de desconexión del sensor. En ese caso se abre el rele, suena el buzer y queda encendido el led
Falta:
Oredenar un poco el código
Actualizar comentarios
========================================================================================================================*/

#include <PIC1687x.h>
#include <delay.h>
#include    <stdio.h>
#include    <htc.h>
static bit              led             @ (unsigned)&PORTC*8+0;  
static bit              rele           @ (unsigned)&PORTA*8+4;
static bit              buzer           @ (unsigned)&PORTA*8+5;
static bit       switchplancha   @ (unsigned)&PORTB*8+3; 
static bit       btn_tiempo      @ (unsigned)&PORTB*8+4;      
static bit              boton_tiempo;
static bit       btn_temp        @ (unsigned)&PORTB*8+5;      // Boton seteo temperatura
static bit              boton_temperatura;
static bit       btn_dis         @ (unsigned)&PORTB*8+6;      // Boton disminuye
static bit              boton_disminuye;
static bit       btn_aum         @ (unsigned)&PORTB*8+7;      // Boton aumenta
static bit              boton_aumenta;
static bit       pto_unidad      @ (unsigned)&PORTB*8+0;      //punto de la unidad
static bit       pto_minutos     @ (unsigned)&PORTB*8+2;      //punto en la centena pero esta en la decena!!!!!!!!

//displays 7 segmentos
static bit              D1              @ (unsigned)&PORTC*8+3;      //salidas a transistores de displays (verificar el puerto!!!)
static bit              D2              @ (unsigned)&PORTC*8+1;
static bit              D3              @ (unsigned)&PORTC*8+2;
// dato Display 7 segmentos
static bit              A               @ (unsigned)&PORTC*8+4;
static bit              B               @ (unsigned)&PORTC*8+7;
static bit              C               @ (unsigned)&PORTC*8+6;
static bit              D               @ (unsigned)&PORTC*8+5;
//variables estaticas
unsigned int                    tiempo_restante;
unsigned int                    variable;
unsigned int                    temp_actual;                       
unsigned char                   temp_actualH;
unsigned char                   temp_actualL;
unsigned int                    tiempo_deseado;                   
unsigned int                    temperat_deseada;
unsigned char                   unidad = 0;
unsigned char                   dec = 0;
unsigned char                   decena = 0;
unsigned int                    centena = 0;
unsigned char                   TempH, TiempoH = 0;
unsigned char                   TempL, TiempoL = 0;
unsigned char                   esp = 3;
static bit                      termino = 0;
volatile unsigned char          digito, tickCounter, apaga_buz, pitido;
volatile unsigned int           ret1, ret2, contadoradq, contadorfin, contadortitila1, contadortitila2, contadortitila11, contadortitila22;
volatile unsigned char          salir = 1;
const unsigned char    Tonh = 0x0B;  
const unsigned char    Tonl = 0xDB;       //TonH+TonL = 3035
static bit                      aum,dism, titila_pto, titila_led, set_time,set_temp = 0;  
static bit                      cambiar_tiempo,cambiar_temp,write_time,write_temp,emergencia = 0;
static bit                      puso_tiempo,iniciar_control, calentamiento; 
static bit                      puso_temp, puede_controlar;
//control
unsigned int temp70, buffer, sob, umbral_calc, umbral_inf, prim_vez;
unsigned char regimen, sobrepaso, llego;
unsigned char i,prim_cal, seg_cal,prim_sob, continuo;

void inicializar (void){
    PORTA = 0;
    PORTB  = 0;                            //   Inicializa port B.
    PORTC  = 0;                            //   Inicializa port C.
    TRISA = 0B11001111;                      //   RA0 entrada A/D, RA1..RA7 salidas
    TRISB = 0B11111000;                      //   RB0..RB2 salidas, RB3..RB7 entradas                    
    TRISC = 0B00000000;                      //   RC0..RC7 salidas    
    PORTA = 0;
    PORTB  = 0;                            //   Inicializa port B.
    PORTC  = 0;                            //   Inicializa port C.                 
    GIE = 0;
    D1,D2,D3 = 0;
   
    OPTION = 0B00000000;                       // NO CAMBIADO A PULLUPS PORTB DISABLED               
    ret1 = 0;                                 //cont de tiempo de apagado/enc en titleo
    ret2 = 80;                               //cont de tiempo de apagado/enc en titleo
    
    pto_unidad = 0;
    aum = 0;
    contadoradq = 0;
    contadorfin = 0;
    contadortitila1 = 0;
    contadortitila11 = 0;
    contadortitila2 = 80;
    contadortitila22 = 80;
    buffer = 2;
    puede_controlar=0;
    sobrepaso = 0;
    llego = 0;
    iniciar_control = 0;
    calentamiento = 0;
    emergencia = 0;
    continuo = 0;
    prim_sob = 0;
    prim_vez = 1;
    seg_cal=0;
    switchplancha = 1;
//  A/D
    //ADCON1 = 0B10000010;    //Right justified result; Vref- = Vss; Vref+ = Vdd; AN0..AN4 = Analogic Input 
    ADCON1 = 0B10001110;    //Right justified result; Vref- = Vss; Vref+ = Vdd; AN0, AN1 y AN3 = Analogic Input 
    ADCON0 = 0B10000000;    // Fosc/32; RA0/AN0 = input; A/D = off;        
 
}
 
void IniTmr0(void) {
                      TMR0 = 61;                                    // 256 - TMR0 = (Fosc/4) * (1/fm) / Presc; Para fm 100Hz => TMR0=61 
                      OPTION = 0b00000111;                          // Presc = 256  
                      T0IE = 1;
                      T0IF = 0;
                      GIE = 1;
}
void IniTmr1(void) {
                    TMR1H = Tonh;                                  //00001011
                   TMR1L = Tonl;                                  //11011011 //TMR1H+TMR1L = 3035 => 62500 cuentas => t = 62500*(4/20 MHz)*presc = 100 mS e interrumpe
                   T1CON =  0B00110101;                       // Timer1 on, prescaler = 8, timer mode
                   TMR1IF = 0;                                    // flag not overflow
                   TMR1IE = 1;                                    // interrupt enabled
               
                                                    
} 
void adquiere_pt100(void) {
                      ADCON0 = 0B10000100;                           // Fosc/32; RA0/AN0 = input; A/D = off;  
                      ADIF = 0;                                      // Flag de interrup = 0;
                      ADIE = 1;                                      //Habilito interrupcion A/D;
                      GIE = 1;
                      ADON = 1;                                      //Habilito el A/D
                      GODONE = 1;                                    // Comienza a convertir, al terminar baja a cero
                      
}
void control_temp (void){

                      umbral_inf = temperat_deseada - 5;                                  
                      temp70 = (temperat_deseada*7)/10;                                   // 70% de la temp deseada  
              if (iniciar_control){  
                        
 
                       if (temp_actual<temp70) {
                      
                           prim_cal = 1;                                                   //chequea que comience debajo de temp70%
                           calentamiento = 1;
                           continuo = 0;
                           prim_vez=0;
                           seg_cal=0;
                           iniciar_control = 0;
                           
                       }
                       if (temp_actual>temp70) {
                           continuo = 1;
                           iniciar_control = 0;
                           calentamiento = 0;
                           buffer = 2;  
                           sobrepaso= 0;                           
                           seg_cal = 1;
                       }
              }
         
                  if (calentamiento){           
                      if ((prim_cal)&&(temp_actual<temp70)){                                               
                              
                            rele = 1;                                                        //esta en 1° calentamiento, enciende el calefactor 
                            sobrepaso=1;
                      }
                      else{
                        
                           if ((sobrepaso)&&(temp_actual>temp70)){                            //sobrepasó 70% temp seteada en 1° calentamiento y
                                
                                rele = 0; 
                                prim_cal=0;                                                   // apaga para calcular la inercia térmica                     
                              
                                
                                if (temp_actual>buffer)   buffer = temp_actual;                //guardo en buffer el maximo de sobresalto luego de cortar al 60%
                                if ((temp_actual)<=(buffer-1)){
                                   sobrepaso = 0;
                                   seg_cal=1;
                                }
                                if (temp_actual>umbral_inf){                    // En el caso de sobrepasar umbral inf en el apagado del 70%
                                             continuo = 1;
                                             
                                             calentamiento = 0;
                                             buffer = 2;  
                                             sobrepaso= 0;                           
                                             seg_cal = 1;
                                             
                                }
                           }
                        
                           else{
                                if (((temp_actual<umbral_inf))&&(seg_cal)){                       //luego de calcular el sobrepaso desciende y pasa por temp70%
                              
                                  rele = 1;                                                               
                                  sobrepaso = 0;
                                  seg_cal = 1;
                                  prim_sob = 1;
                                 
                                }
                              
                                if ((temp_actual)>(umbral_inf-2)){                              //umbral de tempdeseada - 5°C
                                             continuo = 1;
                                             
                                             calentamiento = 0;
                                             buffer = 2;                               //se limpia el buffer
                                             seg_cal = 1;
                                }
                                                            
                           }                                  
                           
                      }
                 }
              
              if (continuo){                                 //luego de un primer calentamiento sin sobrepaso o un inicio 
                                                              //caliente pasa a modo continuo donde corta el calentamiento en temp deseada
                      if (temp_actual<temp70){                                               
                            buffer = 2;  
                            rele = 1;                                                    //se plancha y cae por debajo del 70% seteado 
                            sobrepaso=1;
                            seg_cal=0;
                      }
                        if ((sobrepaso)&&(temp_actual>temp70)){                                 
                                
                                rele = 0; 
                                                                                        // apaga para frenar inercia termica                     
                              
                                
                                if (temp_actual>buffer)   buffer = temp_actual;           //guardo en buffer el maximo para continuar luego desde alli - 2°C
                                if ((temp_actual)<=(buffer-1)){
                                   sobrepaso = 0;
                                   seg_cal=1;
                                }
                        }
                        
                        if (((temp_actual)<(umbral_inf+1))&&(seg_cal)) {
                               rele = 1;
                        }
                        if ((temp_actual)>(temperat_deseada-3)) {        //corta dos grados antes
                               rele = 0;
                               
                        }
                       
              }
                        if ((temp_actual)>(temperat_deseada-3)) {
                               rele = 0;
                               
                        }
              
                  
}
void lee_memoria(void){
                 if (set_temp){
                      TempH = eeprom_read(3);
                      temperat_deseada = TempH;
                      temperat_deseada = temperat_deseada<<8;
                      TempL = eeprom_read(2);
                      temperat_deseada = ((temperat_deseada) | (TempL));       //variable contiene la temperatura almacenada */
                      if (temperat_deseada > 301) temperat_deseada= 0;
                      if (temperat_deseada < 1) temperat_deseada= 1;
                      
                 }
                 if (set_time){
                      
                      TiempoH = eeprom_read(5);
                      tiempo_deseado = TiempoH;
                      tiempo_deseado = tiempo_deseado<<8;
                      TiempoL = eeprom_read(4);
                      tiempo_deseado = ((tiempo_deseado) | (TiempoL));       //variable contiene la temperatura almacenada */
                      if (tiempo_deseado > 598) tiempo_deseado= 0;
                      if (tiempo_deseado < 1) tiempo_deseado= 1;
                 }
}
void escribe_memoria(void){
                 if (write_temp){
                      write_temp = 0;
                      TempL = temperat_deseada;
                      TempH = temperat_deseada>>8;
                      eeprom_write(2,TempL);
                      eeprom_write(3,TempH);
                     
 
                 }
                 if (write_time){
                      write_time = 0;
                      TiempoL = tiempo_deseado;
                      TiempoH = tiempo_deseado>>8;
                      eeprom_write(4,TiempoL);
                      eeprom_write(5,TiempoH);
                      if (cambiar_tiempo){ 
                           tiempo_restante = tiempo_deseado;                     //si cambió guarda el tiempo seteado para el reloj regresivo 
                      }
                     
                 }
}
void set_variable(void){
             if (cambiar_tiempo){
                      if(aum) {
                                
                                if (tiempo_deseado<599) tiempo_deseado++;   
                       
                      }
                      if(dism) {
                                
                                if (tiempo_deseado>1) tiempo_deseado--;    
                      }
                  
             }       
             if (cambiar_temp){
                      if(aum) {
                                
                                if (temperat_deseada<301) temperat_deseada++; 
                                puede_controlar = 1;                          
                      }
                      if(dism) {
                               
                               if (temperat_deseada>1) temperat_deseada--;
                               puede_controlar = 1;
                      }
                      
                      
                   
             }        
                 
                      aum = 0;
                      dism = 0;
                     
}
void var_a_3_7segm(void){                      // pasa un Char a tres siete segmentos 
              if ((set_temp)|(puso_temp)){
                                centena = variable/100;
                                dec = (variable)-(100*centena);
                                decena = dec/10;
                                unidad = (dec)-(10*decena);
                                pto_minutos = 0;
              }
              else {
                      
                    if ((set_time)|(puso_tiempo)){
                           centena = variable/60;
                           dec = variable - (60*centena);
                           decena = dec/10;
                           unidad = (dec)-(10*decena);                                             
                           pto_minutos = 1;
                          
                    }
                    else {
                                   variable = temp_actual;     // si no se seteó ninguna variable, que muestre la temp actual...
                                   centena = variable/100;
                                   dec = (variable)-(100*centena);
                                   decena = dec/10;
                                   unidad = (dec)-(10*decena);
                                   pto_minutos = 0;
                                   titila_led = 1;                        // comienza titilando el led
                   }
           }
}
void visualizar(void){
                      digito++; 
                      switch(digito){
                                     case 1:{  
                                             D2= 0;
                                             D3= 0;             
                                             A = unidad;
                                             B = unidad>>1;
                                             C = unidad>>2;
                                             D = unidad>>3; 
                                             D1= 1;
                                            
                                             break;
                                             }
                                     case 2:{  
                                             D1= 0;
                                             D3= 0;
                                             A = decena;
                                             B = decena>>1;
                                             C = decena>>2;
                                             D = decena>>3; 
                                             D2= 1;
  
                                             break;
                                            
                                             }
                                     case 3:{  
                                             D1= 0; 
                                             D2= 0;
                                             A = centena;
                                             B = centena>>1;
                                             C = centena>>2;
                                             D = centena>>3; 
                                             D3= 1; 
 
                                             break;
                                             }
                                                                          
                               }
                      if(digito==3)digito=0;
                      if (emergencia) {                          // en emergencia se apagan los displays entre otras cosas
                             D1 = 0;
                             D2 = 0;
                             D3 = 0;
                      }
}

 
static void interrupt isr(void) {
         if ((T0IF)&&(T0IE)){                                             //TIMER para visualización de 7segmentos
                      T0IF = 0;                                            
                      TMR0 = 170;                                          //Tiempo de visualización a  
       
                                      
                          
                      if ((set_time)|(set_temp)){                       //titilan los 7 seg mientras seteo tiempo o temperatura 
                          ret1++;
                          D1 = 0;
                          D2 = 0;
                          D3 = 0;
                          if (ret1 >= 80) {                              //Tiempo de titilación 
                                ret2--;
                             var_a_3_7segm();
                             visualizar();
                          
                             if (ret2 == 0){
                                ret1 = 0;
                                ret2 = 80;
                              
                             }                               
                          } 
                          
                          if (set_time) variable = tiempo_deseado;                                                          
                          if (set_temp) variable = temperat_deseada;                                                                                               
                      }    
                      else{
                          if (puso_temp) {
                                 
                                 variable = temp_actual;                                //dejar mostrando el tipo de variable que seteó ultimo, hacer un flag en el bucle anterior..                                
                                                              
                                
                          }
                          if (puso_tiempo){
                                 if (cambiar_tiempo) {
                                        tiempo_restante = tiempo_deseado;
                                        cambiar_tiempo = 0;
                                 }
                                 else {
                                     variable = tiempo_restante;                        
                                                                             
                                 }
                          }
                          pto_unidad = 0;
                          var_a_3_7segm();
                          visualizar();
                      }
                       if (titila_pto){
                          contadortitila1++;
                          led = 0;                          
                          if (contadortitila1 >= 80) {                             
                             contadortitila2--;
                             pto_unidad = 1;                                       //titila el pto de la unidad en el conteo regresivo
                          
                             if (contadortitila2 == 0){
                                contadortitila1 = 0;
                                contadortitila2 = 80;
                                pto_unidad = 0;
                             }                               
                          } 
                       }   
                       if (titila_led){
                          contadortitila11++;
                          
                          if (contadortitila11 >= 80) {                             
                             contadortitila22--;
                             led = 1;                                     
                          
                             if (contadortitila22 == 0){
                                contadortitila11 = 0;
                                contadortitila22 = 80;
                                led = 0;
                             }                               
                          } 
                       }   
 

         } 

         if((TMR1IE)&&(TMR1IF)){
                  
                     TMR1IF=0;           
               if(++tickCounter == 10){        //cada conteo = 100mS  => 10 conteos = 1 Seg
                     tickCounter=0;
                           if ((tiempo_restante>0)&&(puso_tiempo)){            //si se presiono el switch y se seteo tiempo comienza el conteo regresivo
                                titila_pto = 1;                     //titila el pto de la unidad en el conteo regresivo
                                titila_led = 0;
                                tiempo_restante--;                
                                                                
                                if (tiempo_restante==0){
                                    
                                   
                                    buzer = 1;
                                    termino = 1;         //variable para apagar con cualquier boton una vez terminado
                                    titila_pto = 0;
                                    titila_led = 1;
                                    
                                }
                           }
                  
               }
                     if (++contadoradq == 5){         //cada 500 mS adquiere del pt100
                           contadoradq = 0;
                           adquiere_pt100();
 
                     }
                     if (pitido){
                        buzer = 1;
                        if (++apaga_buz == 2){         //cada 500 mS adquiere del pt100
                             buzer = 0;
                             apaga_buz = 0;
                             pitido = 0;   
                        }
                     }
                     if (termino){                   
                        if (++contadorfin == 30){            //al terminar conteo suena el buzer 3 segundos
                              
                             contadorfin = 0;                             
                             buzer = 0;
                             termino = 0;
                             puso_tiempo = 0;                 //queda mostrando la temp actual
                                                  
                        }
                    }
                   
                   
      }
         if (ADIF){
                               
                 temp_actualH = ADRESH;
                 temp_actualL = ADRESL;
                 temp_actual = temp_actualH;
                 temp_actual = temp_actual<<8;
                 temp_actual = ((temp_actual) | (temp_actualL));
                  
                 // t en °C                
                 temp_actual = (((temp_actual-268)*50)/56);                                        // Ecuacion de Temp y = 1.122*t+312 => t=((y-312)*1000)/1122  
                 if ((temp_actual>600)&&(temp_actual<620)) {                                   //SEGURIDAD por si se desconecta el PT100
                       
                       emergencia = 1;
                       rele = 0;                                                             // es el rango que da temp_actual desconectando el sensor
                       T0IE =0; 
                       D1, D2, D3 = 0;                                                         //apaga los displays
                       buzer = 1;
                       titila_led=0;
                       led = 1;
                 }
                 ADIF = 0;
                 control_temp();
         }
        
}
 

main() {
inicializar ();
IniTmr0();
IniTmr1();
led = 0;
set_time=0;
set_temp=0;
lee_memoria();
    while(1){  
                       if (!btn_tiempo){                             
                           DelayMs(120);                               // espera que se estabilice
                           if (!btn_tiempo){
                              pitido = 1;   
                              if (!set_temp){                           //para que no se superponga con el seteo de temperatura
                                    set_time ^= 1;                     
                                    if (set_time){ 
                                                lee_memoria();
                                                puso_temp = 0;
                                    }
                                    if (!set_time){
                                                write_time = 1;
                                                escribe_memoria();
                                             //   puso_tiempo = 1;           ahora lo hace el switch                                                                                             
                                    }
                              }
                           }
                                                             
                      }                  
                      if (!btn_temp){                           
                           DelayMs(120);                               // espera que se estabilice
                           if (!btn_temp){ 
                               pitido = 1; 
                               if (!set_time){                         //para que no se superponga con el seteo de tiempo
                                     set_temp ^= 1;                    
                                     if (set_temp){
                                                lee_memoria();
                                                puso_tiempo = 0;        
                                     }
                                     if (!set_temp){
                                                write_temp = 1;
                                                escribe_memoria();  
                                                cambiar_temp=0;             //nuevo!!!                                              
                                                puso_temp = 1;
                                                if (puede_controlar){
                                                    puede_controlar = 0;
                                                    iniciar_control = 1;           // inicia control si se seteo alguna temperatura, no si se observo
                                                    calentamiento=0;
                                                    continuo = 0;
                                                }
                                     } 
                              }  
 
              
                           }  
                      }
                      if (((!btn_aum)&&(btn_dis))&&(set_time)){ 
   
                            DelayMs(120); 
                           if(!btn_aum){  
                            pitido = 1;     
                            cambiar_tiempo=1;
                            aum = 1;
                            set_variable();
                           }                                                            
                      }
 
                      if (((!btn_dis)&&(btn_aum))&&(set_time)){   
                           
                            DelayMs(120);                               // espera que se estabilice
                            if (!btn_dis){                            
                               pitido = 1; 
                               cambiar_tiempo=1;
                               dism=1;
                               set_variable();                                                            
                            }
                      }
  
                      if (((!btn_aum)&&(btn_dis))&&(set_temp)){                                
                            DelayMs(120);                               // espera que se estabilice
                            if (!btn_aum){ 
                               pitido = 1; 
                               cambiar_temp=1;
                               aum = 1;
                               set_variable();                                                            
                            }
                      }
 
                      if (((!btn_dis)&&(btn_aum))&&(set_temp)){     
                            
                            DelayMs(120);                               // espera que se estabilice
                            if (!btn_dis){
                                pitido = 1; 
                                cambiar_temp=1;
                                dism=1;
                                set_variable();                                                            
                            }
                      }
                      if (switchplancha) {
                          DelayMs(120);  
                          if (switchplancha) {
                               puso_tiempo = 1;
                               
                               titila_pto = 1;   
                               if (esp==3){
                                    tiempo_restante = tiempo_deseado;
                                    --esp;
                               }
                          } 
                      }
                      if (!switchplancha) {
                          DelayMs(120);  
                          if (!switchplancha) {
                               puso_tiempo = 0;
                               esp = 3;
                               titila_pto = 0;   //nuevo
                                
                          } 
                      }  
                  
   }     
}


Gracias y saludos!
 
Atrás
Arriba