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

Set TMR1H and TMR1L in Pic 16F877A
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

Set TMR1H and TMR1L in Pic 16F877A
PostPosted: Tue Mar 17, 2009 4:21 pm     Reply with quote

Hi!

how do i set a PIC16F877A TMR1H = 0x21 and TMR1L = 0x18 i tried with #byte TMR1H=0x21 and #byte TMR1L=0x18 but it seems not work
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 4:36 pm     Reply with quote

Use the CCS function. That's what it's there for. It accurately creates
the code to load Timer1:
Code:

... set_timer1(0x2118);
000F:  MOVLW  21
0010:  BCF    STATUS.RP0
0011:  MOVWF  TMR1H
0012:  MOVLW  18
0013:  MOVWF  TMR1L


Also, #byte is used to tell the compiler the address of the register
(or other memory identifier name). #byte is not used to load the
register.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 5:14 pm     Reply with quote

Hi!

setting:
set_timer1 (0x2118);

.................... set_timer1(0x2118);
*
0035: MOVLW 21
0036: MOVWF 0F
0037: MOVLW 18
0038: MOVWF 0E

not TMR1H and TMR1L
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 5:29 pm     Reply with quote

Download the 16F877A data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf
Look in this section:
Quote:
FIGURE 2-3: PIC16F876A/877A REGISTER FILE MAP

It shows the register addresses:
Quote:
TMR1L 0E
TMR1H 0F
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 5:36 pm     Reply with quote

Hi!

thanks, because it appears in your program instead of 0F and 0E TMR1H and TMR1L?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 5:57 pm     Reply with quote

In MPLAB, you can set the List File Format to:
Quote:

- Normal CCS format
- MPLAB format
- Symbolic format

This is done in the Project / Build Options menu.

I used the Symbolic format mode.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 6:41 pm     Reply with quote

Hi!
This instruction is placed in the interrupt function? or you can put in the main?
Example:
Code:

#int_TIMER1                       
void TIMER1_isr()
{                     
set_timer1(0x7F81);   
                           
Ticker -= 65536;
                                                                                         
if ( Ticker < 65536 )   {
 
    Ticker = TIMER1_FREQUENCY;
   
     seconds++;                           
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 7:02 pm     Reply with quote

Are you asking about this function:
Code:
set_timer1()

Put it anywhere in your program.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 7:50 pm     Reply with quote

Hi!
Code:
#include "C:\Programmi\PICC\Projects\interrupt ccs.h"   
 
#define green_led pin_a5
#define yellow_led pin_b4             
#define red_led pin_b5       
                       
//RTC variables
#define XTAL_FREQUENCY  20000000
#define TIMER1_FREQUENCY (XTAL_FREQUENCY /4)     
int32 Ticker;       
int8 Seconds=0;     
                                       
//    Initialize RTC
 void Initialize_RTC(void)
{                           

  Ticker = TIMER1_FREQUENCY;                 
  setup_timer_1( T1_INTERNAL | T1_DIV_BY_2 );
   enable_interrupts( INT_TIMER1 );           
                                                       
       
}     


#int_TIMER1                       
void TIMER1_isr()
{                     
 set_timer1(0x7F81);                     //setting TMR1H e TMR1L    76 cicli  1000,008ms 
                                            //13,158ms pari a 75,99939Hz
 
 Ticker -= 65536;                        // Decrement ticker by clocks per interrupt                                                                       
 if ( Ticker < 65536 )                    // If second has expired    dopo 76 cicli quando Ticker =19264
  {
    Ticker = TIMER1_FREQUENCY;
    seconds++;                            //   Increment number of seconds   
     
                                         
     
   }
}


void main()                         
{
 int8 prev_second;
 int8 minutes=0;
                   
                                         
  Initialize_RTC();
  enable_interrupts( GLOBAL );         
  output_low (green_led), output_high (red_led); 
                                                 
  // loop forever                                         
  while(true)
{                                                                     
                                                               
   // Toggle output every second 
   if (seconds != prev_second) 
    {                     
      prev_second = seconds;     
      output_toggle (green_led);
                         
      if(Seconds == 60)
    {
      Seconds=0;
      minutes++;   
      output_toggle (yellow_led);     
    }
   
      if(minutes == 60) 
  {
      minutes = 0;
      output_toggle (red_led);           
  }
                         
                       
    }
         
  }
     
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 17, 2009 7:58 pm     Reply with quote

You keep posting more and more code. I don't know what you want.
I don't want to do this. I'm done.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 5:47 pm     Reply with quote

The posted code is a modified version of Neutone's Real Time Clock (RTC) code found at several places in this forum. Here a link to the version in the Code Library

Same as PCM Programmer I have no clue as to what the question is, but from the modifications made to the original source my guess is the clock is running too fast.
My suggestion: study the modifications you made. You made two vital changes and both are wrong.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Sat Mar 21, 2009 11:24 am     Reply with quote

Hi!

his is the code that I changed and I'm using with an error of 1 second in 24 hours :

Code:
#define green_led pin_a5
#define yellow_led pin_b4             
#define red_led pin_b5       

                                         
#define XTAL_FREQUENCY  20000000
int8 Ticker;       
int8 Seconds=0;     
       

                                         
void Initialize_RTC(void)
{                           

  Ticker = 10;
  setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );
  enable_interrupts( INT_TIMER1 );            // Start RTC
                                                                 
}     


#int_TIMER1                       
void TIMER1_isr()
{                     
      set_timer1(0x0BDC);                                                             
     Ticker -= 1;
     if ( Ticker == 0 )
 {
    Ticker = 10;
    seconds++;                                                                         
     
  }

 }

 

void main()                         
{
 //int8 prev_second;
 int8 minutes=0;
                   
                                         
  Initialize_RTC();
  enable_interrupts( GLOBAL );         
  output_low (green_led), output_high (red_led), output_high (yellow_led); 
                                               
                                                 
                                         
  while(true)
 
     if (Ticker > 5)
     {           
      output_low (green_led);                               
     }
     else
     {
     output_high (green_led);               
     }
                                                               
      if(Seconds == 60)  {
      Seconds=0;
      minutes++;   
      output_toggle (yellow_led);     
  }
      if(minutes == 60)    {
      minutes = 0;
      output_toggle (red_led);           
      }                                                             
  }
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Mar 22, 2009 6:53 pm     Reply with quote

volcane wrote:
his is the code that I changed and I'm using with an error of 1 second in 24 hours :
And your question is....?

Interrupts take some time to execute (all working registers have to be saved first). Depending on processor model and compiler version number this takes about 20 to 50 instruction times. Accuracy can be increased by changing the line:
Code:
      set_timer1(0x0BDC);
to:
Code:
      set_timer1( get_timer1() + 0x0BDC);
This removes any (variable) delay from the the time your interrupt code is being executed.
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 10:38 am     Reply with quote

ckielstra wrote:

Code:
      set_timer1(0x0BDC);
to:
Code:
      set_timer1( get_timer1() + 0x0BDC);
This removes any (variable) delay from the the time your interrupt code is being executed.


thanks i try
volcane



Joined: 23 Feb 2008
Posts: 29

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 10:40 am     Reply with quote

PCM programmer wrote:
In MPLAB, you can set the List File Format to:
Quote:

- Normal CCS format
- MPLAB format
- Symbolic format

This is done in the Project / Build Options menu.

I used the Symbolic format mode.


which version of MPLAB and CCS compiler uses?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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