概述
NY8A053E简介视频
单片机内核:NY8A053E
*项目:PWM1~PWM4同时输出
*文件:main.asm
*描述:本项目介绍如何设置和输出PWM1~PWM4
*1.指令时钟=20MHz/4T
* 2.
*PWM4(PA2):周期=4.88KHz(占空比:255/1024)
*PWM3(PA3):周期=4.88KHz(占空比:768/1024)
*PWM2(PA0):周期=4.88KHz(占空比:1023/1024)
*PWM1(PB6):周期=4.88KHz(占空比:1/1024)
#include <ny8.h>
#include "ny8_constant.h"
//PWM duty setting
#define C_PWM_LB_DUTY_00H 0x00
#define C_PWM_LB_DUTY_40H 0x40
#define C_PWM_LB_DUTY_01H 0x01
#define C_PWM_LB_DUTY_FFH 0xFF
#define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
void main(void)
{
DISI();
// Initial GPIO
IOSTB = C_PB_Output; // Set PortB as output port
IOSTA = C_PA_Output; // Set PortA as output port
PORTA = 0x00; // PortA Data Register = 0x00
PORTB = 0x00; // PortB Data Register = 0x00
PCON = C_WDT_En | C_LVR_En; // Enable WDT & LVR
// Initial Timer 1 & PWM1/2 control register
TMRH = C_TMR1_Data_b9 | C_TMR1_Data_b8 | C_PWM2_Duty_b9 | C_PWM2_Duty_b8; // SET TMR1_Data_b9 , TMR1_Data_b8 , PWM2_Duty_b9 & PWM2_Duty_b8 as 1
TMR1 = 0xFF; // Move FFH to TMR1 LB register ( TMR1[9:0]=3FFH )
PWM1DUTY = C_PWM_LB_DUTY_01H; // Move 01H to PWM1DUTY LB register ( PWM1DUTY[9:0]=001H )
PWM2DUTY = C_PWM_LB_DUTY_FFH; // Move FFH to PWM2DUTY LB register ( PWM2DUTY[9:0]=3FFH )
T1CR2 = C_PS1_Dis | C_TMR1_ClkSrc_Inst; // Prescaler 1:1 , Timer1 clock source is instruction clock
T1CR1 = C_PWM1_En | C_PWM1_Active_Hi | C_TMR1_Reload | C_TMR1_En; // Enable PWM1 , Active_High , Non-Stop mode ,reloaded from TMR1[9:0] , enable Timer1
P2CR1 = C_PWM2_En | C_PWM2_Active_Hi | C_TMR1_Reload | C_TMR1_En; // Enable PWM2 , Active_High , Non-Stop mode ,reloaded from TMR1[9:0] , enable Timer1
// Initial Timer 3 & PWM3/4 control register
TM34RH = C_PWM3_Duty_b9 | C_PWM3_Duty_b8; // SET PWM3_Duty_b9 & PWM3_Duty_b8 as 1
PWM3DUTY = C_PWM_LB_DUTY_00H; // Move 00H to PWM3DUTY LB register ( PWM3DUTY[9:0]=300H )
PWM4DUTY = C_PWM_LB_DUTY_FFH; // Move FFH to PWM4DUTY LB register ( PWM4DUTY[9:0]=0FFH )
P3CR1 = C_PWM3_En | C_PWM3_Active_Hi; // Enable PWM3 , Active_High
P4CR1 = C_PWM4_En | C_PWM4_Active_Hi; // Enable PWM4 , Active_High
while(1)
{
CLRWDT(); // Clear WatchDog
}
}
更多关于NY8A053E的相关例程请留言!
最后
以上就是激动冬日为你收集整理的NY8A053E 例程 之 PWM Ouput单片机内核:NY8A053E的全部内容,希望文章能够帮你解决NY8A053E 例程 之 PWM Ouput单片机内核:NY8A053E所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复