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 CCS Technical Support

atoi function

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



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

atoi function
PostPosted: Fri Feb 22, 2008 9:00 am     Reply with quote

My task is press button to select time for relay on and off, but it doesn't work now, here is my code, hope you show me where I am wrong (my LCD works well as I expect, I think the problem lie in my C coding)
Code:

   int array[16]={'1','4','7','<','2','5','8','0','3','6','9','>','C','&','E','M'};
   int keyPressed;
   int16 timeResult;
// declare functions ...
void main()
{
   // TODO: USER CODE!!
   InitPic();
   InitLcd();
   timeResult=Keypad();
   delay_ms(500);
   do
   {
   output_high(PIN_C0);
   delay_ms(timeResult);
   output_low(PIN_C0);
   delay_ms(timeResult);
   }
   while(1);
}
int OnRelease()
{
   int i,j,k;
   int value[4]={0x07,0x0B,0x0D,0x0E};
   set_tris_a(0x0f);
   k=0;
   for(i=0;i<4;i++)
   {
      output_d(value[i]);
      delay_us(100);
      for(j=0;j<4;j++)
      {
         if(!input(40+j))
         {
            do
            {
               delay_ms(50);
            }
            while(!input(40+j));
            return k;
         }
         else
            k++;
      }
   }
   return -1;
}
//*************************
int16 Keypad()
{
   char number[];
   int iNum;
   int16 numResult;
   timeResult=0;
   do
   {
   keyPressed=OnRelease();
   if ((array[keyPressed] > 0x2F) && (array[keyPressed] < 0x3A))   // for numbers 0-9 only
   {
      WrDat2Lcd(array[keyPressed]);
      number[iNum]=array[keyPressed];
      iNum++;
   }
   if (array[keyPressed] == 'E')   // press Enter key to exit function
   {
      number[iNum]='\0';
      numResult=atoi(number);
      return numResult;
   }
   }
   while(1);
}
//*************************

Thanks !!!
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 22, 2008 1:57 pm     Reply with quote

Quote:
Code:
int OnRelease()
{
   int i,j,k;
   int value[4]={0x07,0x0B,0x0D,0x0E};
   set_tris_a(0x0f);
   k=0;
   for(i=0;i<4;i++)
   {
      output_d(value[i]);
      delay_us(100);
      for(j=0;j<4;j++)
      {
         if(!input(40+j))
         {
            do
            {
               delay_ms(50);
            }
            while(!input(40+j));
            return k;
         }
         else
            k++;
      }
   }
   return -1;         // << signed return value!
}


Remember ints are unsigned in CCS so this function may not work as you expect it to..

Also..

Quote:
Code:
int16 Keypad()
{
   char number[];


You need to set a size for 'number'
And Ive just noticed that you dont initialise inum
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