Hi I just got this program from keil and i am tryin to understand and i hope somebody out there can help me. First:I dont understand how this simple line define Port_D XBYTE [0xFFA0]defines port 1(bit 0,1,4,5).What is FFA0 doin there? Second:What is the line below doing? #define _CLOCKVAL ((unsigned int) ((XTAL/(12/(X2+1))) * INT_CLOCK)) Thanx in advance Martin #define Port_D XBYTE [0xFFA0] // bit 0: switch S1 // bit 1: switch S2 // bit 4: LED D1 // bit 5: LED D2 #define DipSwitch XBYTE [0xFF80] static unsigned char IOinfo = 0xFF; static bit SendInfo; /******************************************************************************/ /* Timer 0 interrupt service function */ /* executes each 1ms @ 20 MHz Crystal Clock */ /******************************************************************************/ #define INT_CLOCK 0.001 // timer interval 0.001Sec #define XTAL 20000000 #define X2 0 // set to 1 if in X2 Mode #define _CLOCKVAL ((unsigned int) ((XTAL/(12/(X2+1))) * INT_CLOCK)) #define T0_CLOCK ((-_CLOCKVAL)+13)
It's Manual reading time! The XBYTE macro is described in the C51 User Guide INT_CLOCK and X2 are described in the comments in the code you quoted, and I presume that XTAL must represent your processor's clock frequency? In Hz?
Yes i understand XTAL is the processor's clock what i dont understand is what is being calculated in the line i mentioned: define _CLOCKVAL ((unsigned int) ((XTAL/(12/(X2+1))) * INT_CLOCK))
Looks like the instruction clock is beging derived from the oscillator frequency. Jon