用单片机+PWM来解码WAV真人声乐
#include
#include "wav.h"
sbit dataOut = P2^2;
#define maxSize 2060
unsigned char pwmData=0;
unsigned char pwmCycle=256; //pwm的频率
unsigned int datIndex=0;
void TimerInit() {
TMOD=0x22;
TH0=(256-pwmData)%256;
TH1=(256-(pwmCycle-pwmData))%256;
RCAP2H=0xfe; //1
RCAP2L=0xc7; //199
TH2=RCAP2H;
TL2=RCAP2L;
PT2=0;//高中断优先级
TR0=1;TR1=0;TR2=1; //启动/停止定时器
ET0=1;ET1=1;ET2=1; //打开中断
EA=1;
}
///////////////////定时器0中断//////////////////////
Timer0() interrupt 1 {
TR0=0; //turn off Timer0
dataOut=0;
TR1=1; //turn on Timer1
}
///////////////////定时器1中断///////////////////////
Timer1() interrupt 3 {
TR1=0; //turn off Timer1
dataOut=1;
TH0=(256-pwmData)%256;
TH1=(256-(pwmCycle-pwmData))%256;
TR0=1; //turn on Timer0
}
///////////////////定时器2中断///////////////////////
Timer2() interrupt 5 {
TF2=0;
pwmData=wavdata1[datIndex];
if(++datIndex==maxSize){
datIndex=0;
}
}
main(){
TimerInit();
while(1);
{}
}
单片机PWM来解码真人声 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)