Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 1st July 2009, 02:24 PM   #1
Default CCS compiler help

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.
khwoo is offline  
Old 1st July 2009, 02:57 PM   #2
Default

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(); 
   while(1){
      lcd_gotoxy (1,1); 
      lcd_putc ("RPM:" +minutes ); 
   }
}
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.
Pommie is offline  
Old 1st July 2009, 03:13 PM   #3
Default

Quote:
Originally Posted by khwoo View Post
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.
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 by BeeBop; 1st July 2009 at 03:22 PM.
BeeBop is online now  
Old 1st July 2009, 03:13 PM   #4
Default

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.

Quote:
You can't just have main ending.
yes, you can.
millwood is offline  
Old 1st July 2009, 03:20 PM   #5
Default

Quote:
Originally Posted by millwood View Post
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.
BeeBop is online now  
Old 1st July 2009, 03:32 PM   #6
Default

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.
millwood is offline  
Old 1st July 2009, 04:07 PM   #7
Default

Quote:
Originally Posted by BeeBop View Post
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?
khwoo is offline  
Old 1st July 2009, 04:11 PM   #8
Default

Quote:
Originally Posted by khwoo View Post
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 by BeeBop; 1st July 2009 at 04:16 PM.
BeeBop is online now  
Old 1st July 2009, 04:30 PM   #9
Default

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.
millwood is offline  
Old 1st July 2009, 04:42 PM   #10
Default

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 by BeeBop; 1st July 2009 at 04:44 PM.
BeeBop is online now  
Old 1st July 2009, 05:19 PM   #11
Default

Quote:
Originally Posted by BeeBop View Post
That chip isn't an ARM it is a PIC 18F2525.
if you read my post, i answered that before you wrote the above.

Quote:
while that was on ARM chip / using serial interface, the basic building blocks and structure still apply.
millwood is offline  
Old 1st July 2009, 05:29 PM   #12
Default

Quote:
Originally Posted by millwood View Post
if you read my post, i answered that before you wrote the above.



What are you talking about? I'll say it again:
Quote:
Originally Posted by BeeBop View Post

That chip isn't an ARM it is a PIC 18F2525.
You said:
Quote:
Originally Posted by millwood View Post
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 is online now  
Old 1st July 2009, 05:32 PM   #13
Default

Quote:
Originally Posted by BeeBop View Post



What are you talking about? I'll say it again:
please read that thread and your confusion will be all gone.
millwood is offline  
Old 1st July 2009, 05:37 PM   #14
Default

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.
Pommie is offline  
Old 1st July 2009, 05:39 PM   #15
Default

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.
millwood is offline  
Reply

Tags
ccs, compiler

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
C compiler lasvegasmale31 Micro Controllers 3 22nd January 2009 09:09 PM
What is a Compiler? Suraj143 Micro Controllers 33 27th April 2008 07:13 PM
IAR Compiler mtkee2003 Micro Controllers 0 19th November 2006 06:41 AM
Compiler gimmix Micro Controllers 13 14th May 2005 09:50 PM
about pic compiler Navid Micro Controllers 3 31st January 2005 03:11 AM



All times are GMT. The time now is 09:37 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker