Mithun_K_Das
Advanced Member level 3
- Joined
- Apr 24, 2010
- Messages
- 899
- Helped
- 24
- Reputation
- 48
- Reaction score
- 26
- Trophy points
- 1,318
- Location
- Dhaka, Bangladesh, Bangladesh
- Activity points
- 8,254
There is no error or fault here, but I need to find a way to reduce the memory consumption of the following code. If you have any suggestions please suggest.
MCU: PIC16F690, 8bit. Compiler: mikroC pro for PIC v7.6.0
This block is consuming 544 bytes of ROM. How can I reduce a little from here? Other parts are saturated but I need to add some in another part.
All strings [str_xyz] are kept as const char[]; delay(xyz) is simple delay function.
Also in this block how can I reduce some memory consumption?
MCU: PIC16F690, 8bit. Compiler: mikroC pro for PIC v7.6.0
This block is consuming 544 bytes of ROM. How can I reduce a little from here? Other parts are saturated but I need to add some in another part.
All strings [str_xyz] are kept as const char[]; delay(xyz) is simple delay function.
C++:
void edit_parameters(short mode)
{
switch (mode)
{
case 0:
Lcd_COut(1,5,str_temp);
temp_set_point1 = EEPROM_Read(temp_address0)*100+EEPROM_Read(temp_address1)*10+EEPROM_Read(temp_address2);
if(!plus)
{
if(temp_set_point1<400)temp_set_point1++;//50.0'C
else temp_set_point1=400;
buzzer=1;
}
if(!minus)
{
if(temp_set_point1>0)temp_set_point1--;
else temp_set_point1 = 0;
buzzer=1;
}
EEPROM_Write(temp_address0,(temp_set_point1/100)%10); while(WR_bit);
EEPROM_Write(temp_address1,(temp_set_point1/10)%10); while(WR_bit);
EEPROM_Write(temp_address2,(temp_set_point1/1)%10); while(WR_bit);
temp_set_point1 = EEPROM_Read(temp_address0)*100+EEPROM_Read(temp_address1)*10+EEPROM_Read(temp_address2);
temp_setpoint = 700 + temp_set_point1;
display_temp(2,0,temp_setpoint);
delay(150);
buzzer=0;
break;
case 1:
Lcd_COut(1,5,str_on);
Lcd_COut(1,9,str_time);
on_time = EEPROM_Read(on_time_address);
if(!plus)
{
if(on_time<255)on_time++;
else on_time=255;
buzzer=1;
}
if(!minus)
{
if(on_time>1)on_time--;
else on_time=1;
buzzer=1;
}
on_time_minute = (int)(on_time/60);
on_time_second = on_time-(on_time_minute*60);
disp_time(2,1,on_time_minute,on_time_second);
Lcd_COut(2,10,str_mm_ss);
EEPROM_Write(on_time_address,on_time);
while(WR_bit);
delay(150);
buzzer=0;
break;
case 2:
Lcd_COut(1,5,str_off);
Lcd_COut(1,9,str_time);
off_time = EEPROM_Read(off_time_address);
if(!plus)
{
if(off_time<59)off_time++;
else off_time=59;
buzzer=1;
}
if(!minus)
{
if(off_time>1)off_time--;
else off_time=1;
buzzer=1;
}
disp_time(2,1,off_time,0);
Lcd_COut(2,10,str_mm_ss);
EEPROM_Write(off_time_address,off_time);
while(WR_bit);
delay(150);
buzzer=0;
break;
break;
}
}
--- Updated ---
Also in this block how can I reduce some memory consumption?
C++:
//temp_sensing
/******************************************************************************/
int k=0;
unsigned int temp;
bit temp_read_ok;
unsigned int temperature=0;
float average=0.0;
/******************************************************************************/
void read_temp()
{
temperature=0;
TRISA0_bit = 1;
ADCON0=0x01;//select adc0
ADCON1=0x00;//2uS per sample
ANSEL=0x01;
ANSELH=0x00;
for(k=0;k<=10;k++)
{
temp = ADC_Read(0);
average = (unsigned int)temp;
average = ((1023 /average)-1);
average = 10000/average; // get the resistor value
average = average/10000; // R/Ro
average = log(average); // temp = log(R/Ro)
average /= 3950; // 1/B
average += 1.0/(25.00 + 273.15);
average = 1.00/average;
average = ((average-273.15)*1.8)+32.00; // converting K to F.
temperature += (unsigned int)average*10; //take Temperature data
delay(50);
}
temperature/=10;
temp_read_ok=1;//read ok
separation_bit=1;
}
/******************************************************************************/
//
Last edited: