打印
[DemoCode下载]

N76E003的多路PWM

[复制链接]
776|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jonas222|  楼主 | 2024-7-26 18:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include “N76E003.h”
#include “Common.h”
#include “Delay.h”
#include “SFR_Macro.h”
#include “Function_define.h”
bit BIT_TMP;
void Timer0_Delay10us(UINT32 u32CNT)
{
clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
TIMER0_MODE1_ENABLE; //TMOD |= 0x01; //Timer0 is 16-bit mode
  • set_TR0;                                        <span class="hljs-regexp">//</span>Start Timer0
  • <span class="hljs-keyword">while</span> (u32CNT != <span class="hljs-number">0</span>)
  • {
  •     TL0 = LOBYTE(TIMER_DIV12_VALUE_10us);    <span class="hljs-regexp">//</span>Find  define <span class="hljs-keyword">in</span> <span class="hljs-string">"Function_define.h"</span> <span class="hljs-string">"TIMER VALUE"</span>
  •     TH0 = HIBYTE(TIMER_DIV12_VALUE_10us);
  •     <span class="hljs-keyword">while</span> (TF0 != <span class="hljs-number">1</span>);                           <span class="hljs-regexp">//</span>Check Timer0 Time-Out Flag
  •     clr_TF0;
  •     u32CNT --;
  • }
  • clr_TR0;                                           <span class="hljs-regexp">//</span>Stop Timer0
}
//————————————————————————————————————-
void Timer0_Delay100us(UINT32 u32CNT)
{
clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
TMOD |= 0x01; //Timer0 is 16-bit mode
set_TR0; //Start Timer0
while (u32CNT != 0)
{
TL0 = LOBYTE(TIMER_DIV12_VALUE_100us); //Find define in “Function_define.h” “TIMER VALUE”
TH0 = HIBYTE(TIMER_DIV12_VALUE_100us);
while (TF0 != 1); //Check Timer0 Time-Out Flag
clr_TF0;
u32CNT —;
}
clr_TR0; //Stop Timer0
}
//———————————————————————————————————————
//void Timer0_Delay1ms(UINT32 u32CNT)
//{
// clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
// TMOD |= 0x01; //Timer0 is 16-bit mode
// set_TR0; //Start Timer0
// while (u32CNT != 0)
// {
// TL0 = LOBYTE(TIMER_DIV12_VALUE_1ms); //Find define in “Function_define.h” “TIMER VALUE”
// TH0 = HIBYTE(TIMER_DIV12_VALUE_1ms);
// while (TF0 != 1); //Check Timer0 Time-Out Flag
// clr_TF0;
// u32CNT —;
// }
// clr_TR0; //Stop Timer0
//}
void Timer0_Delay1ms(UINT32 u32CNT)
{
clr_T0M; //T0M=0, Timer0 Clock = Fsys/12
// TMOD |= 0x01; //Timer0 is 16-bit mode
TMOD&=0xf0; TMOD |= 0x01; //Timer0 is 16-bit mode
  • set_TR0;
//
Start Timer0
while (u32CNT != 0)
{
// TL0 = LOBYTE(TIMER_DIV12_VALUE_1ms); //Find define in “Function_define.h” “TIMER VALUE”
// TH0 = HIBYTE(TIMER_DIV12_VALUE_1ms);
TL0 = TIMER_DIV12_VALUE_1ms & 0xff;
TH0 = TIMER_DIV12_VALUE_1ms >> 8;

  •     while  (TF0 != <span class="hljs-number">1 //</span>Check Timer0 Time-Out Flag
  •     clr_TF0;
  •     u32CNT --;
  • }
  • clr_TR0;                           //Stop Timer0
}
//———————————————————————————————————————
void Timer1_Delay10ms(UINT32 u32CNT)
{
clr_T1M; //T1M=0, Timer1 Clock = Fsys/12
TMOD |= 0x10; //Timer1 is 16-bit mode
set_TR1; //Start Timer1
while (u32CNT != 0)
{
TL1 = LOBYTE(TIMER_DIV12_VALUE_10ms); //Find define in “Function_define.h” “TIMER VALUE”
TH1 = HIBYTE(TIMER_DIV12_VALUE_10ms);
while (TF1 != 1); //Check Timer1 Time-Out Flag
clr_TF1;
u32CNT —;
}
clr_TR1; //Stop Timer1
}
//———————————————————————————————————————
void Timer2_Delay500us(UINT32 u32CNT)
{
clr_T2DIV2; //Timer2 Clock = Fsys/4
clr_T2DIV1;
set_T2DIV0;
set_TR2; //Start Timer2
while (u32CNT != 0)
{
TL2 = LOBYTE(TIMER_DIV4_VALUE_500us); //Find define in “Function_define.h” “TIMER VALUE”
TH2 = HIBYTE(TIMER_DIV4_VALUE_500us);
while (TF2 != 1); //Check Timer2 Time-Out Flag
clr_TF2;
u32CNT —;
}
clr_TR2; //Stop Timer2
}
//———————————————————————————————————————
void Timer3_Delay100ms(UINT32 u32CNT)
{
T3CON = 0x07; //Timer3 Clock = Fsys/128
set_TR3; //Trigger Timer3
while (u32CNT != 0)
{
RL3 = LOBYTE(TIMER_DIV128_VALUE_100ms); //Find define in “Function_define.h” “TIMER VALUE”
RH3 = HIBYTE(TIMER_DIV128_VALUE_100ms);
while ((T3CON&SET_BIT4) != SET_BIT4); //Check Timer3 Time-Out Flag
clr_TF3;
u32CNT —;
}
clr_TR3; //Stop Timer3
}
//———————————————————————————————————————
void Timer3_Delay10us(UINT32 u32CNT)
{
T3CON = 0x07; //Timer3 Clock = Fsys/128
set_TR3; //Trigger Timer3
while (u32CNT != 0)
{
RL3 = LOBYTE(TIMER_DIV4_VALUE_10us); //Find define in “Function_define.h” “TIMER VALUE”
RH3 = HIBYTE(TIMER_DIV4_VALUE_10us);
  •     <span class="hljs-keyword">while</span> ((T3CON&SET_BIT4) != SET_BIT4);        <span class="hljs-regexp">//</span>Check Timer3 Time-Out Flag
  •     clr_TF3;
  •     u32CNT --;
  • }
  • clr_TR3;                                        <span class="hljs-regexp">//</span>Stop Timer3
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

23

主题

1391

帖子

0

粉丝