How to generate the 18kHz sqaure wave using 8051
Easy: just toggle a port pin once every 28ms!
Now, here are the links to the so-called "bible" for the 8051 - see what you can find that might enable you to toggle a port pin once every 28ms:
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
Also check the datasheet for the particular chip that you're using - it may have other useful features...
28uS :-)
Actually, 28us !! ;-)
even easier: use the PCA of course, if you insist on using some antique or 'simple' chip, that does not apply
Erik
reference: The PCA cookbook www.intel.com/.../270609.htm