intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 4.27 DESCRIPTION OF STATEMENTS STATEMENT: PWM [expr], [expr], [expr] MODE: COMMAND and/or RUN TYPE: INPUT/OUTPUT PWM stands for PULSE WIDTH MODULATION. What it does is generate a user defined pulse sequence on P1.2 (bit 2 of I/O PORT 1) of the MCS BASIC-52 device. The first expression following the PWM statement is the number of clock cycles the pulse will remain high. A clock cycle is equal to 12/XTAL, which is 1.085 microseconds at 11.0592 MHz. The second expression is the number of clock cycles the pulse will remain low and the third expression is the total number of cycles the user wishes to output. All expressions in the PWM statement must be valid integers (i.e.

between 0 and 65535 (0FFFFH) inclusive). Additionally, the minimum value for the first two expressions in the PWM statement is 25 . The PWM statement can be used to create "audiable" feedback in a system. In addition, just for fun, the programmer can play music using the PWM statement. More details about using the PWM statement are in the appendix. EXAMPLE: >PWM 100,100,1000 At 11.0592 MHz would generate 1000 cycles of a square wave that has a period of 217 microseconds (4608 Hz) on P1.2. - 62 -