![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
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;
}
}
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 );
}
Can anyone correct my mistakes? Thanks. | |
| |
| | #2 |
|
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 );
}
}
Mike. | |
| |
| | #3 | |
| Quote:
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;
}
}
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
}
Last edited by BeeBop; 1st July 2009 at 03:22 PM. | ||
| |
| | #4 | |
|
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:
| ||
| |
| | #5 | |
| Quote:
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 |
|
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 | |
| Quote:
Thanks for all the replies... But after trying the beebop code, it still cannot function... hmm.. Why? | ||
| |
| | #8 | |
| Quote:
![]() 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 |
|
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 |
|
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 |
| | |
| |
| | #12 | ||
| Quote:
![]() ![]() ![]() What are you talking about? I'll say it again: You said: Quote:
| |||
| |
| | #13 |
| | |
| |
| | #14 |
|
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 |
|
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. | |
| |
|
| 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 |