CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with input

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
se07860



Joined: 13 May 2008
Posts: 5

View user's profile Send private message

Problem with input
PostPosted: Tue May 13, 2008 3:23 am     Reply with quote

Good morning,

i have a problem with the input pins of my uprocessor.
It doesn't matter what i have in the input pins of portA. I always get the same values. I have the inputs with pull-ups and switches, is very simple this part, but doesn't work

Maybe is a problem of setup, but i can't find it.
The pic is a 16F876A

This is the .h code:

Code:

#include <16F876A.h>
#device adc=8
#FUSES NOWDT, XT, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, WRT_50%
#use delay(clock=4000000)
#define PuenteFacial   PIN_A0
#define PuenteCCompact   PIN_A1
#define PuenteCorporal   PIN_A2
#define PuenteComun   PIN_A3
#define ParoCorporal   PIN_A4
#define MarchaCorporal   PIN_A5
#define Zumbador   PIN_C2
#define Troceado   PIN_C3
#define RelePM   PIN_C5
#define LEDOff   PIN_C6
#define LEDOn   PIN_C7
#use rs232(baud=9600,parity=N,xmit=PIN_B4,rcv=PIN_B5,bits=8,invert)


And here is the .c code

Code:

#include "D:\Documents and Settings\Javier\Escritorio\Laboratorio\TF8 0.1B\TF8B.h"
  #include <stdio.h>


void main()
{
   char c;
   int pm, conex, chop, salida, puesta_en_marcha,i;
   int bot_paro,recepcion;
   int16 aux;
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   //setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   // TODO: USER CODE!!
   delay_ms(30000);
   output_low(Troceado); output_low(PuenteComun);
   output_low(LEDOn); output_low(LEDOff);
   chop=0; salida=0; puesta_en_marcha=0; recepcion=0; pm=1; conex=0; i=0; bot_paro=0;
   while(1)
   {
    if(kbhit())
    {
     c = getc();
     switch (c){
      case '0': chop=10; break;
      case '1': chop=20; break;
      case '2': chop=30; break;
      case '3': chop=40; break;
      case '4': chop=50; break;
      case '5': chop=60; break;
      case '6': chop=70; break;
      case '7': chop=80; break;
      case '8': chop=90; break;
      case '9': chop=100; break;
      case 'F': recepcion=0; pm=2; salida=1; break; //aquí debemos comprobar si la pieza de mano está puesta o no
      case 'c': recepcion=0; pm=3; salida=1; break; //aquí debemos comprobar si la pieza de mano está puesta o no
      case 'C': recepcion=0; pm=1; salida=0; break; //aquí debemos comprobar si la pieza de mano está puesta o no
      case 'M': i=0; bot_paro=0; if(chop==0){puesta_en_marcha=0;} else{puesta_en_marcha=1;} break;
      case 'P': i=0; output_low(RelePM); bot_paro=1; puesta_en_marcha=0; conex=0; if(salida==0) {output_low(LEDOn); output_high(LEDOff);} break;
      case 'R': recepcion=1; break; //Comprobamos si la pantalla confirma la recepcion de la orden
      case 'S': i=0; bot_paro=0; salida=0; chop=0; pm=1; conex=0; output_low(LEDOff); break;
      default: break; //puesta_en_marcha=0; chop=0; c='x'; break;
     } //Fin del switch
    }//Fin de if(kbhit())
    else
    {
      aux=input(PIN_A0);
      write_eeprom(1,aux);
      aux=input(PIN_A1);
      write_eeprom(2,aux);
      aux=input(PIN_A2);
      write_eeprom(3,aux);
      aux=input(PIN_A3);
      write_eeprom(4,aux);
      aux=input(PIN_A4);
      write_eeprom(5,aux);
      aux=input(PIN_A5);
      write_eeprom(6,aux);     
      output_high(Zumbador);
      while(1){}
     if(puesta_en_marcha==1)
     {
      if (salida==1) //Si la salida es [spam], activamos el relé y paramos las luces de la corporal
      {
       output_high(RelePM);
       output_low(LEDOn);
       output_low(LEDOff);
      }
      else
      {
       output_low(RelePM);
       output_high(LEDOn);
       output_low(LEDOff);
      }
      if(i>chop) output_low(Troceado);
      else output_high(Troceado);
      i++;
      if(i>100) i=0;
     } //Fin if(puesta_en_marcha==1)
     else{     
      //if(aux==0){if(bot_paro==1){if(salida==0){output_high(Zumbador); bot_paro=0; putc(77);}}}
/*      if (recepcion==0) { //Tenemos que enviar una info a la pantalla confirmando si la pieza de mano esta conectada o no
       output_high(PuenteComun);
       if((pm==1)&&(PuenteCorporal==1)) conex++; //Hay que ponerlos a 0 que es un pull-up!!!
       if((pm==2)&&(PuenteFacial==1)) conex++;
       if((pm==3)&&(PuenteCcompact==1)) conex++;
       if(conex==1)
       {
        conex=2;
        putc(86);//Es una 'v' de verificado
       }//Fin if(conex==1)
       if(conex>2) conex=2;
      }*/
     } //Fin else-if(puesta_en_marcha==1)
    } //Fin else-if(kbhit())
   } //Fin while(1)
}//Fin programa 


Thanks
Ttelmah
Guest







PostPosted: Tue May 13, 2008 4:12 am     Reply with quote

How often have you run this?.
I can't follow the whole thing through, but it appears to have an infinite loop, which if it doesn't find a character on the serial, then proceeds to write 6 bytes to the EEPROM. This seems to repeat indefinately, until a character is seen. Now the EEPROM, has a limited 'write life' on the PIC. A minimum of only 100K cycles. The cycle time is as small as 4mSec, so if the code does what it seems to do, it can potentially destroy the chip's EEPROM in about 400seconds (under 7 minutes). Once destroyed, the value will probably remain fixed, and would give what you are seeing.

Best Wishes
Guest








PostPosted: Tue May 13, 2008 5:48 am     Reply with quote

Thanks for your reply Ttelmah.

The program must be an infinite loop, but the writing on the eeprom is only because i want to verify the switches.

I have modified the code to write the eeprom only the first loop (and i've tried a new chip also).

I get the same input combination A5 A4 A3 A2 A1 A0 -> 0 1 0 0 0 0 but i've verified the Voltage in the pins and are 5V in all of them. Is because of this i think i can have a problem in the settings.
se07860



Joined: 13 May 2008
Posts: 5

View user's profile Send private message

PostPosted: Tue May 13, 2008 5:51 am     Reply with quote

Guest is me, sorry.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group