How to generate the 18kHz sqaure wave using 8051
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...