蜂鸣器驱动:
1、原理图
GPD0_0<---->PWM TOUT0
2、芯片手册
CPD0CON 0x114000A0 1
(1)[3:0] <=== 0x2
c
TCFG0 139D0000 2
(2)[7:0] <== 0~255 0xff
TCFG1 139D0004
(3)[3:0] <== 0~4 0x1
TCON 139D0008
(6)[3:0] <== 0x2
(7)[3:0] <== 0x9
TCNTB0 139D000C
(4)[31:0] <===? 0x200
TCMPB0 139D0010
(5)[31:0] <===? 必须小于TCNTB0 0x100
#define PWM_ON _IO('K', 0) ----开定时器 TCON
#define PWM_OFF _IO('K', 1) ----关定时器 TCON
#define SET_PRE _IOW('K', 2, int) ----设置预分频值 TCFG0
#define SET_CNT _IOW('K', 3, int) ----设置周期 TCNTB0 = 2TCMPB0