View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
changing value inside the hex. file |
Posted: Tue Nov 20, 2012 7:39 am |
|
|
I want to ask about this macros:
#define treshold 500
how can I change value 500 directly by hex. file. With other words, where into the hex is placed the value 500 so I can change that without open the source and compile it again. Is that posible at all? If it is, please tell me how to find it? |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Nov 20, 2012 7:44 am |
|
|
Hi,
It may not be as simple as you think. Beyond finding the desired value, you
would also have to update the .hex file checksum so that your programmer
will not flag an error during programming of your target device.
Is this a compile-time change, or a run-time change? Tell us why you want
to do this, and we may be able to suggest a way to accomplish what you
desire!
John |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Tue Nov 20, 2012 8:12 am |
|
|
I need to do this because I have to give the program to a person that is not progremmer an he needs to change that value by himself. This is a refference to a value that conrols the operation of a electronic switch. I will not be there to do this instead. My decision was to study him to do that by manipulating the hex. It is much easier instead of study him programming on C. He has never worked with CCS Compiler. |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Tue Nov 20, 2012 9:40 am |
|
|
Here is the program.
Code: |
#include <12F683.h>
#DEVICE ADC=12
#fuses INTRC,PUT,WDT,NOMCLR
#use delay (internal = 8M,RESTART_WDT)
#USE FAST_IO (A)
#define activ_tovari 680 //I need to change
#define prag_izkl_not 650 //these three values
#define prag_izkl_dvata 630 //trough the hex.
#define losw pin_a4 //low liable switch èçõîä çà íèñêî îòãîâîðåí òîâàð
#define hisw pin_a5 //high liable switch èçõîä çà âèñîêî îòãîâîðåí òîâàð
#define delay_time 500 //âðåìåòî çà èç÷àêâàíå íà óñòàíîâÿâàíåòî íà U áàòåðèÿ â [ms]
int16 bat; //bat - íàïðåæåíèå âàòåðèÿ;
void read_bat(); //÷åòåíå íà U áàòåðèÿ
void main()
{
set_tris_a(0x04);
output_A(0x00);
SETUP_WDT(WDT_36MS);
SETUP_ADC(ADC_CLOCK_INTERNAL);
SETUP_ADC_PORTS(sAN2);
delay_ms(500);
while(true)
{
restart_wdt();
read_bat();
delay_ms(15);
if(bat<(prag_izkl_dvata))
{
delay_ms(delay_time);
read_bat();
if(bat<(prag_izkl_dvata))
{
output_low(hisw);output_low(losw);
}
}
else if(bat<prag_izkl_not)
{
delay_ms(delay_time);
read_bat();
if(bat<prag_izkl_not)
output_low(losw);
}
else if(bat>activ_tovari)
{
output_high(hisw);output_high(losw);
}
}
}
///////////////////////////////////
void read_bat()
{
set_adc_channel(2);
bat=READ_ADC();
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Nov 20, 2012 10:36 am |
|
|
As I see it your value 'threshold' is a constant.
Could you:-
Set the value yourself, and store it in EEPROM.
Arrange for the code to read threshold at startup.
Then let your friend either
1) Change the EEPROM value before programming .
OR
2) Change the EEPROM value after programming using a PC via a UART.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Tue Nov 20, 2012 1:31 pm |
|
|
Thanks for replies guys, but if there is no way to change it via hex, just tell me it is impossible. I'll come up with something else. But I want to be sure that it is impossible. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Tue Nov 20, 2012 2:00 pm |
|
|
It is NOT impossible, just that there may be other ways to do what you need to happen. |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Nov 20, 2012 4:57 pm |
|
|
Whichever way you go, your friend is going to HAVE to do some work.
Provide a series of HEX files which cover the range of possible 'threshold' values.
What more do you want?
Mike |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Tue Nov 20, 2012 6:33 pm |
|
|
hmm..another way to do it ...
though it take more code...
Assign a spare ADC channel to a trimpot accessible only during 'calibration'.
During 'powerup' run through a 'calibrate' routine
that reads the pot and stores the ADC value as the 'setpoint #1'
Press a button on another input pin to goto next step.
Read adc again, press button to store as setpoint #2
Do again for setpoint #3
...
Store these setpoints into EEPROM.
This way should power fail, 'calibrate' would not have to be done again.
The main program would refer to the EEPROM values to decide what is to be done...
If it reads '0xff' in all 3 locations it knows a 'calibration' should be done.
If you have a spare I/O pin, put an LED on it to show the user the calibration steps are being done. 1 flash=step1, 2 flashes=step2,....etc.
You can get fancy and have a second set of 'factory set default' values as well.
Overall the project is easier for the client to setup and use...NO programming or editing of hex files, etc.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
|
Posted: Wed Nov 21, 2012 12:02 am |
|
|
It is a great idea, but how can I store 10bit value (from a ADC) to a EEPROM? |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Nov 21, 2012 3:08 am |
|
|
Quote: | It is a great idea, but how can I store 10bit value (from a ADC) to a EEPROM? |
Rikotech8:- You seem to be asking this sort of question at every end and turn.
Answer:-
Do it the same way that the 8 bit micros do it.
I.e. look up in the microchip manual how the PICs handle the 10bit data from the ADC.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
|