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

TIMER problem

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



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

TIMER problem
PostPosted: Mon Jun 05, 2017 2:33 am     Reply with quote

Hi,
I would like to calculate time before push button B6.
My problem is when i push button B6 it will not give actual time in second.
Please help to solve this problem


Code:

#include <18F4550.h>
#DEVICE ADC=10
#fuses HSPLL,NOWDT,PROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN         
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#include <string.h>
#include <input.c>
#include <stdio.h>
#include <stdlib.h>
#include <usb_cdc.h>
#define INTS_PER_SECOND 91         // (48000000/(4*2*65536))



int8 v;      // A running seconds counter
int8 int_count;    // Number of interrupts left before a second has elapsed



#INT_RTCC                        // This function is called every time
void clock_isr() {                 // timer 1 overflows (65535->0), which is
                                   // approximately 91 times per second for
    if(--int_count==0) {           // this program.
      ++v;
      int_count = INTS_PER_SECOND;
    }
}



 
 
 
void main()
   {
      char c;
      unsigned char d;
      unsigned char key;


   usb_init_cs();
   


   while (TRUE)
         {
         usb_task();


            if (usb_cdc_kbhit())
               {
                 c=usb_cdc_getc();
                 if (c=='\n') {putc('\r'); putc('\n');}
                 if (c=='\r') {putc('\r'); putc('\n');}

                                       

                 while(true)
                 
                     {
                  ART:

                  d = usb_cdc_getc();

                         if(d=='C')   // push C
                             {
                                while (key!=32) // push SPACE BAR to stop
                                   {

                                 if(usb_cdc_kbhit())
                                   {key=usb_cdc_getc();}

                                       {
                                             {
                                       
                                                setup_timer_0(RTCC_DIV_2|RTCC_INTERNAL);                                         
                                                set_timer0(0);
                                                enable_interrupts(INT_RTCC);
                                                enable_interrupts(GLOBAL);
                                             
                                                {
                                                    int_count = INTS_PER_SECOND;
                                                     v = 0;

                                                   while(input(PIN_B6));    //Push Button B6
                                                    {
                                                     v=get_timer0();
                                                     printf(usb_cdc_putc,"%u seconds\r", v);
                                                    }
                                                }
                                             }                               

                                       }
                                   

                                   } key=0; // to initialize 'key' not as SPACE BAR
                             }

                     }
               }       
         }             
}                     

alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Mon Jun 05, 2017 4:43 am     Reply with quote

Code:
v=get_timer0();  ???????????
Are you sure. Doesn't v already contains the second value you are looking for.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Mon Jun 05, 2017 7:03 pm     Reply with quote

Hi alan,
Thanks, you are right !
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