Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

declaring 512 byte array for PIC

Status
Not open for further replies.

redsuns

New Member
hi

i need to declare a 512 byte array for my code because i need to get those data from a camera and send it to a FAT16 SD card

when i was going through the code, it gives me no definition that matches the type of section "udata_filename_0" when i was compiling it

it works fine if the total array declare is less than 256 byte
i opened the .asm file and the udata use percentage is not half yet
so how can i define a 512 byte array?
i just write a simple code to test how to declare this array but fail
i try to compile this code with 2 different compiler MPLAB IDE with MPLAB C18 and sdcc

the error msg is like this for sdcc
warning:relocation of section "udata_a_1"fail,relocating to a shared memory location
error:linker script has no definition that matches the type of section "udata_a_1"

and MPLAB C18 gives
Error - section '.udata_a.o' can not fit the section. Section '.udata_a.o' length=0x00000206

//file include
#include <p18f2620.h>
#include <stdio.h>
//***************************

//***********define************
#define TX PORTCbits.RC6
#define RX PORTCbits.RC7
//*****************************

//*****global variable**********
unsigned char rx_buffer[6];
unsigned char tx_buffer[512];
//******************************

//start coding
void main()
{
//register mapping for asynchronous transmit
TRISCbits.TRISC0 = 1; //setting pin as RX pin
INTCON |= 0xC0; //enable interrupts
RCSTAbits.SPEN = 1; //enable SPEN
TXSTAbits.SYNC = 0; //clear SYNC bits for asynchronous mode
TXSTAbits.BRGH = 1;//clock configure
PIE1 = 0x38;//set interrupt for EUSART & SPI
TXSTAbits.TXEN = 1; //transmit enable , trigger TXIF
RCSTAbits.CREN = 1; // enables receiver
SPBRG = 21; //57.6K baud rate
//end
}
 
Last edited:
You need to copy the linker script into your project folder and change it to,
Code:
// File: 18f2620.lkr
// Sample linker script for the PIC18F2620 processor

LIBPATH .

FILES c018i.o
FILES clib.lib
FILES p18f2620.lib

CODEPAGE   NAME=page       START=0x0               END=0xFFFF
CODEPAGE   NAME=idlocs     START=0x200000          END=0x200007       PROTECTED
CODEPAGE   NAME=config     START=0x300000          END=0x30000D       PROTECTED
CODEPAGE   NAME=devid      START=0x3FFFFE          END=0x3FFFFF       PROTECTED
CODEPAGE   NAME=eedata     START=0xF00000          END=0xF003FF       PROTECTED

ACCESSBANK NAME=accessram  START=0x0            END=0x7F
DATABANK   NAME=gpr0       START=0x80           END=0xFF
DATABANK   NAME=gpr1       START=0x100          END=0x1FF
DATABANK   NAME=gpr2       START=0x200          END=0x2FF
DATABANK   NAME=gpr3       START=0x300          END=0x3FF
DATABANK   NAME=gpr4       START=0x400          END=0x4FF
DATABANK   NAME=gpr5       START=0x500          END=0x5FF
DATABANK   NAME=gpr6       START=0x600          END=0x6FF
DATABANK   NAME=gpr7       START=0x700          END=0x7FF
DATABANK   NAME=gpr8       START=0x800          END=0x8FF
DATABANK   NAME=gpr9       START=0x900          END=0x9FF
DATABANK   NAME=gpr10      START=0xA00          END=0xAFF
DATABANK   NAME=gpr11      START=0xB00          END=0xBFF
[COLOR="red"]//DATABANK   NAME=gpr12      START=0xC00          END=0xCFF
//DATABANK   NAME=gpr13      START=0xD00          END=0xDFF
DATABANK   NAME=bigarray   START=0xC00          END=0xDFF[/COLOR]
DATABANK   NAME=gpr14      START=0xE00          END=0xEFF
DATABANK   NAME=gpr15      START=0xF00          END=0xF7F
ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED

SECTION    NAME=CONFIG     ROM=config

STACK SIZE=0x100 RAM=gpr14

And then change your program to,
Code:
//file include
#include <p18f2620.h>
#include <stdio.h>
//***************************

//***********define************
#define TX PORTCbits.RC6 
#define RX PORTCbits.RC7
//*****************************

//*****global variable**********
[COLOR="red"]#pragma udata
unsigned char rx_buffer[6];
#pragma udata bigarray
unsigned char tx_buffer[512];[/COLOR]
//******************************
#pragma code

//start coding
void main()
{
    //register mapping for asynchronous transmit
    TRISCbits.TRISC0 = 1; //setting pin as RX pin
    INTCON |= 0xC0; //enable interrupts
    RCSTAbits.SPEN = 1; //enable SPEN
    TXSTAbits.SYNC = 0; //clear SYNC bits for asynchronous mode
    TXSTAbits.BRGH = 1;//clock configure
    PIE1 = 0x38;//set interrupt for EUSART & SPI
    TXSTAbits.TXEN = 1; //transmit enable , trigger TXIF
    RCSTAbits.CREN = 1; // enables receiver
    SPBRG = 21; //57.6K baud rate
//end
}

Make sure your project is using the modified linker script and all should work.

I chose banks 12 and 13 as bank 14 is used for the stack.

Mike.
 
Last edited:
it really does work , thank you
if i need 2 512 array then i can combine 2 more stack together with another name and pragma that name to use it is it?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top