//PROJECT : EA21
//IC : SAMSUNG S3C9454
#include "ioS3C9454.h"
//自己編寫,注意const ?
//****************************
//PINdefine 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 MOV ingData(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
#defineSILenceKey 0x40
//*********************************
//variable define area
//*********************************
unsigned char VolData[7][5]; //如果上電前,即使按鍵按下,也不識別,那么,初始化為0就可以,
//如果需要識別,就要處理??
unsigned char Key_OldStatus; //表示前一時刻鍵的狀態(tài),1表示按下,0表示彈起
unsigned char RepeatKey_Status; //表示重鍵的狀態(tài),1表示有,0表示無,對應七個鍵
unsigned char Key_NowPushStatus; //表示現在鍵按下的狀態(tài)
#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.1A/Dinput, 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 MOV ingData(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;