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
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: 9199
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