Проблемы С Памятью

11-05-2013, 11:13 От: admin Посмотрели: 1076
Здравствуйте.

не могли бы Вы подсказать, как посмотреть,где именно он пишет в некорректную облать памяти.




#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <inttypes.h>
#include "lcd_lib.h"
//define R2R port
#define R2RPORT PORTA
#define R2RDDR DDRA
//define button port and dedicated pins
#define BPORT PORTD
#define BPIN PIND
#define BDDR DDRD
#define DOWN 0//PORTD
#define LEFT 1//PORTD
#define START 2//PORTD
#define RIGHT 3//PORTD
#define UP 4//PORTD
//Define Highs Speed (HS) signal output
#define HSDDR DDRD
#define HSPORT PORTD
#define HS 5//PD5
//define eeprom addresses
#define EEMODE 0
#define EEFREQ1 1
#define EEFREQ2 2
#define EEFREQ3 3
#define EEDUTY 4
#define EEINIT E2END
#define RESOLUTION 0.095367431640625
#define MINFREQ 0//minimum frequency
#define MAXFREQ 65534//maximum DDS frequency
#define MN_No 5// number of menu items
//function prototypes
void delay1s(void);
void Timer2_Init(void);
void Timer2_Start(void);
void Timer2_Stop(void);
void Main_Init(void);
void Menu_Update(uint8_t);
void Freq_Update(void);
void Timer1_Start(uint8_t);
void Timer1_Stop(void);
void static inline Signal_OUT(const uint8_t *, uint8_t, uint8_t, uint8_t);
//adjust LCDsendChar() function for strema
static int LCDsendstream(char c, FILE *stream);
//----set output stream to LCD-------
static FILE lcd_str = FDEV_SETUP_STREAM(LCDsendstream, NULL, _FDEV_SETUP_WRITE);
//Menu Strings in flash
//menu 1
const uint8_t MN100[] PROGMEM=" exp \0";
//Array of pointers to menu strings stored in flash
const uint8_t *MENU[]={
MN100 //menu 1 string
};
//various LCD strings
const uint8_t MNON[] PROGMEM="ON \0";//ON
const uint8_t MNOFF[] PROGMEM="OFF\0";//OFF
const uint8_t NA[] PROGMEM=" NA \0";//Clear freq value
const uint8_t CLR[] PROGMEM=" \0";//Clear freq value
const uint8_t MNClrfreq[] PROGMEM=" \0";//Clear freq value
const uint8_t TOEEPROM[] PROGMEM="Saving Settings\0";//saving to eeprom
const uint8_t ONEMHZ[] PROGMEM=" 1MHz \0";//saving to eeprom
const uint8_t welcomeln1[] PROGMEM="AVR SIGNAL\0";
const uint8_t RND[] PROGMEM=" Random\0";
//variables to control TDA7313
struct signal{
volatile uint8_t mode; //signal
volatile uint8_t fr1; //Frequency [0..7]
volatile uint8_t fr2; //Frequency [8..15]
volatile int8_t fr3; //Frequency [16..31]
volatile uint32_t freq; //frequency value
volatile uint8_t flag; //if "0"generator is OFF, "1" - ON
volatile uint32_t acc; //accumulator
volatile uint8_t ON;
volatile uint8_t HSfreq; //high speed frequency [1...4Mhz]
volatile uint32_t deltafreq; //frequency step value
}SG;
//define signals
const uint8_t expwave[] __attribute__ ((section (".MySection1")))= //exp wave
{
0x00,0x09,0x12,0x1B,0x23,0x2c,0x34,0x3c,0x43,0x4B,0x52,0x59,0x60,0x67,0x6E,0x74,
0x7A,0x80,0x86,0x8C,0x91,0x97,0x9C,0xA1,0xA6,0xAA,0xAF,0xB3,0xB8,0xBC,0xC0,0xC3,
0xC7,0xCB,0xCE,0xD1,0xD4,0xD7,0xDA,0xDD,0xE0,0xE2,0xE4,0xE7,0xE9,0xEB,0xED,0xEF,
0xF0,0xF2,0xF3,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFE,0xFE,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xfd,0xfd,0xfc,0xfc,0xfb,0xfa,0xfa,
0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0,0xee,0xed,0xec,0xea,0xe9,0xe8,
0xe6,0xe5,0xe3,0xe2,0xe0,0xdf,0xdd,0xdb,0xda,0xd8,0xd6,0xd5,0xd3,0xd1,0xd0,0xce,
0xcc,0xca,0xc8,0xc7,0xc5,0xc3,0xc1,0xbf,0xbd,0xbb,0xba,0xb8,0xb6,0xb4,0xb2,0xb0,
0xae,0xac,0xaa,0xa8,0xa6,0xa4,0xa2,0xa1,0x9f,0x9d,0x9b,0x99,0x97,0x95,0x93,0x91,
0x8f,0x8e,0x8c,0x8a,0x88,0x86,0x84,0x82,0x80,0x7e,0x7d,0x7b,0x79,0x77,0x76,0x74,
0x72,0x70,0x6e,0x6d,0x6b,0x69,0x68,0x66,0x64,0x62,0x61,0x5f,0x5d,0x5c,0x5a,0x59,
0x57,0x55,0x54,0x52,0x51,0x4f,0x4e,0x4c,0x4b,0x49,0x48,0x46,0x45,0x44,0x42,0x41,
0x3f,0x3e,0x3d,0x3b,0x3a,0x39,0x37,0x36,0x35,0x34,0x31,0x30,0x2f,0x2e,0x2d,0x2b,
0x2a,0x29,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x20,0x1f,0x1e,0x1d,0x1c,
0x1b,0x1a,0x1a,0x19,0x18,0x17,0x16,0x15,0x15,0x14,0x13,0x12,0x11,0x11,0x10,0x0f,
0x0f,0x0e,0x0d,0x0d,0x0c,0x0b,0x0b,0x0a,0x09,0x09,0x08,0x08,0x07,0x07,0x06,0x06,
};

//array of pointers to signal tables
const uint8_t *SIGNALS[] ={
expwave
};
//adjust LCD stream fuinction to use with printf()
static int LCDsendstream(char c , FILE *stream)
{
LCDsendChar(c);
return 0;
}
//delay 1s
void delay1s(void)
{
uint8_t i;
for(i=0;i<100;i++)
{
_delay_ms(10);
}
}
//initialize Timer2 (used for button reading)
void Timer2_Init(void)
{
TCNT2=0x00;
sei();
}
//start timer2
void Timer2_Start(void)
{
TCCR2|=(1<<CS22)|(1<<CS21); //prescaller 256 ~122 interrupts/s
TIMSK|=(1<<TOV2);//Enable Timer0 Overflow interrupts
}
//stop timer 2
void Timer2_Stop(void)
{
TCCR0&=~((1<<CS22)|(1<<CS21)); //Stop timer0
TIMSK&=~(1<<TOV2);//Disable Timer0 Overflow interrupts
}
//Initial menu
//show initial signal and frequency
//generator is off
void Menu_Update(uint8_t on)
{
LCDclr();
CopyStringtoLCD(MENU[(SG.mode)], 0, 0 );
LCDGotoXY(0, 1);
if (SG.mode==6)
{
CopyStringtoLCD(CLR, 0, 1 );
LCDGotoXY(0, 1);
printf(" %5uHz", (uint16_t)SG.deltafreq);
}
if (SG.mode==7)
{
CopyStringtoLCD(CLR, 0, 1 );
CopyStringtoLCD(RND, 0, 1 );
}
if (SG.mode==8)
{
CopyStringtoLCD(CLR, 0, 1 );
LCDGotoXY(0, 1);
printf(" %5uMHz", SG.HSfreq);
}
if((SG.mode==0)||(SG.mode==1)||(SG.mode==2)||(SG.mode==3)||(SG.mode==4)||(SG.mode==5))
{
CopyStringtoLCD(CLR, 0, 1 );
LCDGotoXY(0, 1);
printf(" %5uHz", (uint16_t)SG.freq);
}
if (SG.mode!=6)
{
if(on==1)
CopyStringtoLCD(MNON, 13, 1 );
else
CopyStringtoLCD(MNOFF, 13, 1 );
}
}
//update frequency value on LCD menu - more smooth display
void Freq_Update(void)
{
if (SG.mode==6)
{
LCDGotoXY(0, 1);
printf(" %5uHz", (uint16_t)SG.deltafreq);
}
if (SG.mode==8)
{
//if HS signal
LCDGotoXY(0, 1);
printf(" %5uMHz", SG.HSfreq);
}
if((SG.mode==0)||(SG.mode==1)||(SG.mode==2)||(SG.mode==3)||(SG.mode==4)||(SG.mode==5))
{
LCDGotoXY(0, 1);
printf(" %5uHz", (uint16_t)SG.freq);
}
}
//External interrupt0 service routine
//used to stop DDS depending on active menu
//any generator is stopped by setting flag value to 0
//DDs generator which is inline ASM is stopped by setting
//CPHA bit in SPCR register
ISR(INT0_vect)
{
SG.flag=0;//set flag to stop generator
SPCR|=(1<<CPHA);//using CPHA bit as stop mark
//CopyStringtoLCD(MNOFF, 13, 1 );
SG.ON=0;//set off in LCD menu
loop_until_bit_is_set(BPIN, START);//wait for button release
}
//timer overflow interrupt service tourine
//checks all button status and if button is pressed
//value is updated
ISR(TIMER2_OVF_vect)
{
if (bit_is_clear(BPIN, UP))
//Button UP increments value which selects previous signal mode
//if first mode is reached - jumps to last
{
if (SG.mode==0)
{
SG.mode=MN_No-1;
}
else
{
SG.mode--;
}
//Display menu item
Menu_Update(SG.ON);
loop_until_bit_is_set(BPIN, UP);
}
if (bit_is_clear(BPIN, DOWN))
//Button Down decrements value which selects next signal mode
//if last mode is reached - jumps to first
{
if (SG.mode<(MN_No-1))
{
SG.mode++;
}
else
{
SG.mode=0;
}
//Display menu item
Menu_Update(SG.ON);
loop_until_bit_is_set(BPIN, DOWN);
}
if (bit_is_clear(BPIN, RIGHT))
//frequency increment
{
if(SG.mode==6)
{
if(SG.deltafreq==10000)
SG.deltafreq=1;
else
SG.deltafreq=(SG.deltafreq*10);
Freq_Update();
loop_until_bit_is_set(BPIN, RIGHT);
}
if (SG.mode==8)
{
//ifhigh speed signal
if(SG.HSfreq==8)
SG.HSfreq=1;
else
SG.HSfreq=(SG.HSfreq<<1);
Freq_Update();
loop_until_bit_is_set(BPIN, RIGHT);
}
if((SG.mode==0)||(SG.mode==1)||(SG.mode==2)||(SG.mode==3)||(SG.mode==4)||(SG.mode==5))
{
if ((0xFFFF-SG.freq)>=SG.deltafreq)
SG.freq+=SG.deltafreq;
Freq_Update();
uint8_t ii=0;
//press button and wait for long press (~0.5s)
do{
_delay_ms(2);
ii++;
}while((bit_is_clear(BPIN, RIGHT))&&(ii<=250));//wait for button release
if(ii>=250)
{
do{
if ((0xFFFF-SG.freq)>=SG.deltafreq)
SG.freq+=SG.deltafreq;
Freq_Update();
}while(bit_is_clear(BPIN, RIGHT));//wait for button release
}
}
}
if (bit_is_clear(BPIN, LEFT))
//frequency decrement
{
if(SG.mode==6)
{
if(SG.deltafreq==1)
SG.deltafreq=10000;
else
SG.deltafreq=(SG.deltafreq/10);
Freq_Update();
loop_until_bit_is_set(BPIN, LEFT);
}
if (SG.mode==8)
{
//ifhigh speed signal
if(SG.HSfreq==1)
SG.HSfreq=8;
else
SG.HSfreq=(SG.HSfreq>>1);
Freq_Update();
loop_until_bit_is_set(BPIN, LEFT);
}
if ((SG.mode==0)||(SG.mode==1)||(SG.mode==2)||(SG.mode==3)||(SG.mode==4)||(SG.mode==5))
{
if (SG.freq>=SG.deltafreq)
SG.freq-=SG.deltafreq;
Freq_Update();
uint8_t ii=0;
//press button and wait for long press (~0.5s)
do{
_delay_ms(2);
ii++;
}while((bit_is_clear(BPIN, LEFT))&&(ii<=250));//wait for button release
if(ii>=250)
{
do{
if (SG.freq>=SG.deltafreq)
SG.freq-=SG.deltafreq;
Freq_Update();
}while(bit_is_clear(BPIN, LEFT));//wait for button release
}
}
}
if (bit_is_clear(BPIN, START))
{
if(SG.mode!=6)
{
//saving last configuration
SG.fr1=(uint8_t)(SG.freq);
SG.fr2=(uint8_t)(SG.freq>>8);
SG.fr3=(uint8_t)(SG.freq>>16);
if (eeprom_read_byte((uint8_t*)EEMODE)!=SG.mode) eeprom_write_byte((uint8_t*)EEMODE,SG.mode);
if (eeprom_read_byte((uint8_t*)EEFREQ1)!=SG.fr1) eeprom_write_byte((uint8_t*)EEFREQ1,SG.fr1);
if (eeprom_read_byte((uint8_t*)EEFREQ2)!=SG.fr2) eeprom_write_byte((uint8_t*)EEFREQ2,SG.fr2);
if (eeprom_read_byte((uint8_t*)EEFREQ3)!=SG.fr3) eeprom_write_byte((uint8_t*)EEFREQ3,SG.fr3);
//Calculate frequency value from restored EEPROM values
SG.freq=(((uint32_t)(SG.fr3)<<16)|((uint32_t)(SG.fr2)<<8)|((uint32_t)(SG.fr1)));
//calculate accumulator value
SG.acc=SG.freq/RESOLUTION;
SG.flag=1;//set flag to start generator
SG.ON=1;//set ON on LCD menu
SPCR&=~(1<<CPHA);//clear CPHA bit in SPCR register to allow DDS
//Stop timer2 - menu inactive
Timer2_Stop();
//display ON on LCD
Menu_Update(SG.ON);
}
loop_until_bit_is_set(BPIN, START);//wait for button release
}
}
/*DDS signal generation function
Original idea is taken from
http://www.myplace.nu/avr/minidds/index.htm
small modification is made - added additional command which
checks if CPHA bit is set in SPCR register if yes - exit function
*/
void static inline Signal_OUT(const uint8_t *signal, uint8_t ad2, uint8_t ad1, uint8_t ad0)
{
asm volatile( "eor r18, r18 ;r18<-0" "\n\t"
"eor r19, r19 ;r19<-0" "\n\t"
"1:" "\n\t"
"add r18, %0 ;1 cycle" "\n\t"
"adc r19, %1 ;1 cycle" "\n\t"
"adc %A3, %2 ;1 cycle" "\n\t"
"lpm ;3 cycles" "\n\t"
"out %4, __tmp_reg__ ;1 cycle" "\n\t"
"sbis %5, 2 ;1 cycle if no skip" "\n\t"
"rjmp 1b ;2 cycles. Total 10 cycles" "\n\t"
:
:"r" (ad0),"r" (ad1),"r" (ad2),"e" (signal),"I" (_SFR_IO_ADDR(PORTA)), "I" (_SFR_IO_ADDR(SPCR))
:"r18", "r19"
);
}
void Timer1_Start(uint8_t FMHz)
{
switch(FMHz){
case 1:
//start high speed (1MHz) signal
OCR1A=7;
break;
case 2:
OCR1A=3;//2MHz
break;
case 4:
OCR1A=1;//4MHz
break;
case 8:
OCR1A=0;//8MHz
break;
default:
OCR1A=7;//defauls 1MHz
break;}
//Output compare toggles OC1A pin
TCCR1A=0x40;
//start timer without prescaler
TCCR1B=0b00001001;
}
void Timer1_Stop(void)
{
TCCR1B=0x00;//timer off
}
//main init function
void Main_Init(void)
{
//stderr = &lcd_str;
stdout = &lcd_str;
//--------init LCD----------
LCDinit();
LCDclr();
LCDcursorOFF();
//-------EEPROM initial values----------
if (eeprom_read_byte((uint8_t*)EEINIT)!='T')
{
eeprom_write_byte((uint8_t*)EEMODE,0x00);//initial mode 0 – OUT~~~~;
eeprom_write_byte((uint8_t*)EEFREQ1,0xE8);//initial frequency 1kHz
eeprom_write_byte((uint8_t*)EEFREQ2,0x03);
eeprom_write_byte((uint8_t*)EEFREQ3,0x00);
eeprom_write_byte((uint8_t*)EEINIT,'T');//marks once that eeprom init is done
//once this procedure is held, no more initialization is performed
}
//------restore last saved values from EEPROM------
SG.mode=eeprom_read_byte((uint8_t*)EEMODE);
SG.fr1=eeprom_read_byte((uint8_t*)EEFREQ1);
SG.fr2=eeprom_read_byte((uint8_t*)EEFREQ2);
SG.fr3=eeprom_read_byte((uint8_t*)EEFREQ3);
SG.freq=(((uint32_t)(SG.fr3)<<16)|((uint32_t)(SG.fr2)<<8)|((uint32_t)(SG.fr1)));
SG.acc=SG.freq/RESOLUTION;
SG.flag=0;
//default 1MHz HS signal freq
SG.HSfreq=1;
SG.deltafreq=100;
//------------init DDS output-----------
R2RPORT=0x00;//set initial zero values
R2RDDR=0xFF;//set A port as output
//-------------set ports pins for buttons----------
BDDR&=~(_BV(START)|_BV(UP)|_BV(DOWN)|_BV(RIGHT)|_BV(LEFT));
BPORT|=(_BV(START)|_BV(UP)|_BV(DOWN)|_BV(RIGHT)|_BV(LEFT));
//---------set ports pins for HS output---------
HSDDR|=_BV(HS);//configure as output
//-----------Menu init--------------
SG.ON=0;//default signal is off
Menu_Update(SG.ON);
//-----------Timer Init-------------
Timer2_Init();
//Start Timer with overflow interrupts
Timer2_Start();
}
int main(void)
{
//Initialize
Main_Init();
while(1)//infinite loop
{
if (SG.flag==1)
{
GICR|=(1<<INT0);//set external interrupt to enable stop
if (SG.mode==7)
{
//Noise
do
{
R2RPORT=rand();
}while(SG.flag==1);
//set signal level to 0
R2RPORT=0x00;
//display generator OFF
Menu_Update(SG.ON);
//stop external interrupt
GICR&=~(1<<INT0);
//start timer menu active
Timer2_Start();
}
/* else if (SG.mode==6)
{
//freq step
while((SG.flag==1))
{
//not implemented
CopyStringtoLCD(NA, 0, 1 );
}
//set signal level to 0
R2RPORT=0x00;
//display generator OFF
Menu_Update(SG.ON);
GICR&=~(1<<INT0);//|(1<<INT1);//stop external interrupt
//start timer menu active
Timer2_Start();
}*/
else if (SG.mode==8)
{
//High speed signal
Timer1_Start(SG.HSfreq);
while((SG.flag==1))
{
//not implemented
CopyStringtoLCD(MNON, 13, 1 );
}
Timer1_Stop();//timer off
//set HS pin to LOW
HSPORT&=~(1<<HS);
//display generator OFF
Menu_Update(SG.ON);
GICR&=~(1<<INT0);//|(1<<INT1);//stop external interrupt
//start timer menu active
Timer2_Start();
}
else
{
//start DDS
Signal_OUT(SIGNALS[SG.mode],
(uint8_t)((uint32_t)SG.acc>>16),
(uint8_t)((uint32_t)SG.acc>>8),
(uint8_t)SG.acc);
//set signal level to 0
R2RPORT=0x00;
//display generator OFF
Menu_Update(SG.ON);
GICR&=~(1<<INT0);//|(1<<INT1);//stop external interrupt
//start timer menu active
Timer2_Start();
}
}
}
return 0;
}



ошибка section .MySection1 loaded at [000016ce,000017cd] overlaps section .data loaded at [000016ce,000016f5]



Подскажите пожалуйста,где посмотреть, по какой причине он так записывает в память.

Гуглила, ничего толкого не нашла.

Заранее спасибо.
Раздел: Песочница или Вопрос-Ответ

Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться, либо войти на сайт под своим именем.

Обсудить на форуме


На момент добавления Проблемы С Памятью все ссылки были рабочие.
Все публикации статей, книг и журналов, представлены на этом сайте, исключительно для ознакомления,
авторские права на эти публикации принадлежат авторам статей, книг и издательствам журналов!
Подробно тут | Жалоба

Добавление комментария

Ваше имя:*
E-Mail:*
Текст:
Вопрос:
Решите уравнения x+2x=789
Ответ:*
Введите два слова, показанных на изображении:



Опрос

Ваши предпочтения в TRX


Одинарное преобразование
Двойное преобразование
Прямое преобразование
SDR
Другое
Мне всё равно

Календарь новостей
«    Апрель 2024    »
ПнВтСрЧтПтСбВс
1234567
891011121314
15161718192021
22232425262728
2930