View previous topic :: View next topic |
Author |
Message |
TEK66TIM
Joined: 03 Nov 2004 Posts: 13
|
18f252 array problem |
Posted: Thu Feb 10, 2005 5:19 pm |
|
|
Hi, having a problem with arrays on the 18f252 part with compiler version
PCW 3.115 IDE version 3.21. The array reads back fine untill element 244
after 244 it reads back junk. I have tried the #locate directive and it does not work at all. I'm new to posting code to the forum so I hope this works,any help would be great.
Thanks in advance
Tim
Code: |
#include <18f252.h>
#include <stdlib.h>
#fuses NOLVP, NOWDT, EC_IO
#use delay (clock=40000000)
#use rs232 (baud=9600, xmit=PIN_A6, rcv=PIN_C7)
#define DEBUG PIN_A6
#define CHSEL PIN_C6
#define N_STATUS PIN_A0
#define CONF_DONE PIN_A1
#define INIT_DONE PIN_A2
#define DATA_0 PIN_A3
#define N_CONFIG PIN_A4
#define DCLK PIN_A5
// functions
void blink_led ();
void read_ser_port ();
// variables
int8 data_array_1 [300];
int1 eof_flag = 0;
// constants
// mem locations
//#locate data_array_1 = 0x100 // tried this un-commented, array reads back junk. commented out it reads back fine until element 244
void main (void)
{
int8 data;
output_float (N_STATUS); // tri-state pins for PLD programming interface
output_float (CONF_DONE);
output_float (INIT_DONE);
output_float (DATA_0);
output_float (N_CONFIG);
output_float (DCLK);
output_high (CHSEL); // de-select serial eeprom
delay_ms (1000); // let PCB settle after powerup
blink_led (); // blink LEDS to let me know it's alive
blink_led ();
blink_led ();
blink_led ();
blink_led ();
do
{
data = getc ();
if (data == 0x01)
{
read_ser_port ();
}
}
while (1); // loop to get serial port handshake
}
void read_ser_port () // this should read 270 bytes from serial port then print them back to the computer
{
int16 count;
do
{
putc (0xAA);
for (count = 0; count < 270; count ++)
{
data_array_1 [count] = getc ();
}
for (count = 0; count < 270; count ++)
{
printf ("count = %Lu data = %x \n\r", count, data_array_1 [count]);
}
}
while (1);
}
void blink_led () // blinks LED
{
output_low (DEBUG);
delay_ms (200);
output_high (DEBUG);
delay_ms (200);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 11, 2005 1:29 am |
|
|
Quote: | Hi, having a problem with arrays on the 18f252 part with compiler
version PCW 3.115 |
That's a fairly old version. It could easily have a bug in that area.
If you can't upgrade, then maybe you could break it up into two
smaller arrays. This might fix it. |
|
|
TEK66TIM
Joined: 03 Nov 2004 Posts: 13
|
|
Posted: Fri Feb 11, 2005 7:43 am |
|
|
Funny thing, I tried this ( two 135 byte arrays ) each array ran fine for the first 110 bytes, then produced junk. Then I tried two 100 byte arrays and one 70 byte array. the first array was fine the second and third produced junk again. |
|
|
|