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

using all analogue inputs of pic16f877a for adc

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



Joined: 02 Feb 2014
Posts: 4
Location: cameroon

View user's profile Send private message

using all analogue inputs of pic16f877a for adc
PostPosted: Sun Feb 02, 2014 10:57 am     Reply with quote

hello!
I am designing a system which uses a keypad and an lcd plus pic16f877a MCU
It is to work as such:
If i press say key one on my keypad An0 should be active and is displayed on the lcd such that when i vary its potentiometer it should vary live on lcd.
When i press two, it should leave the loop and enter into the second case and vary live on lcd also.
The problem is when it enters into any case it won't leave the loop until i rerun the simulation.
Please help me with the C statement which can make my circuit work live without restarting my simulation.

I used
Code:

#include <ADC.h>
#include <KBD_MLB.c>//contains definition for keypad(4by4)
#include <ctype.h>
#define LCD_ENABLE_PIN PIN_D0
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7

#include <lcd.c>

void main()
{
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL);

   lcd_init();
   kbd_init();
   long int a,b,c,d,e,f,g,h;
   float i,j,k,l,m,n,o,p;
   char key;

   while(TRUE)
   {
   key=kbd_getc();
   switch(key)
   {
   

   case '1'://the array in KBD_MLB.C USES char for keypad
  do{
   set_adc_channel(0);
   delay_ms(200);
   a=read_adc();
   i=(float)(5*a)/256;
   printf(lcd_putc,"\f ANALOGUE:%01.2fV",i);
   printf(lcd_putc,"\n DIGITAL:%ld",a);
   }
  while(key=='1');

   break;
   
    case '2':
do{
   set_adc_channel(1);
   delay_ms(200);
   b=read_adc();
   j=(float)(5*b)/256;
   printf(lcd_putc,"\f ANALOGUE:%1.2fV",j);
   printf(lcd_putc,"\n DIGITAL:%ld",b);
   break;
   
   while(key=='2');

   
   /*odd inputs */
   
   
   case '0':
   printf(lcd_putc,"\f invalid input");
   break;
   
   
    case '9':
   printf(lcd_putc,"\f invalid input");
   break;
   
    case 'O':
   printf(lcd_putc,"\f invalid input");
   break;
   
    case '*':
   printf(lcd_putc,"\f invalid input");
   break;
   
    case '+':
   printf(lcd_putc,"\f invalid input");
   break;
   
    case '/':
   printf(lcd_putc,"\f invalid input");
   break;
   
    case '-':
   printf(lcd_putc,"\f invalid input");
   break;
 
    case '=':
   printf(lcd_putc,"\f invalid input");
   break;
   }

}
}

}


Crying or Very sad Crying or Very sad Crying or Very sad Crying or Very sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Sun Feb 02, 2014 11:32 am     Reply with quote

After you have read the key, you never read it again, so it's value will remain the same. So while(key==1) will always be true, and loop for ever. Same applies with every other value you use...

Also learn to use the code buttons, and read the data sheet about when you can use ADC_CLOCK_INTERNAL. You don't tell us your clock rate, but it is almost certainly not legal....

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Feb 02, 2014 11:34 am     Reply with quote

1) Are you using REAL hardware or computer SIMULATION?
2) Please use the code buttons to retain formatting.

Mike
duke.sir



Joined: 02 Feb 2014
Posts: 4
Location: cameroon

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 7:39 am     Reply with quote

i am using proteus for the simulation and for this purpose i use 20mhz as my internal clock frequency.
duke.sir



Joined: 02 Feb 2014
Posts: 4
Location: cameroon

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 7:44 am     Reply with quote

thanks you all for your support atleast am happy.
but really what i need is if some one can suggest a particular c statement that can make me live the loop of each case.
thanks and God bless you!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 8:41 am     Reply with quote

You are missing the point.

There is no simple C statement, you need to change your code, so it checks the key again. This will depend on how the key data is actually being 'done' (you are receiving it via RS232, but what happens when the key is held down - does the source keep sending characters?).

You can loop for ever, exit immediately, etc. etc.. These are all decisions made by _your_ code. Currently though the code keeps looping, and never tests the key again, so 'of course' it'll loop for ever. Just remove the while statements, and it'll respond to the next character, but will only send the reply once for each key character. If your source sends has 'key repeat', so will keep sending the key value, for as long as the key is held down, this is all you need to do....
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 8:57 am     Reply with quote

In my opinion you don't need driver for such a simple algorithm. You are using quite complicated code for implementation of a simple actions. I would suggest you to examine this https://drive.google.com/?tab=wo&authuser=0&urp=https://www.google.bg/?gws_rd%3Dcr%26ei%3DJwbdUriqFoHl4w#folders/0B_EYtdS7J5eKNGVqOVM5VlBFWW8 book. Refer to if - else conditions.
_________________
A person who never made a mistake never tried anything new.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 9:56 am     Reply with quote

duke.sir wrote:
i am using proteus for the simulation and for this purpose i use 20mhz as my internal clock frequency.
Waste of time. Do a search on this forum for confirmation.

Mike
duke.sir



Joined: 02 Feb 2014
Posts: 4
Location: cameroon

View user's profile Send private message

PostPosted: Mon Feb 03, 2014 1:16 pm     Reply with quote

Thanks to you all but the are some security measures on the following link you gave
https://drive.google.com/?tab=wo&authuser=0&urp=https://www.google.bg/?gws_rd%3Dcr%26ei%3DJwbdUriqFoHl4w#folders/0B_EYtdS7J5eKNGVqOVM5VlBFWW8 book. Refer to if - else conditions.

can you make it available in order means?
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 1:49 am     Reply with quote

Try this: https://drive.google.com/file/d/0B_EYtdS7J5eKZ1RaeEt4a2hlQnM/edit?usp=sharing

Also consider what Mike Walne says. Isis is not the most reliable tool for debugging.
_________________
A person who never made a mistake never tried anything new.
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