📄 mainc.c
字号:
//-------------------------------------------------------------------
// Include Files
//-------------------------------------------------------------------
#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
//-------------------------------------------------------------------
// C Interrupt Handlers
//-------------------------------------------------------------------
#pragma interrupt_handler Counter16_ISR_C
//-------------------------------------------------------------------
// Global Symbols
//-------------------------------------------------------------------
extern BYTE bElapsedCount;
//-------------------------------------------------------------------
// Variable Allocation
//-------------------------------------------------------------------
BYTE bElapsedCount;
//-----------------------------------------------------------------------------
// FUNCTION NAME: Mainc
//
// DESCRIPTION:
// Main function. Performs system initialization and loops infinitely.
//
//-----------------------------------------------------------------------------
//
// ARGUMENTS: None
// RETURNS: Nothing.
// SIDE EFFECTS: None.
//
// THEORY of OPERATION or PROCEDURE:
// 1) Enable Interrupts of user modules and Global Interrupt
// 2) Start the user modules
// 3) Loop Infinitely
//
void mainc()
{
//Initialise port2 to 0x00
PRT2DR=0x00;
//Enable the global Interrupt
M8C_EnableGInt;
//Enable the Coutner Interrupt
Counter16_EnableInt();
//Start the Counter
Counter16_Start();
//Infinite loop. Processing done only at Counter16 ISR
while(1);
}
//-----------------------------------------------------------------------------
// FUNCTION NAME: Counter16_ISR_C
//
// DESCRIPTION:
// Interrupt Service routine of Counter16 usermodule written in C.
// The _Counter16_ISR subroutine In the Counter16int.asm file,
// redirects the flow to this subroutine.
//-----------------------------------------------------------------------------
//
// ARGUMENTS: None
// RETURNS: Nothing.
// SIDE EFFECTS: None.
//
// THEORY of OPERATION or PROCEDURE:
// This ISR is serviced on every Termincal count (ie., normally after of every
// one second, if the input switch at P1[4] is not pressed)
// A counter is incremented and output to PORT-2.
// When the counter reaches 0x10 (ie.,16), it is reset to 0
//
void Counter16_ISR_C()
{
//increment the variable
bElapsedCount++;
//if bElapsedCount is greater than or equal to 0x10 (ie.,16)
if (bElapsedCount >= 0x10 ) {
//reset the variable to 0
bElapsedCount=0x00;
}
//output to Port2.
PRT2DR=bElapsedCount;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -