📄 ports.c
字号:
/**************** (c) 2004 STMicroelectronics **********************
PROJECT : 3-phase AC induction motor drive Software Library
COMPILER : COSMIC / METROWERKS
MODULE : ports.c
VERSION : 1.1
CREATION DATE : 07.2003
AUTHOR : Florent COSTE / Microcontroller Application Lab / ST Hong Kong
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
DESCRIPTION : I/O line control routines
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MODIFICATIONS
04.2004 (V. Onde) Rel 1.1: Remove unused functions and variables
******************************************************************************
THE SOFTWARE INCLUDED IN THIS FILE IS FOR GUIDANCE ONLY. ST MICROELECTRONICS
SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES
WITH RESPECT TO ANY CLAIMS ARISING FROM USE OF THIS SOFTWARE.
******************************************************************************
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
******************************************************************************/
#include "lib.h"
#include "ports.h"
#include "ST7FMC2N6.h"
#include "pwmart.h"
#define BUTTON 0
#define BUTTON_PORT PCDR
#define LED ((u8)0x80) /* PB7 */
#define PB7 ((u8)7)
static u8 KeyState; // status of key panel
#define KEY_IDLE ((u8)0)
#define KEY_IDLE_NEXT ((u8)1)
#define KEY_PUSHED ((u8)2)
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_Init
INPUT/OUTPUT : None
DESCRIPTION : Configure the ports
COMMENTS :
-----------------------------------------------------------------------------*/
void PORTS_Init(void) // Setting for 56 pins case of Starter kit
{
PADDR = 0x00; //PA7 to PA0 floating Input
PAOR = 0x00;
PBDDR = 0x80; //PB7 output push pull
PBOR = 0x80; //PB6 to PB0 floating Input
PCDDR = 0x00; //PC7 to PC0 floating Input
PCOR = 0x00;
PDDDR = 0x00; //PD7 to PD0 floating Input
PDOR = 0x00;
PEDDR = 0x00; //PE7 to PE0 floating Input
PEOR = 0x00;
PFDDR = 0x00; //PF7 to PF0 floating Input
PFOR = 0x00;
KeyState = 0;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_RedLedOn; PORTS_RedLedOff; PORTS_RedLedToggle
PORTS_GreenLedOn; PORTS_GreenLedOff; PORTS_GreenLedToggle
PORTS_RedGreenLedToggle; PORTS_BothLedOff
INPUT/OUTPUT : None
DESCRIPTION : Set/Reset/Toggle Red or Green or Both LED
COMMENTS :
-----------------------------------------------------------------------------*/
void PORTS_RedLedOn(void)
{
PBDDR |= LED; //PB7 push-pull Output
PBOR |= LED;
PBDR |= LED;
}
void PORTS_RedLedOff(void)
{
PBOR &= (u8)~LED; // touch PBOR first
PBDDR &= (u8)~LED; // then PBDDR -> PB7 Floating Input
}
void PORTS_RedLedToggle(void)
{
if (ValBit(PBDDR,PB7)) // push-pull config?
{
PBOR &= (u8)~LED;
PBDDR &= (u8)~LED; //Toggle PB7 direction (Floating Input or push-pull Output)
}
else
{
PBDDR |= LED; //Toggle PB7 direction (Floating Input or push-pull Output)
PBOR |= LED;
PBDR |= LED; // ((u8)0x80)
}
}
void PORTS_GreenLedOn(void)
{
PBDDR |= LED; //PB7 push-pull Output
PBOR |= LED;
PBDR &= (u8)~LED;
}
void PORTS_GreenLedOff(void)
{
PBOR &= (u8)~LED; // touch first PBOR
PBDDR &= (u8)~LED; // then PBDDR -> PB7 Floating Input
}
void PORTS_GreenLedToggle(void)
{
if (ValBit(PBDDR,PB7)) // output config?
{
PBOR &= (u8)~LED;
PBDDR &= (u8)~LED; //Toggle PB7 direction (Floating Input or push-pull Output)
}
else
{
PBDDR |= LED; //Toggle PB7 direction (Floating Input or push-pull Output)
PBOR |= LED;
PBDR &= (u8)~LED;
}
}
void PORTS_RedGreenLedToggle(void)
{
if (!ValBit(PBDDR,PB7))
{
PBDDR |= LED; //Toggle PB7 direction (Floating Input or push-pull Output)
PBOR |= LED;
}
PBDR ^= LED;
}
void PORTS_BothLedOff(void)
{
PBDDR &= (u8)~LED; //PB7 Floating Input
PBOR &= (u8)~LED;
}
/*-----------------------------------------------------------------------------
ROUTINE Name : key_scan
Description : return TRUE if button is read and released
-----------------------------------------------------------------------------*/
BOOL PORTS_KeyScan(void)
{
if (!ValBit(BUTTON_PORT,BUTTON)) // Button released (Pull-up resistor)
{
switch(KeyState)
{
case KEY_PUSHED:
if (DebounceButton == 0)
{
KeyState = KEY_IDLE_NEXT;
return (TRUE);
}
else return (FALSE);
break;
case KEY_IDLE:
DebounceButton = 10; // 100ms debounce time
KeyState = KEY_PUSHED;
return(FALSE);
break;
case KEY_IDLE_NEXT:
default:
return(FALSE);
break;
}
}
else KeyState = KEY_IDLE;
return(FALSE);
}
#ifdef __HIWARE__ /* test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS /* additional registers will be saved */
#else
#ifdef __CSMC__ /* test for Cosmic Compiler */
@interrupt /* Cosmic interrupt handling */
#else
#error"Unsupported Compiler!" /* Compiler Defines not found! */
#endif
#endif
/*-----------------------------------------------------------------------------
ROUTINE NAME : PORTS_0_Interrupt
INPUT/OUTPUT : None
DESCRIPTION :
COMMENTS :
-----------------------------------------------------------------------------*/
void PORTS_0_Interrupt(void)
{
}
/*** (c) 2004 STMicroelectronics ****************** END OF FILE ***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -