📄 pulse.c
字号:
/**********************************************************************
File Name: Pulse.c
Discription: Pulse for thyristor. The zero-crossing signal of power
is inputed from the capture of 2407, which generate the
pulse and control its phase.
Copy Right: Guoguo
**********************************************************************/
/*include register definition of 2407*/
#include "Reg_2407_C.h"
/*include varable and I/O address definition of 2407*/
#include "Pulse.h"
main()
{
CPU_Init();
EV_Init();
IOport_Init();
asm(" CLRC INTM ");
/*i = 0;/*tt*/
/**T1CON |= 0x0040;/*tt*/
*T2CON |= 0x0040; /* Enable T2 */
while(1)
{
/*------------------------------------------------------------------------*/
/* Pulse generation. P1 is started from the zero-crossing of Uca. */
/* Pulse width is 90 degree. Order: P1-P2-P3-P4-P5-P6-P1 */
/* ___________ ___________ ___________ ___ */
/* |_____1_____|___|_____3_____|___|_____5_____|___|_1_ */
/* ___ ___________ ___________ ___________ */
/* |_6_|___|_____2_____|___|_____4_____|___|_____6_____| */
/* | | | | | | | | | | | | | | */
/* 0 30 60 90 120 150 180 210 240 270 300 330 360 30 */
/* */
/* 0 is the zero-crossing of Uca. 30 degree: i=125 */
/*------------------------------------------------------------------------*/
switch(i)
{
case 0: {*PADATDIR=0x0C040; *PBDATDIR=0x0F08; break;}
case 125: {*PADATDIR=0x0C040; *PBDATDIR=0x0F00; break;}
case 250: {*PADATDIR=0x0C0C0; *PBDATDIR=0x0F00; break;}
case 375: {*PADATDIR=0x0C080; *PBDATDIR=0x0F00; break;}
case 500: {*PADATDIR=0x0C080; *PBDATDIR=0x0F01; break;}
case 625: {*PADATDIR=0x0C000; *PBDATDIR=0x0F01; break;}
case 750: {*PADATDIR=0x0C000; *PBDATDIR=0x0F03; break;}
case 875: {*PADATDIR=0x0C000; *PBDATDIR=0x0F02; break;}
case 1000: {*PADATDIR=0x0C000; *PBDATDIR=0x0F06; break;}
case 1125: {*PADATDIR=0x0C000; *PBDATDIR=0x0F04; break;}
case 1250: {*PADATDIR=0x0C000; *PBDATDIR=0x0F0C; break;}
case 1375: {*PADATDIR=0x0C000; *PBDATDIR=0x0F08; break;}
default: {break;}
}
}
}
interrupt void cap_isr(void)
{
unsigned int EVAIFRC_temp;
EVAIFRC_temp = *EVAIFRC;
if(!(EVAIFRC_temp & 0x0004)) /* CAP3 interrupt-go down; else return */
{
asm(" CLRC INTM ");
return;
}
i = 0;
*EVAIFRC = *EVAIFRC|0x0004;
asm(" CLRC INTM ");
*T1CON |= 0x0040;
*T1CNT = 0x0000;
*T2CNT = 0x0000;
return;
}
interrupt void T1P_isr(void) /* T1 period interrupt: 40/3us */
{
int flag;
flag = *EVAIFRA;
if(!(flag & 0x0080))
{
asm(" CLRC INTM ");
return;
}
*EVAIFRA = *EVAIFRA|0x0080;
i++;
/*if(i>=1500) i=0;/*tt*/
asm(" CLRC INTM ");
return;
}
interrupt void Phantom(void)
{
asm(" CLRC INTM ");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -