We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi all I want to add Asm file to a 'C' project. Project has one '.c'and one '.h' file. Assmbly file to be added is with '.a51' extension.only one routine is added to a51 file,which is called from main.A51 file is getting assembled successfully,but project is not getting compiled as whole. decleration in main file is :
extern void delay_asm(unsigned char);
void main() { . delay_asm(2); . }
PR?delay_asm?delay_asm SEGMENT CODE PUBLIC delay_asm delay_asm: USING 0 mov a,R7 rv:dec A Jnz rv RET END
For such a simple loop why don't you stay in "C"
void Delay (unsigned char Cycles) { while (--Cycles); }
DELAY1: DJNZ R7,DELAY1
For such a simple loop why don't you stay in "C" This function generates super efficient code Maybe and maybe not depending on brand, options and release. There is absolutely no guarantee that C will generate any specific code. Thus all timing must be in assembler. There is no end to the bitbanging and other time critical routines I have seen fall apart because the Compiler got upgraded/replaced. Erik
If you really want accurate timing, use a timer. Even hand-tweaked assembler loops can fall apart the instant you change parts (12 clocks per instruction? 4? 2?), or oscillator frequency, or perhaps the external memory subsystem timing. Any function you put in software -- in whatever language -- will leave you potentialy liable for software maintenance when the environment changes in just the wrong way.