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

Undefined Identifier TMR1H

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



Joined: 23 Mar 2006
Posts: 9

View user's profile Send private message

Undefined Identifier TMR1H
PostPosted: Sun Mar 25, 2007 5:30 pm     Reply with quote

Hi, I'm trying to use timer1 to read the frequency of an incoming square wave signal. However, when I try to read the TMR1H and TMR1L registers, I get the error "Undefined Identifier TMR1H". Shouldn't I be able to read this? Here's my code for the project. A lot of this can be ignored as it's simply outputting to an LCD. Focus on the code highlighted by "***********".

Note: I made a similar thread earlier about a different problem when I was using a different method to execute this. I'm not trying a different technique for Frequency measurement.

Code:
#include "18F458.H"
#fuses HS,NOWDT,NOPUT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <string.h>
#include <stdlib.h>
#use fast_io(D)


// Global Variables
int i;
int16 speed = 50;
char mystr[10];
int overflow_cnt =0;
unsigned long int wheel_counts, wheel_test, last_counts, delta_counts, sensor_freq;
/*unsigned long int end_time = 0, start_time = 0;
unsigned long int pulse_ticks = 0;
unsigned long int actual_speed = 0;
unsigned int32 cnt = 0;*/
int b1 = 0;
int b2 = 0;
int screenChanged = 1;

//sends a data byte to the LCD
void send_data(char e)
{
   output_bit(PIN_C4, 1);  //RS is set high so that the LCD is in Data Mode

   output_B(e);
   delay_us (20);  //Delays for one microsecond
   output_bit(PIN_C5, 1);
   delay_us (20);  //Delays for one microsecond to give the LCD time to read the data
   output_bit(PIN_C5, 0);  //enable is low.  brought high to put on data
   delay_us (20);
}

//sends a command to the LCD
void send_command(char f)
{
   output_bit(PIN_C4, 0);  //RS is set low so that the LCD is in Command Mode

   output_B(f); //turns on display and adds cursor, underline, and cursor blink
   delay_us (20);
   output_bit(PIN_C5, 1);  //trows enable low to send command to LCD
   delay_us (20);  //Delays for one microsecond to give the LCD time to read the data
   output_bit(PIN_C5, 0);  //enable is brought back to high
   delay_us (20);
}

//***************************************
#int_TIMER2
TIMER2_isr() //interupt for timer1 overflow
{

   //makes sure the received count is the most recent
   wheel_counts = TMR1H << 8;
   wheel_counts += TMR1L;
   wheel_test = TMR1H << 8;
   wheel_test = TMR1L;
   if (wheel_counts != wheel_test)
   {
      wheel_counts = TMR1H << 8;
      wheel_counts += TMR1L;
   }
   
   delta_counts = (int32) (wheel_counts - last_counts);
   sensor_freq = 1000 * delta_counts;  //frequency of input signal
   
   last_counts = wheel_counts;
}

//*********************************************

void main()
{
   //initiates the LCD
   delay_ms(500);
   output_bit(PIN_C5, 0);  //enable is low.  brought high to put on data
   send_command(0x0C);
   send_command(0x38);
   send_command(0x01);

   //activate and setup LCD
   delay_ms (100);

   //send to LCD "Hello World"
   send_data('W');
   send_data('e');
   send_data('l');
   send_data('c');
   send_data('o');
   send_data('m');
   send_data('e');
   delay_ms(2000); //2 second delay
   send_command(0x01); //clears the screen
   delay_ms(5);

//************************************
   //initialization of timer1 and timer2
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DIV_BY_4, 125, 10);  //Timer2 interrupt every 1 ms

   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_EXT);
   enable_interrupts(global);
//***********************************


   while(1)
   {
      //checks to see if button 1 is pressed (speed up)
      if(!input(PIN_C0) && b1 == 1)
      {
         if (speed < 2000)
            speed += 50;
         b1=0;
         screenChanged = 1;
      }
      if(input(PIN_C0))
         b1 = 1;

      //checks to see if button 2 is pressed (speed down)
      if(!input(PIN_C1) && b2 == 1)
      {
         if (speed > 50)
            speed -= 50;
         b2 = 0;
         screenChanged = 1;
      }
      if(input(PIN_C1))
         b2 = 1;

      //makes sure the screen get's refreshed if no button is pushed
      ++cnt;
      if(cnt > 1000)
      {
         screenChanged = 1;
         cnt = 0;
      }

      //outputs the speed to the LCD
      if (screenChanged == 1)
      {
         send_command(0x80);  //clears the display

         sprintf(mystr, "%lu", speed); //converts the int to a character string

         i = 0;  //loop that writes the number to the LCD
         while(mystr[i] != NULL)
         {
            send_data(mystr[i]);
            i++;
         }

         send_data('R');
         send_data('P');
         send_data('M');
         send_data(' ');
         send_data(' ');
         send_data(' ');
         send_data(' ');


         send_command(0xC0); //shift writing position to second line

         sprintf(mystr, "%lu", sensor_freq); //converts the int to a character string

         i = 0;  //loop that writes the number to the LCD
         while(mystr[i] != NULL)
         {
            send_data(mystr[i]);
            i++;
         }

         send_data('R');
         send_data('P');
         send_data('M');
         send_data(' ');
         send_data(' ');
         send_data(' ');
         send_data(' ');

         screenChanged = 0;
      }

   }  //end while

} // end main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 25, 2007 5:50 pm     Reply with quote

Quote:

However, when I try to read the TMR1H and TMR1L registers, I get the
error "Undefined Identifier TMR1H". Shouldn't I be able to read this ?

The compiler doesn't know what those symbols are. You need to tell it.
Here, someone has typed in all the register declaration statements.
You can save it out as 18F458_regs.h and #include it in your program.
http://www.ccsinfo.com/forum/viewtopic.php?t=14755
SimpleAsPossible



Joined: 19 Jun 2004
Posts: 21

View user's profile Send private message

Generally speaking, for stuff like this...
PostPosted: Sun Mar 25, 2007 5:55 pm     Reply with quote

Go to 41159D.pdf (for PIC18F458), go to page 47 (page 49 of the PDF file) and look at Table 4.1 Special Function Register Map, TMR1H is FCFh and TMR1L is FCEh. Add this near the top of your file:

Code:
#byte TMR1H = 0xFCF
#byte TMR1L = 0xFCE


And you'll be off and running.

Obviously, if someone has written a register header file, you can use it instead. It's just useful to know how to make it yourself too.
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