📄 cc6.c
字号:
CCU6_CC63SRL = 0x00; // load CCU6 capture/compare shadow register
// low for channel 3
CCU6_CC63SRH = 0x00; // load CCU6 capture/compare shadow register
// high for channel 3
/// -----------------------------------------------------------------------
/// Configuration of Multi-Channel Mode Output Register
/// -----------------------------------------------------------------------
CCU6_MCMOUTSL = 0x00; // load CCU6 multi channel mode output
// control register low
CCU6_MCMOUTSH = 0x00; // load CCU6 multi channel mode output
// control register high
SFR_PAGE(_cc2, noSST); // switch to page 2
/// -----------------------------------------------------------------------
/// Configuration of Timer Control Register
/// -----------------------------------------------------------------------
CCU6_TCTR2L = 0x00; // load CCU6 timer control register 2 low
CCU6_TCTR2H = 0x00; // load CCU6 timer control register 2 high
/// -----------------------------------------------------------------------
/// Configuration of CCU6 trap control:
/// -----------------------------------------------------------------------
/// - a trap can only be generated by SW by setting the bit TRPF
/// - the trap state is left when a zero-match of T12 (while counting up)
/// is detected (synchronization to T12)
/// - bit TRPF is automatically cleared by HW (according to TRPPEN, TRPM0
/// and TRPM1)
/// - trap interrupt is disabled
CCU6_TRPCTRL = 0x00; // load CCU6 trap control register low
CCU6_TRPCTRH = 0x00; // load CCU6 trap control register high
/// -----------------------------------------------------------------------
/// Configuration of Multi Channel Mode:
/// -----------------------------------------------------------------------
/// - multi channel mode is enabled
/// - switching selection:
/// - transfer on correct hall event
/// - switching synchronization:
/// - direct transfer
/// - interrupt on correct hall event is enabled
/// - interrupt on wrong hall event is disabled
/// - the automatic entering of the idle state is disabled
CCU6_MODCTRL = 0x80; // load CCU6 modulation control register low
CCU6_MODCTRH = 0x00; // load CCU6 modulation control register high
/// -----------------------------------------------------------------------
/// Configuration of Multi_Channel Mode Control Register
/// -----------------------------------------------------------------------
CCU6_MCMCTR = 0x01; // load CCU6 multi channel mode control
// register
/// -----------------------------------------------------------------------
/// Configuration of T12 Capture/Compare Mode Select Register
/// -----------------------------------------------------------------------
CCU6_T12MSELL = 0x88; // load CCU6 T12 campture/compare mode
// select register low
CCU6_T12MSELH = 0x08; // load CCU6 T12 campture/compare mode
// select register high
/// -----------------------------------------------------------------------
/// Configuration of Passive State Level Register
/// -----------------------------------------------------------------------
CCU6_PSLR = 0x00; // load CCU6 passive state level register low
/// -----------------------------------------------------------------------
/// Configuration of CCU6 interrupt control:
/// -----------------------------------------------------------------------
/// - for channel 0 interrupts is node I3 selected
/// - for channel 1 interrupts is node I3 selected
/// - for channel 2 interrupts is node I3 selected
/// - for correct hall event interrupt is node I3 selected
/// - for error interrupts is node I3 selected
/// - for T12 interrupts is node I3 selected
/// - for T13 interrupts is node I3 selected
CCU6_INPL = 0xFF; // load CCU6 capture/compare interrupt node
// pointer register low
CCU6_INPH = 0x3F; // load CCU6 capture/compare interrupt node
// pointer register high
CCU6_IENL = 0x00; // load CCU6 capture/compare interrupt
// enable register low
CCU6_IENH = 0x10; // load CCU6 capture/compare interrupt
// enable register high
SFR_PAGE(_cc3, noSST); // switch to page 3
/// -----------------------------------------------------------------------
/// Configuration of Compare State Register
/// -----------------------------------------------------------------------
CCU6_CMPSTATH = 0x00; // load CCU6 compare status register high
/// -----------------------------------------------------------------------
/// Configuration of CCU6 module input signals:
/// -----------------------------------------------------------------------
/// - signal CC60_0 is used as output
/// - signal CC61_0 is used as output
/// - signal CC62_0 is used as output
/// - signal #CTRAP is not used
CCU6_PISEL0L = 0x00; // load CCU6 Port Input Select Register 0 Low
/// - signal CCPOS0_0 is used
/// - signal CCPOS1_0 is used
/// - signal CCPOS2_0 is used
/// - signal T12HR is not used
CCU6_PISEL0H = 0x00; // load CCU6 Port Input Select Register 0
// High
/// - signal T13HR is not used
CCU6_PISEL2 = 0x00; // load CCU6 Port Input Select Register 2
/// Pin P3.0 is used as CC60_0 Output
/// Pin P3.1 is used as COUT60_0 Output
/// Pin P3.2 is used as CC61_0 Output
/// Pin P3.3 is used as COUT61_0 Output
/// Pin P3.4 is used as CC62_0 Output
/// Pin P3.5 is used as COUT62_0 Output
SFR_PAGE(_pp2, noSST); // switch to page 2
P3_ALTSEL0 |= 0x3F; // set AltSel0
P3_ALTSEL1 &= ~(ubyte)0x3F; // set AltSel1
SFR_PAGE(_pp0, noSST); // switch to page 0
P3_DIR |= 0x3F; // set P3.7 OutPut
/// -----------------------------------------------------------------------
/// Configuration of the used CCU6 Channels Interrupts:
/// -----------------------------------------------------------------------
/// - capture/compare interrupt node 0 is disabled
/// - capture/compare interrupt node 1 is disabled
/// - capture/compare interrupt node 2 is disabled
/// - capture/compare interrupt node 3 is enabled
IEN1 |= 0x80; // load interrupt enable register 2
SFR_PAGE(_cc0, noSST); // switch to page 0
/// -----------------------------------------------------------------------
/// Timer Control Register
/// -----------------------------------------------------------------------
/// - enable shadow transfer to T12 and T13
CCU6_TCTR4L = 0x40; // load CCU6 timer control register 4 low
CCU6_TCTR4H = 0x40; // load CCU6 timer control register 4 high
/// Start timer settings
CCU6_TCTR4L = 0x02; // start timer 12
// USER CODE BEGIN (Init,3)
// USER CODE END
} // End of function CC6_vInit
//****************************************************************************
// @Function void CC6_viNodeI3(void)
//
//----------------------------------------------------------------------------
// @Description This is the interrupt service routine for the CC6 node I3.
// If the content of the corresponding compare timer
// (configurable) equals the content of the capture/compare
// register or if a capture event occurs at the associated
// port pin, the interrupt request flag is set and an
// interrupt is triggered (only if enabled).
// Please note that you have to add application specific code
// to this function.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 7/25/2005
//
//****************************************************************************
// USER CODE BEGIN (NodeI3,1)
// USER CODE END
void CC6_viNodeI3(void) interrupt CCU6_NodeI3_INT
{
// USER CODE BEGIN (NodeI3,2)
extern code unsigned char HallPatt[];
extern code unsigned char OutputPatt[];
unsigned char temp;
// USER CODE END
SFR_PAGE(_cc3, SST2); // switch to page 3
if(CCU6_ISH & 0x10) //if ISH_CHE
{
//correct hall event detection
SFR_PAGE(_cc0, noSST); // switch to page 0
CCU6_ISRH = 0x10; //clear flag ISH_CHE
// USER CODE BEGIN (NodeI3,23)
temp = CCU6_MCMOUTSH & 0x07; //get next hall state
CCU6_MCMOUTSL = OutputPatt[temp]; //program shadow registers with next state values
CCU6_MCMOUTSH = HallPatt[temp]; //the shadow transfer will be automatic
// USER CODE END
}
SFR_PAGE(_cc0, RST2); // restore the old CCU page
} // End of function CC6_viNodeI3
// USER CODE BEGIN (CCU6_General,10)
// USER CODE END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -