I think you have written the program correctly. The reason it will not work when you put the function main() above the other functions is because the compiler "reads" your program from the top down. The compiler sees the call to functions port_init() and ledrl() in function main() before they have been defined. Adding a function prototype (for each function) at the top of your program may be the solution. Perhaps someone else can explain it better than me. On 24 Feb 2003 at 15:00, Andre Abelian wrote: > Hi to all engineers, > > I wrote simple led test code for microchip demo board2 > it works but when I move main () function to top it generates > an error why? > Any help will appreciate. Hitech support said I didn't > Define port_init () function but I do not get it. > > > Andre > > > > > > /* simple led right,left move C code for Hi-Tech compiler*/ > #include > #include "delay.c" > #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit)) > static bit led1 @ PORTBIT(PORTB, 0); > static bit led8 @ PORTBIT(PORTB, 7); > > // led right,left test funtion > void ledrl(void){ > int c; // setup c for count > led1=1; // make RB0 on > DelayBigMs(20); // delay > for(c=7;c!=0;c--){ // setup counter to count 7 times > PORTB <<= 1 ; // shift left since c!=0 it will exit when c==0 > DelayBigMs(20);} // delay led8=1; DelayBigMs(20); > for(c=7;c!=0;c--){ PORTB >>= 1; DelayBigMs(20);} } > > // Port Init > void port_init(void){ > TRISB=0; // set portb output > TRISA=1; // set portc all input > PORTB=0; // make sure all leds off > } > > // main program > void main(void) > { > port_init(); // setup port > ledrl(); // call led funtion > } > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body -- Brent Brown, Electronic Design Solutions 16 English Street, Hamilton, New Zealand Ph/fax: +64 7 849 0069 Mobile/txt: 025 334 069 eMail: brent.brown@clear.net.nz -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body