#include "common.h"
#include "ics.h"
#include "rtc.h"
#include "uart.h"
#include "kbi.h"
#include "gpio.h"
#include "sysinit.h"
int main (void);
void RTC_Task(void);
void KBI0_Task(void);
void KBI1_Task(void);
int maiChongCiShu=0;//脉冲次数
int waittime=0;//脉冲前等待时间
int waittimeHOU=0;//脉冲后等待时间
int dangWei=0;//挡位
int dangWeix=0;//脉冲设置等待时间
int main (void)
{
uint8_t u8Ch,i;
ICS_ConfigType sICSConfig;
RTC_ConfigType sRTCConfig;
RTC_ConfigType *pRTCConfig = &sRTCConfig;
KBI_ConfigType sKBIConfig;
/* Perform processor initialization */
sysinit();
printf("\nRunning the KBI_demo project.\n");
LED0_Init(); //D2,Middle
LED1_Init(); //D3,RIGHT
LED2_Init(); //D4,LEFT
LED1_Off();
LED0_Off();
LED2_Off();
/* configure RTC to 1Hz interrupt frequency */
pRTCConfig->u16ModuloValue = 9;
pRTCConfig->bInterruptEn = RTC_INTERRUPT_ENABLE; /* enable interrupt */
pRTCConfig->bClockSource = RTC_CLKSRC_BUS; /*clock source is 1khz*/
pRTCConfig->bClockPresaler = RTC_CLK_PRESCALER_1024; /*prescaler is 100*/
RTC_SetCallback(RTC_Task);
RTC_Init(pRTCConfig);
printf("\nin FEE mode now,");
UART_WaitTxComplete(TERM_PORT);
/* switch clock mode from FEI to FEE */
sICSConfig.u32ClkFreq = 32;
ICS_SwitchMode(FEE,FEI, &sICSConfig);
// printf("switch to FEI mode.\n");
OSC_Enable();
/* Disable all the KBI pins */
for (i = 0; i < KBI_MAX_PINS_PER_PORT; i++)
{
sKBIConfig.sPin[i].bEn = 0;
}
sKBIConfig.sBits.bMode = KBI_MODE_EDGE_ONLY;
sKBIConfig.sPin[0].bEdge = KBI_FALLING_EDGE_LOW_LEVEL;
sKBIConfig.sBits.bIntEn = 1;
sKBIConfig.sPin[0].bEn = 1;
KBI_Init(KBI0, &sKBIConfig);
KBI_Init(KBI1, &sKBIConfig);
KBI_SetCallback(KBI0, &KBI0_Task);
KBI_SetCallback(KBI1, &KBI1_Task);
/* echo chars received from terminal */
GPIO_Init(GPIOA, GPIO_PTB2_MASK, GPIO_PinOutput);
/* set PTB2 output 0 */
GPIO_PinClear(GPIO_PTB2);
}
void RTC_Task(void)
{
if(dangWeix>0)
dangWeix--;
if(waittimeHOU>0)
waittimeHOU--;
if(waittime>0)
waittime--;
else if(maiChongCiShu>0){
FGPIO_Toggle(FGPIOA, GPIO_PTB2_MASK);
maiChongCiShu--;
waittimeHOU=1000;
}else
FGPIO_Write(FGPIOA,0);
}
void KBI0_Task(void)
{
// LED2_Toggle();
if((waittime+maiChongCiShu+waittimeHOU)==0){
maiChongCiShu=dangWei*2+5;
waittime=256;
}
}
//DangWei,0-7,show By Led
//LED2,LED0,LED1=gao,zhong,di
void KBI1_Task(void)
{
if(dangWeix==0){
dangWei=(dangWei+1)%8;
dangWeix=1120;
if(dangWei&1)
LED1_On();
else
LED1_Off();
if(dangWei&2)
LED0_On();
else
LED0_Off();
if(dangWei&4)
LED2_On();
else
LED2_Off();
}
}
/********************************************************************/
点焊机程序写好了,本来很简单。不过按键没硬件消抖,搞了好几次延迟 |