?? ex11.c
字號:
//
// example 11: S480 on Mini OS
// description: The program uses a semaphore to synchronize decoding task and interrupt playing task
// keyboard scan uses a mailbox to save key value.
// author: Taiyun Wang
// date: 2003/2/22
///////////////////////////////////////////////////////////////////////////
#include "sposvar.h"
#include "spos.h"
#include "s480.h"
#define MaxSpeechNum 3
#define MaxVolume 15
void CDecoderTask();
void shiftLED();
void ScanKeyTask();
int t1stack[20]; //Task 1 stack
int t2stack[20]; //Task 2 stack
int t3stack[100]; //task 3 stack
HEvent hDecoderSem; //Event handle
HEvent hKeyMbox; //Event handle
volatile unsigned int *P_IOA_DATA=(unsigned int*)(0x7000);
volatile unsigned int *P_IOB_BUFFER =(unsigned int*)(0x7006); //Port B data register
volatile unsigned int *P_IOB_DIR =(unsigned int*)(0x7007); //Port B direction register
volatile unsigned int *P_IOB_ATTRIB = (unsigned int*)(0x7008); //Port B attribute register
int main()
{
SpSInit();
hKeyMbox = SpSMboxCreate(0); //Create mialbox
SpSTaskCreate(CDecoderTask,0,t3stack+99,3); //Create task of decoder
SpSTaskCreate(shiftLED,0,t2stack+19,2); //Create task of LED
SpSTaskCreate(ScanKeyTask,0,t1stack+19,1); //Create task of scan keyboard
SpSStart(); //Start OS kernel
}
void ScanKeyTask( )
{
unsigned int bDown=0;
unsigned int bkeepDown=0;
unsigned int iTemp;
while(1)
{
iTemp = *P_IOA_DATA;
iTemp &=0x00FF;
if(iTemp == 0) {
bDown = 0;
bkeepDown = 0;
}
else {
if(bDown == 0)
bDown = 1;
else if (bkeepDown == 0) {
SpSMboxPost(hKeyMbox,&iTemp); //Send scan keyboard value
bkeepDown = 1;
}
}
SpSTimeDly(2);
}
}
void shiftLED( )
{
unsigned int i = 1;
unsigned int j;
while(1)
{
*P_IOB_DIR = 0XFFFF;
*P_IOB_ATTRIB = 0XFFFF;
*P_IOB_BUFFER = i;
i <<= 1;
if(i == 0x0100)
i = 1;
SpSTimeDly(20);
}
}
void CDecoderTask()
{
int Ret = 0;
long Addr;
int Mode;
void * pKey;
int Key = 0;
int SpeechIndex = 0;
int VolumeIndex = 8;
unsigned int i=0;
Mode = Auto;
SpSSetVector(FIQ_TMA_VEC,F_FIQ_Service_SACM_S480); //Set interrupt function
hDecoderSem = SpSSemCreate(1); //Create semaphore
while(Mode == Auto){
Ret = System_Initial();
Ret = SACM_S480_Initial(Auto);
SACM_S480_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
while(1) {
pKey=SpSMboxAccept(hKeyMbox); //Read key
if(pKey != (void*)0)
Key = *(unsigned int*)pKey;
else
Key = 0;
switch(Key) {
case 0x01:
SACM_S480_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
break;
case 0x02:
SACM_S480_Stop();
break;
case 0x04:
SACM_S480_Pause();
break;
case 0x08:
SACM_S480_Resume();
break;
case 0x10:
VolumeIndex++;
if(VolumeIndex > MaxVolume)
VolumeIndex = MaxVolume;
SACM_S480_Volume(VolumeIndex);
break;
case 0x20:
if(VolumeIndex == 0)
VolumeIndex = 0;
else
VolumeIndex--;
SACM_S480_Volume(VolumeIndex);
break;
case 0x40:
if( ++SpeechIndex == MaxSpeechNum)
SpeechIndex = 0;
SACM_S480_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
break;
case 0x80:
if( --SpeechIndex < 0)
SpeechIndex = MaxSpeechNum-1;
SACM_S480_Play(SpeechIndex,DAC1+DAC2, Ramp_UpDn_On);
break;
default:
break;
}
SACM_S480_ServiceLoop();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -