Texas Instruments MSC1210 User Manual

Page 134

Advertising
background image

PWM Generator

11-10

Table 11−4. Configuring the PWM for Tone Generation with PWM Idling

Stmt

‘C’ Source Code

Assembly Source Code

1

// PWM

PUBLIC main

RSEG ???main?PWM

2

#include <reg1210.h>

3

#define OneUsConst (2−1)

4

sbit p33=p3^3;

5

void main(void)

Main:

6

{

7

PDCON &= 0xED; // turn on tone gen & sys timer

ANL PDCON,#0Edh

8

USEC = OneUsConst;

MOV USEC,#01h

9

P33 = 1; // turn on P3.3

SETB p33

10

PWMCON = 0; // select PWMPeriod

MOV PWMCON,#00h

11

PWM = 5; // Set PWMPeriod

MOV PWMHI,#00h

MOV PWMLOW,#05h

12

PWMCON = 0x10; // select PWMDuty

MOV PWMCON,#10h

13

PWM = 0; // Set PWMDuty

MOV PWMHI,#00h

MOV PWMLOW,#04h

14

PWMCON = 0x09; // Enable PWM

MOV PWMCON,#09h

15

for(i=0; i < 10; i++);

MOV R7,#00h

Loop:

INC R7

CJNE R7,#0Ah,Loop

16

PWMCON = 0x10; // select PWMDuty

MOV PWMCON,#10h

17

PWM = 4; // Set PWMDuty

MOV PWMHI,#00h

MOV PWMLOW,#04h

18

PWMCON = 0x09; // Enable PWM

MOV PWMCON,#09h

19

while(1) {}

SJMP $

20

}

Table 11−5. Statement Explanations

Statement #

Explanation

1−12

Same as previous program in section 11.3.1.

13

Sets PWM Duty to 0, thereby configuring the PWM tone generator for idle mode.

14

Enables PWM. The PWM is enabled, but is in idle mode due to the fact that PWM Duty is 0.

15

This loops for an arbitrary number of instructions.

16−20

Same as statements 12 to 16 in previous program in section 11.3.2.

Advertising