+ Reply to Thread
Page 1 of 2
1 2 Last
Results 1 to 15 of 20

Thread: CCS compiler help

  1. #1
    khwoo Newbie
    Join Date
    Jul 2009
    Posts
    4

    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.


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  3. #3
    BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent
    Join Date
    Dec 2005
    Location
    Vancouver Canada
    Posts
    1,186

    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.

  4. #4
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

  5. #5
    BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent
    Join Date
    Dec 2005
    Location
    Vancouver Canada
    Posts
    1,186

    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.

  6. #6
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

  7. #7
    khwoo Newbie
    Join Date
    Jul 2009
    Posts
    4

    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?

  8. #8
    BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent
    Join Date
    Dec 2005
    Location
    Vancouver Canada
    Posts
    1,186

    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.

  9. #9
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

  10. #10
    BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent
    Join Date
    Dec 2005
    Location
    Vancouver Canada
    Posts
    1,186

    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.

  11. #11
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

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

  12. #12
    BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent BeeBop Excellent
    Join Date
    Dec 2005
    Location
    Vancouver Canada
    Posts
    1,186

    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.

  13. #13
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

  14. #14
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,696

    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.

  15. #15
    Banned millwood Good millwood Good
    Join Date
    Jun 2009
    Posts
    191

    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.

+ Reply to Thread
Page 1 of 2
1 2 Last

Similar Threads

  1. C compiler
    By lasvegasmale31 in forum Micro Controllers
    Replies: 3
    Latest: 22nd January 2009, 09:09 PM
  2. What is a Compiler?
    By Suraj143 in forum Micro Controllers
    Replies: 33
    Latest: 27th April 2008, 07:13 PM
  3. IAR Compiler
    By mtkee2003 in forum Micro Controllers
    Replies: 0
    Latest: 19th November 2006, 06:41 AM
  4. Compiler
    By gimmix in forum Micro Controllers
    Replies: 13
    Latest: 14th May 2005, 09:50 PM
  5. about pic compiler
    By Navid in forum Micro Controllers
    Replies: 3
    Latest: 31st January 2005, 03:11 AM

Tags for this Thread