 |
 |
| View previous topic :: View next topic |
| Author |
Message |
Ttelmah Guest
|
|
Posted: Mon Aug 21, 2006 4:51 am |
|
|
Hi Simon,
I started typing my reply, before your reply appeared. Unfortunately, by the time you have taken a few phone calls etc., ten minutes have 'whizzed' round.
I would though still add the ammendment to use a global variable. If you call the function four times (say), with a seperate counter definition in each, depending on the age of the compiler, you may either get problems, or will end up with four seperate variables, all using space (the latter compiler treats a variable defined this way as 'global', but redefines it each time the routine is called!...).
So if you use the 'inline' declaration as you show, and call the function four times, you get (in the sym file):
| Code: |
023 i
024 i
025 i
026 i
|
Which is rather a waste. If instead you use the sigle global variable, you only get one location used for the counter.
Best Wishes |
|
 |
MikeW
Joined: 15 Sep 2003 Posts: 185 Location: Warrington UK
|
|
Posted: Mon Aug 21, 2006 4:57 am |
|
|
Simon,
sorry it wont compile on 3.249
I get a " a numeric expression must appear here"
below is a complete cut down version for you to try
#include "16F88.h"
//#device *=16
//#device ICD=TRUE
#device adc=8
#FUSES WDT //Watch Dog Timer
#FUSES HS
#fuses MCLR
#fuses NOLVP
#FUSES PUT
#FUSES BROWNOUT
#FUSES NOCPD
#FUSES NOWRT
#FUSES NOPROTECT
#FUSES FCMEN
//#FUSES IESC
#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=PC)
char const command_Cam_OFF[] = {0x81,0x01,0x04,0x00,0x03,0xFF};
#define Send_Command(String) {int8 i; for(i=0; i<sizeof(String);i++) {fputc (String)[i],PC);}}
void Init_PIC()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL);
setup_wdt(WDT_1152MS);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4);
setup_timer_2(T2_DIV_BY_16,241,13);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(False);
set_TRIS_A(0x00);
set_TRIS_B(0x00);
}
#define Test_LED PIN_A4
void main()
{
int8 i;
Init_PIC();
Send_Command(command_Cam_OFF); // error is here
delay_ms(500);
while (1)
{
delay_ms(2000);
output_toggle(Test_LED);
delay_ms(2000);
}
} |
|
 |
Ttelmah Guest
|
|
Posted: Mon Aug 21, 2006 5:11 am |
|
|
Get rid of the closing bracket after the word string, in the fputc.
Realistically, I'd also avoid using the word 'string', since this accepts a character array, not a 'string', and in many languages, this is a reserved keyword.
Also see my comments about declaring the variable 'globally', rather than in each call.
Best Wishes |
|
 |
MikeW
Joined: 15 Sep 2003 Posts: 185 Location: Warrington UK
|
|
Posted: Mon Aug 21, 2006 5:25 am |
|
|
Ttelmah,
at last, the bloody thing works !!!
I note your comments about using a potentially reserved word.
also the use of global integer to save ram
many thanks to both you and Simon
Mike |
|
 |
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Mon Aug 21, 2006 5:45 am |
|
|
Mike, glad you finally got it going.
Ttelmah,
| Quote: | I started typing my reply, before your reply appeared. Unfortunately, by the time you have taken a few phone calls etc., ten minutes have 'whizzed' round.
|
No problem, I did this the other night myself. It took me 25 minutes to write a reply and test some code, during which time 12 other posts had already been posted sorting the problem !!!  _________________ Regards,
Simon. |
|
 |
Ttelmah Guest
|
|
Posted: Mon Aug 21, 2006 7:15 am |
|
|
Yes, there have been threads in the past, where something like five people, all with basically the 'same' answer, post together. I don't know what the 'record' for overlapped posts actually is, but it can be quite 'fun' at times.
Did I see you were from over in Cheshire?. My family 'roots', go back over that way (actually, Germany, then into the Vale of Evesham, then into Cheshire, then emigrated to America, then back over to East London, and into Essex where I am... :-).
Best Wishes |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|