一.STC8H1K16初始化,以下一步配置后就会有波形输出.
//========================================================================
// 函数: PWMB_Output_init
// 描述: 用户初始化程序.
// 参数: None.
// 返回: None.
// 版本: V1.0, 2020-09-28
//========================================================================u16 PWM8__setDuty=25000;u16 PWM8__setPeriod=50000;
void PWMB_Output_init(void)
{PWMx_InitDefine PWMx_InitStructure;
// PWMB_Duty.PWM5_Duty = 128;
// PWMB_Duty.PWM6_Duty = 256;
// PWMB_Duty.PWM7_Duty = 512;
// PWMB_Duty.PWM8_Duty = 1024*10;PWMB_Duty.PWM8_Duty = 25000;
// PWMx_InitStructure.PWM_Mode = CCMRn_PWM_MODE1; //模式, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
// PWMx_InitStructure.PWM_Duty = PWMB_Duty.PWM5_Duty; //PWM占空比时间, 0~Period
// PWMx_InitStructure.PWM_EnoSelect = ENO5P; //输出通道选择, ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8P
// PWM_Configuration(PWM5, &PWMx_InitStructure); //初始化PWM, PWMA,PWMB// PWMx_InitStructure.PWM_Mode = CCMRn_PWM_MODE1; //模式, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
// PWMx_InitStructure.PWM_Duty = PWMB_Duty.PWM6_Duty; //PWM占空比时间, 0~Period
// PWMx_InitStructure.PWM_EnoSelect = ENO6P; //输出通道选择, ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8P
// PWM_Configuration(PWM6, &PWMx_InitStructure); //初始化PWM, PWMA,PWMB// PWMx_InitStructure.PWM_Mode = CCMRn_PWM_MODE1; //模式, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2
// PWMx_InitStructure.PWM_Duty = PWMB_Duty.PWM7_Duty; //PWM占空比时间, 0~Period
// PWMx_InitStructure.PWM_EnoSelect = ENO7P; //输出通道选择, ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8P
// PWM_Configuration(PWM7, &PWMx_InitStructure); //初始化PWM, PWMA,PWMBPWMx_InitStructure.PWM_Mode = CCMRn_PWM_MODE1; //模式, CCMRn_FREEZE,CCMRn_MATCH_VALID,CCMRn_MATCH_INVALID,CCMRn_ROLLOVER,CCMRn_FORCE_INVALID,CCMRn_FORCE_VALID,CCMRn_PWM_MODE1,CCMRn_PWM_MODE2PWMx_InitStructure.PWM_Duty = PWMB_Duty.PWM8_Duty; //PWM占空比时间, 0~PeriodPWMx_InitStructure.PWM_EnoSelect = ENO8P; //输出通道选择, ENO1P,ENO1N,ENO2P,ENO2N,ENO3P,ENO3N,ENO4P,ENO4N / ENO5P,ENO6P,ENO7P,ENO8PPWM_Configuration(PWM8, &PWMx_InitStructure); //初始化PWM, PWMA,PWMBPWMx_InitStructure.PWM_Period = 50000; //周期时间, 0~65535PWMx_InitStructure.PWM_DeadTime = 0; //死区发生器设置, 0~255PWMx_InitStructure.PWM_MainOutEnable= ENABLE; //主输出使能, ENABLE,DISABLEPWMx_InitStructure.PWM_CEN_Enable = ENABLE; //使能计数器, ENABLE,DISABLEPWM_Configuration(PWMB, &PWMx_InitStructure); //初始化PWM通用寄存器, PWMA,PWMB//NVIC_PWM_Init(PWMB,DISABLE,Priority_0);
//NVIC_PWM_Init(PWMB,PWM_CC8IE,Priority_0);//P0_MODE_IO_PU(GPIO_Pin_LOW); //P0.0,P0.1,P0.2,P0.3 设置为准双向口
//P3_MODE_IO_PU(GPIO_Pin_4); //P0.0,P0.1,P0.2,P0.3 设置为准双向口P3_MODE_OUT_OD(GPIO_Pin_4); //T12
// P0_MODE_IO_PU(GPIO_Pin_LOW); //P0.0,P0.1,P0.2,P0.3 设置为准双向口
}
二.设置开关
P3_MODE_OUT_PP(GPIO_Pin_4); //定时器
三.开启关闭.
PWM8P_OUT_DIS(); // 关闭PWM8P的PWM输出PWMB_ENO &= ~0x40 ; // 关闭PWM8P的PWM输出PWMB_Duty8(0) ;EAXRAM();// if(testdata==110){
// EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */
// PWM8P_OUT_DIS(); // 关闭PWM8P的PWM输出
// PWMB_ENO &= ~0x40 ; // 关闭PWM8P的PWM输出
// EAXRAM();
// }
// // if(testdata==111){EAXSFR(); /* MOVX A,@DPTR/MOVX @DPTR,A指令的操作对象为扩展SFR(XSFR) */PWMB_ENO |= ENO8P; // 打开PWM8P的PWM输出EAXRAM();TX1_write2buff('A');TX1_write2buff('D');TX1_write2buff('C');TX1_write2buff('1');
// TX1_write2buff(2+'0');TX1_write2buff('=');TX1_write2buff('=');TX1_write2buff(j/1000 + '0');TX1_write2buff(j%1000/100 + '0');TX1_write2buff(j%100/10 + '0');TX1_write2buff(j%10 + '0');TX1_write2buff(' ');TX1_write2buff('T');TX1_write2buff('C');PrintString1("\r\n");
// PrintString1("ADC_RES_12BIT:");
// TX1_write2buff(ADC_RES_12BIT + '0');
// PrintString1("ADC_CONTR");
// TX1_write2buff(ADC_CONTR + '0');
//disply_three_digitBlack(current_temperature,111);