# CCS compiler help

Status
Not open for further replies.

#### khwoo

##### New Member
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.

#### Pommie

##### Well-Known Member
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.

#### BeeBop

##### Active Member
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:

#### millwood

##### Banned
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.

#### BeeBop

##### Active Member
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.

#### millwood

##### Banned
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.

#### khwoo

##### New Member
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?

#### BeeBop

##### Active Member
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:

#### millwood

##### Banned
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.

#### BeeBop

##### Active Member
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:

#### millwood

##### Banned
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.

#### BeeBop

##### Active Member
if you read my post, i answered that before you wrote the above.

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.

#### millwood

##### Banned

What are you talking about? I'll say it again:

#### Pommie

##### Well-Known Member
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.

#### millwood

##### Banned
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

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

Mike.

a better way to say is that only idiots will call others idiots because they disagree with him.

#### BeeBop

##### Active Member
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?

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.

#### millwood

##### Banned
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?

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.

#### Pommie

##### Well-Known Member
Please note, I did not call anyone names. I wouldn't do that. It's not allowed.

Mike.

#### BeeBop

##### Active Member
No one is calling anyone names, nike6

Status
Not open for further replies.

Replies
17
Views
14K
Replies
2
Views
2K
Replies
5
Views
2K
Replies
6
Views
5K
Replies
4
Views
3K