?? main.c
字號:
//===============================================================
//
// The information contained herein is the exclusive property of
// Sunplus Technology Co. And shall not be distributed, reproduced,
// or disclosed in whole in part without prior written permission.
//
// (C) COPYRIGHT 2001 SUNPLUS TECHNOLOGY CO.
// ALL RIGHTS RESERVED
//
// The entire notice above must be reproduced on all authorized copies.
//
//==============================================================
//============================================================
// 工程名稱: TrafficLight.spj
// 功能描述: 模擬交通燈控制實驗
// IDE環(huán)境: SUNPLUS u'nSPTM IDE 1.8.4(or later)
//
// 涉及的庫: (a) C-Lib: (CMacroB100.lib);
// (b) sacmv25.lib
//
// 組成文件:
// main.c
// hardware.asm
// sram.asm
// sys.asm
// spce061.inc
// spce061v004.h
// s480.inc
// s480.h
// unSPMACRO.h
// TrafficLight.h
//
// Note:
// 常量和變量的定義請參考 TrafficLight.h
//
/*
61板與模擬交通燈控制板的接線方法
61板 交通燈板
+5V VCC
GND VSS
IOA4 S_L
IOA5 S_S
IOA6 S_R
IOA7 N_L
IOA8 N_S
IOA9 N_R
IOA10 E_L
IOA11 E_S
IOA12 E_R
IOA13 W_L
IOA14 W_S
IOA15 W_R
IOB0 CS0
IOB1 CS1
IOB2 CS2
IOB3 CS3
IOB4 CS4
IOB5 CS5
IOB8 IO-0
IOB9 IO-1
IOB10 IO-2
IOB11 IO-3
IOB12 IO-4
IOB13 IO-5
IOB14 IO-6
IOB15 IO-7
*/
//
// 日期: 2004-4-29
//===============================================
#include "SPCE061V004.h"
#include "unSPMACRO.h"
#include "TrafficLight.h"
void MyDelay(unsigned int Ret);
main()
{
IO_Initial();
uiStatus = C_Status_Normal;
uiStatus_Normal = C_1_Green;
uiShowCnt = ui_SN_GreenLight;
uiShi=uiShowCnt/10; // 取倒計時顯示的十位
uiGe=uiShowCnt%10; // 取倒計時顯示的個位
while(1)
{
if(g_uiResetIO == 20)
{
IO_Initial();
g_uiResetIO = 0;
}
uiKey = GetKeyValue(); // 取得61板的按鍵鍵值
switch(uiStatus)
{
case C_Status_Normal: // 正常運行狀態(tài)
Run_Normal();
break;
case C_Status_Emergency: // 緊急狀態(tài)
Run_Emergency();
break;
case C_Status_Setup: // 設(shè)置狀態(tài)
Run_Setup();
break;
case C_Status_Query: // 查詢狀態(tài)
Run_Query();
break;
default:
break;
}
}
}
//========================================================================================================
//函數(shù): MyDelay
//語法:void MyDelay(unsigned int Ret)
//描述:延時函數(shù)
//參數(shù):Ret,延時的計數(shù)值
//返回:無
//========================================================================================================
void MyDelay(unsigned int Ret)
{
while(Ret--);
}
//========================================================================================================
//函數(shù): Run_Normal
//語法:void Run_Normal(void)
//描述:正常運行函數(shù)
//參數(shù):無
//返回:無
//========================================================================================================
//在正常運行狀態(tài),按下Key1會進(jìn)入緊急狀態(tài),按下Key2會進(jìn)入設(shè)置狀態(tài),按下Key3會進(jìn)入查詢狀態(tài)。
void Run_Normal(void) // 正常運行
{
//按鍵處理
switch(uiKey)
{
case C_Key1:
uiStatus = C_Status_Emergency;
break;
case C_Key2:
uiStatus = C_Status_Setup;
break;
case C_Key3:
uiStatus = C_Status_Query;
break;
case C_S_L:
uiSouthCnt_L++; //來自南邊左轉(zhuǎn)車流量加一
break;
case C_S_S:
uiSouthCnt_S++; //來自南邊直行車流量加一
break;
case C_S_R:
uiSouthCnt_R++; //來自南邊右轉(zhuǎn)車流量加一
break;
case C_W_L:
uiWeastCnt_L++; //來自西邊左轉(zhuǎn)車流量加一
break;
case C_W_S:
uiWeastCnt_S++; //來自西邊直行車流量加一
break;
case C_W_R:
uiWeastCnt_R++; //來自西邊右轉(zhuǎn)車流量加一
break;
case C_N_L:
uiNorthCnt_L++; //來自北邊左轉(zhuǎn)車流量加一
break;
case C_N_S:
uiNorthCnt_S++; //來自北邊直行車流量加一
break;
case C_N_R:
uiNorthCnt_R++; //來自北邊右轉(zhuǎn)車流量加一
break;
case C_E_L:
uiEastCnt_L++; //來自東邊左轉(zhuǎn)車流量加一
break;
case C_E_S:
uiEastCnt_S++; //來自東邊直行車流量加一
break;
case C_E_R:
uiEastCnt_R++; //來自東邊右轉(zhuǎn)車流量加一
break;
default :
break;
}
//顯示控制
if(uiQuarterSecondCnt>=2)
{
uiQuarterSecondCnt = 0;
uiFlash_Flag ^= 0xffff;
ShowControl();
}
}
//========================================================================================================
//函數(shù): Run_Emergency
//語法:void Run_Emergency(void)
//描述:緊急狀態(tài)函數(shù)
//參數(shù):無
//返回:無
//========================================================================================================
//在緊急狀態(tài)下,四面都是紅燈。按下Key3鍵返回正常運行狀態(tài)。
unsigned int Cnt=0;
void Run_Emergency(void) // 緊急狀態(tài)
{
Cnt++;
if(uiKey == C_Key3)
{
uiStatus = C_Status_Normal;
uiStatus_Normal = C_1_Green;
uiShowCnt = ui_SN_GreenLight;
uiShi=uiShowCnt/10; // 取倒計時顯示的十位
uiGe=uiShowCnt%10; // 取倒計時顯示的個位
}
if(Cnt%6000==1)
PlayS480(C_JINGDI);
*P_IOB_Data = C_ALL_Red;
}
//========================================================================================================
//函數(shù): Run_Setup
//語法:void Run_Setup(void)
//描述:設(shè)置狀態(tài)函數(shù)
//參數(shù):無
//返回:無
//========================================================================================================
//在設(shè)置狀態(tài)下,按下Key1開始設(shè)置南北的紅燈時間,按下Key2設(shè)置南北的綠燈時間,按下Key3返回正常運行狀態(tài)。
void Run_Setup(void) // 設(shè)置狀態(tài)
{
if(uiKey == C_Key1)
{
ui_SN_RedLight++;
if(ui_SN_RedLight>99)
ui_SN_RedLight = 20;
uiShowCnt = ui_SN_RedLight;
}
else if(uiKey == C_Key2)
{
ui_SN_GreenLight++;
if(ui_SN_GreenLight>99)
ui_SN_GreenLight = 20;
uiShowCnt = ui_SN_GreenLight;
}
else if(uiKey == C_Key3)
{
uiStatus = C_Status_Normal;
uiStatus_Normal = C_1_Green;
}
uiShi=uiShowCnt/10; // 取倒計時顯示的十位
uiGe=uiShowCnt%10; // 取倒計時顯示的個位
}
//========================================================================================================
//函數(shù): Run_Query
//語法:void Run_Query(void)
//描述:查詢狀態(tài)函數(shù)
//參數(shù):無
//返回:無
//========================================================================================================
//在查詢狀態(tài),按下Key1播報南北路口的車流量,按下Key2播報東西路口的車流量,按下Key3返回正常運行狀態(tài)。
void Run_Query(void) // 查詢狀態(tài)
{
if(uiKey == C_Key1)
{
//南北車流量的計算
uiSouthCnt = uiEastCnt_L + uiNorthCnt_S + uiWeastCnt_R;
uiNorthCnt = uiWeastCnt_L + uiSouthCnt_S + uiEastCnt_R;
//播放往南走的車流量
Play2Number(uiSouthCnt,C_NAN);
//播放往北走的車流量
Play2Number(uiNorthCnt,C_BEI);
}
else if(uiKey == C_Key2)
{
//東西車流量的計算
uiEastCnt = uiNorthCnt_L + uiWeastCnt_S + uiSouthCnt_R;
uiWeastCnt = uiSouthCnt_L + uiEastCnt_S + uiNorthCnt_R;
//播放往東走的車流量
Play2Number(uiEastCnt,C_DONG);
//播放往西走的車流量
Play2Number(uiWeastCnt,C_XI);
}
else if(uiKey == C_Key3)
{
uiStatus = C_Status_Normal;
uiStatus_Normal = C_1_Green;
}
}
//========================================================================================================
//函數(shù): PlayS480
//語法:void PlayS480(int Index)
//描述:播音函數(shù)
//參數(shù):Index,播音的索引地址
//返回:無
//========================================================================================================
void PlayS480(int Index)
{
SACM_S480_Initial(1);
SACM_S480_Play(Index, 3, 3);
while((SACM_S480_Status()&0x0001) != 0)
{
SACM_S480_ServiceLoop();
*P_Watchdog_Clear = C_WDTCLR;
}
SACM_S480_Stop();
}
//========================================================================================================
//函數(shù): Play2Number
//語法:void Play2Number(unsigned int uiNumber,unsigned int uiDirection)
//描述:播音函數(shù)
//參數(shù):uiNumber,要播報的兩位數(shù);uiDirection,播音的索引地址
//返回:無
//========================================================================================================
void Play2Number(unsigned int uiNumber,unsigned int uiDirection)
{
unsigned int uiPlayShi,uiPlayGe;
PlayS480(C_ZHUYI);
uiPlayShi = uiNumber/10; //取十位
uiPlayGe = uiNumber%10; //取個位
PlayS480(C_WANG);
PlayS480(uiDirection);
PlayS480(C_ZOU);
if(uiPlayShi)
{
PlayS480(uiPlayShi);
PlayS480(C_10);
if(uiNumber%10)
PlayS480(uiPlayGe);
}
else
PlayS480(uiPlayGe);
}
//========================================================================================================
//函數(shù): ShowControl
//語法:void ShowControl(void)
//描述:顯示函數(shù)
//參數(shù):無
//返回:無
//========================================================================================================
void ShowControl(void)
{
uiShowCntFlag++;
switch(uiStatus_Normal)
{
case C_1_Green://
//對于雙色LED
uiE_2ColorLED = C_1_E_Green;
uiW_2ColorLED = C_1_W_Green;
uiS_2ColorLED = C_1_S_Green;
uiN_2ColorLED = C_1_N_Green;
//對于數(shù)碼管
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -