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

what to do, I can't understand

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



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

what to do, I can't understand
PostPosted: Fri Oct 07, 2011 4:32 am     Reply with quote

Hello all
I'm new in pic programming.

I want to do:

When push switch 1 pressed, corresponding output enable and the timer run for mentioned time and then output off. Here I used a variable 'p' to assign the timing parameter.

When push switch 2 pressed, corresponding output enable and the timer run for another mentioned time and then output off. Here I used a variable 'q' to assign the timing parameter.

I don't want to use delay because in delay time other instruction of program isn't executed.

Please help and give me suggestion.

Here is my code.

Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <flex_LCD420.c>   
#int_timer0
   
int16 p,q;
 timer0_isr()
{
p++;
q++;
   }

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_4);
   enable_interrupts (INT_TIMER0);
   enable_interrupts(global);
   set_timer0(6);


lcd_init();

// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(50);


   printf(lcd_putc, "\f  PIC Experiment");
   printf(lcd_putc, "\n--------------------");
   printf(lcd_putc, "\nNice Day ");
   
while(1)
  {
   if (!input(pin_D0))    // switch 1
   {output_high(pin_C0);}
   if (p==1000)
   {output_low(pin_C0);
   p=0;}
   
   if (!input(pin_D1))        // switch 2
   {output_high(pin_C1);}   
  if (q==500)
   {output_low(pin_C1);
  q=0;}

 
   
  }
}
temtronic



Joined: 01 Jul 2010
Posts: 9164
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 5:01 am     Reply with quote

First off you don't say what value or range the delays are. Anything from nanoseconds to days is possible with this PIC! So more information is required.

Also since this high level language allows for long variable names, I suggest something more descriptive in place of 'p' and 'q'. It'll help you and others, days or weeks from now, when you're working on this project.

You need some kind of 'debouncing' routine on those 'switches'! Unless you're using expensive electronic switches as mechanical ones are 'noisey'!

Concurrent countdown timers are easy to implement, several ways to do it. Microchip has several examples in their 'Designing for Dollars' applications handbook. As well, CCS kindly supplies example code in the 'examples' folder, that would be useful to you.

And of course the Internet is FULL of code that will do the project you describe.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 12:54 pm     Reply with quote

You have another thread back in August, where you are working on the
same problem:
http://www.ccsinfo.com/forum/viewtopic.php?t=35429

In that thread, you were given a link that shows how to do simple multi-tasking:
http://www.ccsinfo.com/forum/viewtopic.php?t=35429
Here is another one:
http://www.ccsinfo.com/forum/viewtopic.php?t=17189


The problem is that your skill level is still at a "beginner". You must be
at least at an intermediate level to understand this type of program.

You need to keep learning C for a few months, so you can understand it,
or find someone else to do your coding. I don't want to do your project
for you.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Fri Oct 07, 2011 2:31 pm     Reply with quote

PCM programmer wrote:
You have another thread back in August, where you are working on the
same problem:
http://www.ccsinfo.com/forum/viewtopic.php?t=35429



The problem is that your skill level is still at a "beginner". You must be
at least at an intermediate level to understand this type of program.



Dear PCM programmer , above mentioned link the suspected isn't me.
But its true that I'm a beginner.

in this forum, I never expect that someone write my code. I just expect some examples or guidelines.

I'm living in a small town in the country named Bangladesh, nobody here that can help me.

Only some downloaded books and internet and this forum only the way.

I start to learn c by this book "Programming 8-bit PIC Microcontrollers in C
by Martin P.Bates "

If you have a good suggestion on book/tutorial for the beginner like me please help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Oct 07, 2011 2:48 pm     Reply with quote

OK, then the first thing you need to do is to fix this:
Quote:

#int_timer0

int16 p,q;
timer0_isr()
{
p++;
q++;
}

You can't put anything between the #int_xxxx statment and the isr
function. If you do that, the isr code will not be compiled (and the
compiler will not tell you this). You can see this in the .LST file, shown
below. Notice there is no ASM code generated:
Code:

.................... #int_timer0 
....................     
.................... int16 p,q; 
....................  timer0_isr() 
.................... { 
.................... p++; 
.................... q++; 
....................    } 
.................... 
.................... void main() 
.................... {
 



This is the correct way:
Code:

int16 p,q;

#int_timer0
timer0_isr()
{
p++;
q++;
}

Compile it as above, and notice that you now get ASM code generated:
Code:

.................... int16 p,q; 
.................... 
.................... #int_timer0 
.................... timer0_isr() 
.................... { 
.................... p++; 
*
0037:  INCF   28,F
0038:  BTFSC  003.2
0039:  INCF   p+1,F
.................... q++; 
003A:  INCF   2A,F
003B:  BTFSC  003.2
003C:  INCF   q+1,F
.................... } 
.................... 
003D:  BCF    00B.2
003E:  BCF    00A.3
003F:  BCF    00A.4
0040:  GOTO   01B
.................... void main() 
.................... { 


So you need to fix that part of your program, and then you can continue
with the program development.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sat Oct 08, 2011 7:53 am     Reply with quote

Dear PCM programmer

Thanks a lot for your kind help and guideline.

I start to learn c by this book "Programming 8-bit PIC Microcontrollers in C
by Martin P.Bates".

Do you have have any good suggestion on book/tutorial for the beginner like me please help.

If so, please provide me some link.

Thank you once again.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 08, 2011 11:59 am     Reply with quote

Here are some threads on books:
http://www.ccsinfo.com/forum/viewtopic.php?t=27839
http://www.ccsinfo.com/forum/viewtopic.php?t=33272

This post has many links to online tutorials on C and CCS and PICs:
http://www.ccsinfo.com/forum/viewtopic.php?t=46384&start=3
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 09, 2011 5:50 am     Reply with quote

thanks a lot
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 09, 2011 8:35 am     Reply with quote

Now the code is working but I suspect a problem while I simulate it with Proteus 7.7.

I suspect timing is not accurate as I want to do start the timer at the point that is noted in the code.

what to do:
Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#include <flex_LCD420.c>   
 
int16 p,q;
#int_timer0
 timer0_isr()
{
p++;
q++;
   }

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_4);
   enable_interrupts (INT_TIMER0);
   enable_interrupts(global);
   set_timer0(6);


lcd_init();

// Clear the LCD.
printf(lcd_putc, "\f");
delay_ms(50);


   printf(lcd_putc, "\f  PIC Experiment");
   printf(lcd_putc, "\n--------------------");
   printf(lcd_putc, "\nNice Day ");
   
while(1)
  {
   if (!input(pin_D0))    // switch 1
   {output_high(pin_C0);} // I want to start the timer at this point
   if (p==1000)
   {output_low(pin_C0);
   p=0;}
   
   if (!input(pin_D1))        // switch 2
   {output_high(pin_C1);}   // I want to start the timer at this point
  if (q==500)
   {output_low(pin_C1);
  q=0;}

 
   
  }
}
temtronic



Joined: 01 Jul 2010
Posts: 9164
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 09, 2011 9:49 am     Reply with quote

You have two and only Two options.

1) Hack into Proteus and FIX one of the many bugs and errors that it has....

2) Get RID of PROTEUS and use real hardware !

I suspect that option #2 is your only choice.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Oct 09, 2011 1:55 pm     Reply with quote

Thanks temtronic

Actually I suspect there is a bug in my code not in Proteus.

Anyway, in my code is it really timing accurately as per my desire .

Maybe I mistake something.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 09, 2011 5:20 pm     Reply with quote

My advice is to make a more simple program. Just use one button and
one LED. Get that working reliably. Then add more features later.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Oct 10, 2011 12:29 am     Reply with quote

Quote:
I want to do start the timer at the point that is noted in the code.

But you don't. Starting the timer would involve resetting the timer variable.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Mon Oct 10, 2011 3:42 am     Reply with quote

Many thanks FvM for your valued suggestion.

You are right.

Now its working.
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