|
|
View previous topic :: View next topic |
Author |
Message |
kevin
Joined: 08 Sep 2003 Posts: 6 Location: salina,ks
|
Program does not work properly if it is over 2048 bytes |
Posted: Sun Jan 20, 2002 2:10 am |
|
|
Hi
I'm new to programming PICs and have got this stupid problem. I'm using the following:
MBPLAB v5.2
Compiler - PIC C v3.045
Pic Chip - PIC16F877
Real Time Clock - Philips PCF8563
I have got a timer chip that creates an interrupt on pin RB0. There is an 'external interrupt' routine in the code. The timer is set to trigger every 10ms. The interrupt function calls a function that checks the status of a ports pins.
In Main(), there is a loop that detects key presses over RS232 and echoes the character back to the screen. I am using Terminal for this. I am using the function KBHIT to detect if a character has been sent before printing it back out.
If the compiled code is less than 2048 bytes the program works fine but if it exceeds 2048 bytes then KBHIT does not work. Depending on the size of my program other things also do not work. The following is a the main parts of my code:
#include <16F877.H>
#device *=16
#include <stdlib.h>
#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#ID CHECKSUM
#ZERO_RAM
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
#use I2C(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
#define RTC_ADDR 0xa2
#use DELAY(CLOCK=19660800)
#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)
#define WORD unsigned long
#define BOOL short
void setup_timer(void);
void clear_timer(void);
void scan_io(void);
void scan_io2(void);
#INT_EXT
timer_interrupt()
{
disable_interrupts(INT_EXT);
// calls to dummy functions
scan_io();
scan_io2();
clear_timer();
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
}
// ******** MAIN ********
void main()
{
char c;
set_tris_a(0xff);
ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
setup_timer();
do
{
if (kbhit())
{
c = getc();
printf("\%c", c);
}
} while (TRUE);
}
// ******** SETUP TIMER ********
void setup_timer(void)
{
// Enable timer interrupt
i2c_start();
i2c_write(RTC_ADDR);
i2c_write(0x01);
i2c_write(0x01);
i2c_stop();
// timer source clock 4096 Hz - 0x80
i2c_start();
i2c_write(RTC_ADDR);
i2c_write(0x0E);
i2c_write(0x80);
i2c_stop();
// countdown 41 units - 0x29
// countdown time = units/Hz
i2c_start();
i2c_write(RTC_ADDR);
i2c_write(0x0F);
i2c_write(0x29);
i2c_stop();
}
// ******** CLEAR TIMER ********
void clear_timer(void)
{
// clear timer
i2c_start();
i2c_write(RTC_ADDR);
i2c_write(0x01);
i2c_write(0x01);
i2c_stop();
}
I would be very grateful for any help
Cheers
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 2111 |
|
|
Peter H Anderson Guest
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Sun Jan 20, 2002 9:18 am |
|
|
My experience has been that if a function is called only once, it will be compiled in-line. This may give you one enormous main() that exceeds the 2048 byte limit.
You can force the compiler to compile the functions separately by using the #separate directive.
For example;
#separate void setup_timer(void);
#separate void clear_timer(void);
#separate void scan_io(void);
#separate void scan_io2(void);
Peter H. Anderson, <a href="http://www.phanderson.com" TARGET="_blank">http://www.phanderson.com</a>
:=Hi
:=
:=I'm new to programming PICs and have got this stupid problem. I'm using the following:
:=
:=MBPLAB v5.2
:=Compiler - PIC C v3.045
:=Pic Chip - PIC16F877
:=Real Time Clock - Philips PCF8563
:=
:=I have got a timer chip that creates an interrupt on pin RB0. There is an 'external interrupt' routine in the code. The timer is set to trigger every 10ms. The interrupt function calls a function that checks the status of a ports pins.
:=
:=In Main(), there is a loop that detects key presses over RS232 and echoes the character back to the screen. I am using Terminal for this. I am using the function KBHIT to detect if a character has been sent before printing it back out.
:=
:=
:=If the compiled code is less than 2048 bytes the program works fine but if it exceeds 2048 bytes then KBHIT does not work. Depending on the size of my program other things also do not work. The following is a the main parts of my code:
:=
:=
:=#include <16F877.H>
:=#device *=16
:=#include <stdlib.h>
:=
:=#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=#ID CHECKSUM
:=#ZERO_RAM
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=#use fast_io(D)
:=#use fast_io(E)
:=
:=#use I2C(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
:=#define RTC_ADDR 0xa2
:=#use DELAY(CLOCK=19660800)
:=#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)
:=#define WORD unsigned long
:=#define BOOL short
:=
:=void setup_timer(void);
:=void clear_timer(void);
:=void scan_io(void);
:=void scan_io2(void);
:=
:=#INT_EXT
:=timer_interrupt()
:={
:=
:= disable_interrupts(INT_EXT);
:=
:= // calls to dummy functions
:= scan_io();
:= scan_io2();
:=
:= clear_timer();
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:=
:=}
:=
:=// ******** MAIN ********
:=void main()
:={
:=char c;
:=
:= set_tris_a(0xff);
:= ext_int_edge(H_TO_L);
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:= setup_timer();
:=
:= do
:= {
:= if (kbhit())
:= {
:= c = getc();
:= printf("\%c", c);
:= }
:= } while (TRUE);
:=}
:=
:=
:=// ******** SETUP TIMER ********
:=void setup_timer(void)
:={
:=
:= // Enable timer interrupt
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=
:= // timer source clock 4096 Hz - 0x80
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0E);
:= i2c_write(0x80);
:= i2c_stop();
:=
:= // countdown 41 units - 0x29
:= // countdown time = units/Hz
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0F);
:= i2c_write(0x29);
:= i2c_stop();
:=
:=}
:=
:=// ******** CLEAR TIMER ********
:=void clear_timer(void)
:={
:=
:= // clear timer
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=}
:=
:=I would be very grateful for any help
:=
:=Cheers
:=
:=Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 2114 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Sun Jan 20, 2002 1:43 pm |
|
|
:=Hi
:=If the compiled code is less than 2048 bytes the program works fine but if it exceeds 2048 bytes then KBHIT does not work. Depending on the size of my program other things also do not work.
This sounds like it might be a compiler bug, but before
deciding that's the case, I'd try a few other things.
For example, when you say KBHIT does not work, it could
be that it works, but the PIC is locked up somewhere else
in the code. It may not be getting to the region where
KBHIT is.
First, comment out all these fast_io statements.
Let the compiler handle the TRIS registers.
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=#use fast_io(D)
:=#use fast_io(E)
2nd, remove the FAST option from the following line.
Just temporarily, run the i2c at low speed.
:=#use I2C(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
In the following ISR code, remove the calls to
disable and enable INT_EXT. The compiler does
that automatically. Also remove the call to enable
GLOBAL interrupts. That's handled in hardware, when
the PIC executes the RETFIE instruction, at the end
of the CCS interrupt handler. By putting it in here
ahead of time, effectively, you're trying to do nested
interrupts, when they're not supported by the rest of
the CCS code. So that could be a problem.
:=#INT_EXT
:=timer_interrupt()
:={
:= disable_interrupts(INT_EXT);
:= // calls to dummy functions
:= scan_io();
:= scan_io2();
:= clear_timer();
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:=
:=}
:=// ******** MAIN ********
:=void main()
:={
:=char c;
Since I suggested commenting out the Fast_io statements,
you should also comment out the set_tris_a() statement below.
Let the compiler handle it.
:= set_tris_a(0xff);
:= ext_int_edge(H_TO_L);
Here, you're enabling interrupts from an external device
before you've initialized the device. You should change
it so the call to setup_timer() is done first.
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:= setup_timer();
:=
:= do
:= {
:= if (kbhit())
:= {
:= c = getc();
:= printf("\%c", c);
:= }
:= } while (TRUE);
:=}
:=
I didn't check the rest of it, because the net is
running too slowly for me to download the PCF8563 data sheet.
___________________________
This message was ported from CCS's old forum
Original Post ID: 2121 |
|
|
krugerrc Guest
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Mon Jan 21, 2002 3:04 am |
|
|
I think I had the same type of problem...
I could fix it with the following line:
#device =*
This tells the compiler to use 16 bit address pointers (I think)
Hope it helps....
Regards
:=Hi
:=
:=I'm new to programming PICs and have got this stupid problem. I'm using the following:
:=
:=MBPLAB v5.2
:=Compiler - PIC C v3.045
:=Pic Chip - PIC16F877
:=Real Time Clock - Philips PCF8563
:=
:=I have got a timer chip that creates an interrupt on pin RB0. There is an 'external interrupt' routine in the code. The timer is set to trigger every 10ms. The interrupt function calls a function that checks the status of a ports pins.
:=
:=In Main(), there is a loop that detects key presses over RS232 and echoes the character back to the screen. I am using Terminal for this. I am using the function KBHIT to detect if a character has been sent before printing it back out.
:=
:=
:=If the compiled code is less than 2048 bytes the program works fine but if it exceeds 2048 bytes then KBHIT does not work. Depending on the size of my program other things also do not work. The following is a the main parts of my code:
:=
:=
:=#include <16F877.H>
:=#device *=16
:=#include <stdlib.h>
:=
:=#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=#ID CHECKSUM
:=#ZERO_RAM
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=#use fast_io(D)
:=#use fast_io(E)
:=
:=#use I2C(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
:=#define RTC_ADDR 0xa2
:=#use DELAY(CLOCK=19660800)
:=#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)
:=#define WORD unsigned long
:=#define BOOL short
:=
:=void setup_timer(void);
:=void clear_timer(void);
:=void scan_io(void);
:=void scan_io2(void);
:=
:=#INT_EXT
:=timer_interrupt()
:={
:=
:= disable_interrupts(INT_EXT);
:=
:= // calls to dummy functions
:= scan_io();
:= scan_io2();
:=
:= clear_timer();
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:=
:=}
:=
:=// ******** MAIN ********
:=void main()
:={
:=char c;
:=
:= set_tris_a(0xff);
:= ext_int_edge(H_TO_L);
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL);
:= setup_timer();
:=
:= do
:= {
:= if (kbhit())
:= {
:= c = getc();
:= printf("\%c", c);
:= }
:= } while (TRUE);
:=}
:=
:=
:=// ******** SETUP TIMER ********
:=void setup_timer(void)
:={
:=
:= // Enable timer interrupt
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=
:= // timer source clock 4096 Hz - 0x80
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0E);
:= i2c_write(0x80);
:= i2c_stop();
:=
:= // countdown 41 units - 0x29
:= // countdown time = units/Hz
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0F);
:= i2c_write(0x29);
:= i2c_stop();
:=
:=}
:=
:=// ******** CLEAR TIMER ********
:=void clear_timer(void)
:={
:=
:= // clear timer
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=}
:=
:=I would be very grateful for any help
:=
:=Cheers
:=
:=Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 2131 |
|
|
RT Guest
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Mon Jan 21, 2002 7:55 am |
|
|
Kevin,
I had this same exact problem. CCS thought it was a compiler bug, but its not. It's a problem with your ISRs. You only need one enable_interrupts(Global); statement in your entire program. From that point on, the Global Interrupt Enable bit will always be set. In order to re-enable your interrupts, simply use enable_interrupts(INT_EXT); without the re-enable of the GIE bit. Give this a try and hopefully it will work.
Rick
:=#include <16F877.H>
:=#device *=16
:=#include <stdlib.h>
:=
:=#FUSES HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
:=#ID CHECKSUM
:=#ZERO_RAM
:=#use fast_io(A)
:=#use fast_io(B)
:=#use fast_io(C)
:=#use fast_io(D)
:=#use fast_io(E)
:=
:=#use I2C(MASTER, SDA=PIN_C4, SCL=PIN_C3, FAST)
:=#define RTC_ADDR 0xa2
:=#use DELAY(CLOCK=19660800)
:=#use RS232 (BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)
:=#define WORD unsigned long
:=#define BOOL short
:=
:=void setup_timer(void);
:=void clear_timer(void);
:=void scan_io(void);
:=void scan_io2(void);
:=
:=#INT_EXT
:=timer_interrupt()
:={
:=
:= disable_interrupts(INT_EXT);
:=
:= // calls to dummy functions
:= scan_io();
:= scan_io2();
:=
:= clear_timer();
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL); //Comment out
:=
:=}
:=
:=// ******** MAIN ********
:=void main()
:={
:=char c;
:=
:= set_tris_a(0xff);
:= ext_int_edge(H_TO_L);
:= enable_interrupts(INT_EXT);
:= enable_interrupts(GLOBAL); //Leave this
:= setup_timer();
:=
:= do
:= {
:= if (kbhit())
:= {
:= c = getc();
:= printf("\%c", c);
:= }
:= } while (TRUE);
:=}
:=
:=
:=// ******** SETUP TIMER ********
:=void setup_timer(void)
:={
:=
:= // Enable timer interrupt
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=
:= // timer source clock 4096 Hz - 0x80
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0E);
:= i2c_write(0x80);
:= i2c_stop();
:=
:= // countdown 41 units - 0x29
:= // countdown time = units/Hz
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x0F);
:= i2c_write(0x29);
:= i2c_stop();
:=
:=}
:=
:=// ******** CLEAR TIMER ********
:=void clear_timer(void)
:={
:=
:= // clear timer
:= i2c_start();
:= i2c_write(RTC_ADDR);
:= i2c_write(0x01);
:= i2c_write(0x01);
:= i2c_stop();
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 2137 |
|
|
kevin
Joined: 08 Sep 2003 Posts: 6 Location: salina,ks
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Tue Jan 22, 2002 2:24 pm |
|
|
Rick
Tried your suggestion and it worked!
Cheers
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 2158 |
|
|
kevin
Joined: 08 Sep 2003 Posts: 6 Location: salina,ks
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Tue Jan 22, 2002 2:27 pm |
|
|
Thanks for your help. The problem was the
enable_interrupts(GLOBAL) in the interrupt function. I commented it out and it worked fine.
Cheers
Kevin
___________________________
This message was ported from CCS's old forum
Original Post ID: 2159 |
|
|
Laurent chouinard Guest
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Thu Oct 03, 2002 12:50 pm |
|
|
Sir, you just saved me a whole freaking lot of hours wasted on this problem! I so happen to have just crossed the 2048KB barrier myself, and was caught with this exact same problem from there on. After a while of having no idea what the problem could be, I came here to the forums and ran a couple searches, and found this thread. Tried your tirck of only_one_global_interrupt and BAM, it works )
Thanks again!
PS: Weird, i've had this problem when i crossed the 96 BYTES barrier oh my ram. This one i lost several days trying to find the causes... finally i changed the way I handle interrupts, and it worked.
PPS: This compiler/microchip has weird stuff going on when you mess with the interrupts register bits.
___________________________
This message was ported from CCS's old forum
Original Post ID: 7393 |
|
|
Hontat Guest
|
Re: Program does not work properly if it is over 2048 bytes |
Posted: Fri Nov 01, 2002 4:09 pm |
|
|
Hi,
I am experiencing the same problem when I cross the 96 byte barrier on my ram. The interrupt handler just messes up and does not return.
What was your trick for handling the interrupts to avoid this problem?
Thanks.
HT
:=Sir, you just saved me a whole freaking lot of hours wasted on this problem! I so happen to have just crossed the 2048KB barrier myself, and was caught with this exact same problem from there on. After a while of having no idea what the problem could be, I came here to the forums and ran a couple searches, and found this thread. Tried your tirck of only_one_global_interrupt and BAM, it works <img src="http://www.ccsinfo.com/pix/forum/smile.gif" border="0">)
:=
:=Thanks again!
:=
:=PS: Weird, i've had this problem when i crossed the 96 BYTES barrier oh my ram. This one i lost several days trying to find the causes... finally i changed the way I handle interrupts, and it worked.
:=
:=PPS: This compiler/microchip has weird stuff going on when you mess with the interrupts register bits.
___________________________
This message was ported from CCS's old forum
Original Post ID: 8409 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|