Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

CCS compiler help

Status
Not open for further replies.

khwoo

New Member
:confused:I am doing a programming on a rpm (revolution per minute) counter for a toy car. When an IR sensor signal input to the PIC, interrupt will be enabled and timer 0 will started to count the rpm and display the value in 16x2 lcd.
The below code shows about the interrupt and timer0:
Code:
#use delay (clock = 20000000) 
#include <LCD.C> 
#define INTS_PER_MINUTE 153   // (40000000/(4*256*256)) 

BYTE minutes;      // A running minutes counter 
BYTE int_count;    // Number of interrupts left before a minute has elapsed 

#int_rtcc                          // This function is called every time 
void clock_isr() {                 // the RTCC (timer0) overflows (255->0). 
   BYTE start; 
   int_count=INTS_PER_MINUTE;    
   set_timer0(0); 
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); 
   enable_interrupts(GLOBAL); 
   enable_interrupts(INT_EXT);      // For this program this is apx 153 times 
    
   if(--int_count==0) {             // per minute. 
   ++minutes; 
   int_count=INTS_PER_MINUTE; 
    } 
 }

And the to display the rpm value per minute in lcd, the code is shown below:
Code:
void main ( void ) 
{ 
   char display [ 4 ]; 

   // Initialization 
   input(PIN_B0); 
   output_high(PIN_A0); 
   output_high(PIN_A1); 
   output_high(PIN_A2); 
   output_high(PIN_A3); 
   output_low(PIN_A4); 
   output_low(PIN_A5); 

   lcd_init(); 

   lcd_gotoxy (1,1); 
   lcd_putc ("RPM:" +minutes ); 
}
The above code are combined together but nothing shown in the lcd.
Can anyone correct my mistakes? Thanks. :confused:
 
You can't just have main ending. Try adding an infinite loop around your code.

Code:
void main ( void ) 
{ 
   char display [ 4 ]; 

   // Initialization 
   input(PIN_B0); 
   output_high(PIN_A0); 
   output_high(PIN_A1); 
   output_high(PIN_A2); 
   output_high(PIN_A3); 
   output_low(PIN_A4); 
   output_low(PIN_A5); 

   lcd_init(); 
   [COLOR="Red"]while(1){[/COLOR]
      lcd_gotoxy (1,1); 
      lcd_putc ("RPM:" +minutes ); 
   [COLOR="red"]}[/COLOR]
}

I also don't see where you initialise the interrupt. However, I've not used the CCS compiler and so don't know how it should be set up.

Mike.
 
:confused:I am doing a programming on a rpm (revolution per minute) counter for a toy car. When an IR sensor signal input to the PIC, interrupt will be enabled and timer 0 will started to count the rpm and display the value in 16x2 lcd.
The below code shows about the interrupt and timer0:
Code:
#use delay (clock = 20000000) 
#include <LCD.C> 
#define INTS_PER_MINUTE 153   // (40000000/(4*256*256)) 

BYTE minutes;      // A running minutes counter 
BYTE int_count;    // Number of interrupts left before a minute has elapsed 

#int_rtcc                          // This function is called every time 
void clock_isr() {                 // the RTCC (timer0) overflows (255->0). 
   BYTE start; 
   int_count=INTS_PER_MINUTE;    
   set_timer0(0); 
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); 
   enable_interrupts(GLOBAL); 
   enable_interrupts(INT_EXT);      // For this program this is apx 153 times 
    
   if(--int_count==0) {             // per minute. 
   ++minutes; 
   int_count=INTS_PER_MINUTE; 
    } 
 }
And the to display the rpm value per minute in lcd, the code is shown below:
Code:
void main ( void ) 
{ 
   char display [ 4 ]; 

   // Initialization 
   input(PIN_B0); 
   output_high(PIN_A0); 
   output_high(PIN_A1); 
   output_high(PIN_A2); 
   output_high(PIN_A3); 
   output_low(PIN_A4); 
   output_low(PIN_A5); 

   lcd_init(); 

   lcd_gotoxy (1,1); 
   lcd_putc ("RPM:" +minutes ); 
}
The above code are combined together but nothing shown in the lcd.
Can anyone correct my mistakes? Thanks. :confused:

I think Mike is right about putting in an endless loop.

Also, I think you need to move the call to enable interrupts to your init:
(perhaps the calls to set up the timers too?)


Code:
#use delay (clock = 20000000) 
#include <LCD.C> 
#define INTS_PER_MINUTE 153   // (40000000/(4*256*256)) 

BYTE minutes;      // A running minutes counter 
BYTE int_count;    // Number of interrupts left before a minute has elapsed 

#int_rtcc                          // This function is called every time 
void clock_isr() {                 // the RTCC (timer0) overflows (255->0). 
   BYTE start; 
   int_count=INTS_PER_MINUTE;    
    
   if(--int_count==0) {             // per minute. 
   ++minutes; 
   int_count=INTS_PER_MINUTE; 
    } 
 }
And the to display the rpm value per minute in lcd, the code is shown below:
Code:
void main ( void ) 
{ 
   char display [ 4 ]; 

   // Initialization 
   input(PIN_B0); 
   output_high(PIN_A0); 
   output_high(PIN_A1); 
   output_high(PIN_A2); 
   output_high(PIN_A3); 
   output_low(PIN_A4); 
   output_low(PIN_A5); 

   lcd_init(); 
   set_timer0(0); 
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); 
   enable_interrupts(GLOBAL); 
    enable_interrupts(INT_EXT);     // For this program this is apx 153 times 
   while(1) {
      lcd_gotoxy (1,1); 
      lcd_putc ("RPM:" +minutes ); 
   } // end while
}

You should look in your CCS examples folder. I think there should be an example of using the capture module in there... That would be useful for this project.
 
Last edited:
I would suggest that you divide the project down to two parts, one to read the rpm, and another to display the reading on the LCD. so work on one at a time and make sure that both of them are working before you join them together.

not knowing much about your lcd, it is tough to know if the right sequences are used to initialize it and to display information it. you will have to consult the datasheet or find sample programs on the net for your controller or similar controllers.

You can't just have main ending.

yes, you can.
 
I would suggest that you divide the project down to two parts, one to read the rpm, and another to display the reading on the LCD. so work on one at a time and make sure that both of them are working before you join them together.

not knowing much about your lcd, it is tough to know if the right sequences are used to initialize it and to display information it. you will have to consult the datasheet or find sample programs on the net for your controller or similar controllers.



yes, you can.


In the case of the CCS compiler the PIC then goes to sleep. I think he would want the LCD to be updated regularly, so he needs the endless loop.
 
his problem right now isn't how the main() functions. His problem is somewhere else so that's where he needs to focus.

As to main(), yes, if you don't have an infinite loop, the function will terminate and what the cpu does is up to its configuration and you do typically do something in a loop there.

However, that's not to say that you have to have an endless loop. for example, you can set up everything in interrupts and let it go from there.

again, not having an endless loop in main() is the least of his problems. While it is NOT advisable to terminate the main() function, it is NOT something that you have to do either.
 
I think Mike is right about putting in an endless loop.

Also, I think you need to move the call to enable interrupts to your init:
(perhaps the calls to set up the timers too?)


Code:
#use delay (clock = 20000000) 
#include <LCD.C> 
#define INTS_PER_MINUTE 153   // (40000000/(4*256*256)) 

BYTE minutes;      // A running minutes counter 
BYTE int_count;    // Number of interrupts left before a minute has elapsed 

#int_rtcc                          // This function is called every time 
void clock_isr() {                 // the RTCC (timer0) overflows (255->0). 
   BYTE start; 
   int_count=INTS_PER_MINUTE;    
    
   if(--int_count==0) {             // per minute. 
   ++minutes; 
   int_count=INTS_PER_MINUTE; 
    } 
 }
And the to display the rpm value per minute in lcd, the code is shown below:
Code:
void main ( void ) 
{ 
   char display [ 4 ]; 

   // Initialization 
   input(PIN_B0); 
   output_high(PIN_A0); 
   output_high(PIN_A1); 
   output_high(PIN_A2); 
   output_high(PIN_A3); 
   output_low(PIN_A4); 
   output_low(PIN_A5); 

   lcd_init(); 
   set_timer0(0); 
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT); 
   enable_interrupts(GLOBAL); 
    enable_interrupts(INT_EXT);     // For this program this is apx 153 times 
   while(1) {
      lcd_gotoxy (1,1); 
      lcd_putc ("RPM:" +minutes ); 
   } // end while
}

You should look in your CCS examples folder. I think there should be an example of using the capture module in there... That would be useful for this project.


Thanks for all the replies... But after trying the beebop code, it still cannot function... hmm.. Why?
 
Thanks for all the replies... But after trying the beebop code, it still cannot function... hmm.. Why?

Well, can you put text on the screen with your LCD_putc function? Please verify that this works first. :)

EDIT: just get rid of every thing except the calls to lcd_putc and try to print a simple line to your LCD.
Code:
void main ( void ) 
{ 
    lcd_init(); 
    while(1) {
        lcd_gotoxy (1,1); 
        lcd_putc ("test" ); 
    } // end while
}
 
Last edited:
kwoo, if you go down the list of threads here, you will see one initiated by atomsoft on driving graphics lcd (nokia 7110). that threads has source code for most of the functions you would need for a glcd.

while that was on ARM chip / using serial interface, the basic building blocks and structure still apply.

you do need to go back to the datasheet of your lcd and understand how to reset the lcd and write data / command to it.
 
If you read his first post, he is using a character LCD and the CCS C compiler, not C18. As such, he is probably using the built-in functions of CCS, which are VERY different from C18. That chip isn't an ARM it is a PIC 18F2525.

khwoo, can you post your connections to the LCD from the micro?
 
Last edited:
if you read my post, i answered that before you wrote the above.
:confused::confused::confused:


What are you talking about? I'll say it again:
That chip isn't an ARM it is a PIC 18F2525.

You said:
kwoo, if you go down the list of threads here, you will see one initiated by atomsoft on driving graphics lcd (nokia 7110). that threads has source code for most of the functions you would need for a glcd.

while that was on ARM chip / using serial interface, the basic building blocks and structure still apply.
 
BeeBop,

I was going to post an almost identical reply - not GLCD or Arm - but was reminded of someones signature here.

It goes something like,

If you argue with idiots, they will drag you down to their level and beat you with experience.

Mike.
 
this actually reminds me of the history of that package. It was originally written in ccs (3.3 I think). I ported it to PIC using picc-lite, and then to arm using mdk.

that's the beauty of writing programs in a high-level language like C.
 
Thanks Mike!:)

It seems like these forums are, indeed, deteriorating quite quickly. :(

I wonder if he had another handle on here which was recently banned? :p

Robert

BeeBop,

I was going to post an almost identical reply - not GLCD or Arm - but was reminded of someones signature here.

It goes something like,

If you argue with idiots, they will drag you down to their level and beat you with experience.

Mike.
 
Thanks Mike!:)

It seems like these forums are, indeed, deteriorating quite quickly. :(

I wonder if he had another handle on here which was recently banned? :p

Robert

when you start to call others idiots just because they disagree with you, or question their intent, the discussion will deteriorate quickly, as this one has shown quite convincingly.
 
Please note, I did not call anyone names. I wouldn't do that. It's not allowed.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top