//PROJECT : EA21
//IC : SAMSUNG S3C9454
#include "ioS3C9454.h"
//自己编写,注意const ??
//****************************
// pin define area
//*****************************
#define CONTROL_RelayLight (P0&0x04) //P0.2
#define SET_RelayLight (P0|=0x04)
#define CLR_RelayLight (P0&=0xFB)
#define CONTROL_RelayCyclone (P0&0x08) //P0.3
#define SET_RelayCyclone (P0|=0x08)
#define CLR_RelayCyclone (P0&=0xF7)
//*********************************
//function declare area
//*********************************
void io_init(void);
void delay(void);
void AD_CONV(void);
void MOVingData(void);
void JudgingKey(void);
void DealKey(void);
void DealDelayClose(void);
void DealDelayLock(void);
void DealBuzz(void);
void DealLockMotor(void);
void ram_init(void);
//*********************************
//constant define area
//*********************************
#define DelayKey 0x01
#define PowerKey 0x02
#define CycloneKey 0x04
#define LightKey 0x08
#define LockKey 0x10
#define BigWindKey 0x20
#define SilenceKey 0x40
//*********************************
//variable define area
//*********************************
unsigned char VolData[7][5]; //如果上电前,即使按键按下,也不识别,那么,初始化为0就可以,
//如果需要识别,就要处理??
unsigned char Key_OldStatus; //表示前一时刻键的状态,1表示按下,0表示弹起
unsigned char RepeatKey_Status; //表示重键的状态,1表示有,0表示无,对应七个键
unsigned char Key_NowPushStatus; //表示现在键按下的状态
#define CONTROL_LockStatus (SYS_Status&0x01)
#define SET_LockStatus (SYS_Status|=0x01)
#define CLR_LockStatus (SYS_Status&=0xFE)
//*********************************
//table define area
//*********************************
//code unsigned char AnalogChannel[7]={0x00,0x00,0x01,0x01,0x02,0x02,0x03};
//code unsigned char ADChannel[7]={0x05,0x15,0x05,0x15,0x05,0x15,0x15};
//*********************************
//SUB PROGRAM ROUTINE
//*********************************
void io_init(void)
{
CLKCON = 0x18; // cpu clock is non-divided clock
BTCON = 0xA3; // disable watch-dog, select fxx/4096 for basic timer clock
//btcon = 0x02, enable watch-dog
SP = 0xC0; // sp <= c0h
FLAGS = 0x00; // clear flags
STOPCON = 0x00; // disable STOP instruction
P0CONH = 0xAA;
P0CONL = 0xAF; // P0.0-P0.1 A/D input, P0.2-P0.7 push-pull output
P1CON = 0x0A; // P1.0-P1.1 push-pull output
P2CONH = 0x4A; //
P2CONL = 0xAA; // P2.0-P2.6 push-pull output
T0DATA = 0x03; //3,200,000/256*3=4166, 250us
T0CON = 0x0A; //
}
void delay(void)
{
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
}
void MOVingData(void)
{
unsigned char i,j;
for(i=0;i<7;i++)
{
for(j=0;j<4;j++)
{
VolData[i][j]=VolData[i][j+1];
}
}
}
void AD_CONV(void)
{
unsigned char i;
unsigned char AD_Flag,AD_WAIT;
for(i=0x00;i<0x07;i++)
{
P1=AnalogChannel[i];
ADCON=ADChannel[i];
delay();
for(AD_WAIT=0x00;AD_WAIT<0xff;AD_WAIT++)
{
AD_Flag=0x00;
if(ADCON&0x08)
{
AD_Flag=0x01;
break;
}
}
if(AD_Flag)
VolData[i][4]=ADDATAH;
}
}
void DealDelayClose(void)
{
if(CONTROL_DelayClose)
{
if(DelayCloseTime>=Interval_5M)
{
CloseAllLED;
CLR_RelayLight;
CLR_RelayCyclone;
CLR_RelayBigWind;
CLR_RelaySilence;
SYS_Status=0x00;
}
}
}
void DealDelayLock(void)
{
if(CONTROL_DelayLock)
{
if(DelayLockTime>=Interval_3S)
{
CLR_DelayLock;
if(CONTROL_LockStatus)
{
CLR_LedLock;
CLR_LockStatus;
}
else
{
SET_LedLock;
SET_LockStatus;
}
}
}
}
void DealBuzz(void)
{
if(CONTROL_BuzzStatus)
{
if(BuzzTime>=BuzzInterval)
{
CLR_BuzzStatus;
BuzzTime=0x00;
}
}
}
void ram_init(void)
{
unsigned char i;
unsigned char *j=(unsigned char*)0x00;
for(i=208;i!=0;i--,j++)
*j=0;
}
__interrupt void TimeInterrupt(void)
{
if((T0CON&0x02)&&(T0CON&0x01))
{
if(CONTROL_BuzzStatus)
{
if(CONTROL_BuzzPulse)
{
CLR_BUZOUT1;
CLR_BuzzPulse;
}
else
{
SET_BUZOUT1;
SET_BuzzPulse;
}
}
BasicIntTime++;
if(BasicIntTime>=BasicInterval)
{
BasicIntTime=0x00;
KeyScanTime++;
LockMotorTime++;
DelayLockTime++;
if(DelayLockTime>=Interval_3S)
{
DelayLockTime=0x00;
DelayCloseTime++;
}
}
}
T0CON=T0CON&0xf6;
}
void main(void)
{
io_init();
ram_init();
// btcon = 0x02;
{
MOVingData();
AD_CONV();
JudgingKey();
DealKey();
DealDelayClose();
DealDelayLock();
DealBuzz();
DealLockMotor();
}
}