Example #1
0
// Write on display duty cycle for Both Motors, 1st line on LCD
void showMotorInfo(){
	
	char buffer[20];
	LCDGotoXY(0,0);
	sprintf(buffer, "%04i %04i",dutyL, dutyR);
	LCDPutString(buffer);
}
Example #2
0
void main(void) {
  /* put your own code here */
  EnableInterrupts;
  LCDInit();
  LCDPutString("XLNX");



int8_t a;

  for(;;) {} /* wait forever */
  /* please make sure that you never leave this function */
}
Example #3
0
File: Logic.c Project: moeabbas/lfr
// Count distance traveled in pulses and show on display.
void test(){

	char buffer[20];	
	int pulseCountL = 0;
	int pulseCountR = 0;

	while(1){
		if(getSensorUpdateFlag()){

			pulseCountL += getSensorMotorL();
			pulseCountR += getSensorMotorR();
		
			LCDGotoXY(0,0);
			sprintf(buffer, "%04i %04i %04i",pulseCountL,pulseCountR, (pulseCountL-pulseCountR));
			LCDPutString(buffer);
			
			readFloorSensors();
			clearSensorUpdateFlag();
		}
	}
}
int mjpegPause(int id)
{
	int seekBytes, media_data_totalBytes, diff;
	int ret = RET_PLAY_NORM, curX, prevX = 0;
	int duration = media.video.duration / media.video.timeScale;
	int swHoldCnt, media_data_denom;
	int time = duration * (float)((float)*pv_src.videoStcoCount / (float)video_stco.numEntry);
	char timeStr[20];

	LCD_SetRegion(0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1);

	pcf_typedef pcf;
	pcf.dst_gram_addr = (uint32_t)frame_buffer;
	pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565;
	pcf.size = 12;
	pcf.color = WHITE;
	pcf.colorShadow = GRAY;
	pcf.alphaSoftBlending = 1;
	pcf.enableShadow = 1;
	pcf_font.metrics.hSpacing = 2;

	drawBuff = (drawBuff_typedef*)cursorRAM;

	char s[10];
	SPRINTF(s, "%d/%d", id, fat.fileCnt - 1);
	LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1);
	LCDPutString(s, &pcf);

	mjpeg_touch.resynch = 1;
	mjpegTouch(id, *pv_src.videoStcoCount);
	mjpeg_touch.resynch = 0;

	LCDPutIcon(4, 100, 12, 12, pause_icon_12x12, pause_icon_12x12_alpha);
	LCDPutIcon(UI_POS_X, UI_POS_Y, 120, 14, seekbar_120x14, seekbar_120x14_alpha);

	drawBuff->navigation_loop.x = 140;
	drawBuff->navigation_loop.y = UI_POS_Y;
	drawBuff->navigation_loop.width = 18;
	drawBuff->navigation_loop.height = 14;
	LCDStoreBgImgToBuff(drawBuff->navigation_loop.x, drawBuff->navigation_loop.y, \
						drawBuff->navigation_loop.width, drawBuff->navigation_loop.height, drawBuff->navigation_loop.p);

	Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode);

	drawBuff->posision.width = 12;
	drawBuff->posision.height = 12;
	drawBuff->posision.x = UI_POS_X + 1;
	drawBuff->posision.y = UI_POS_Y + 1;
	prevX = UI_POS_X + 1;
	LCDStoreBgImgToBuff(prevX, drawBuff->posision.y, \
						drawBuff->posision.width, drawBuff->posision.height, drawBuff->posision.p);

	DRAW_SEEK_CIRCLE((float)time / (float)duration , seek_circle_12x12);

	DRAW_MOV_TIME_STR();

	DRAW_MOV_REMAIN_TIME_STR();

	LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING);

	int pause_flag = 0;
	if(LCDStatusStruct.waitExitKey == PLAY_PAUSE || LCDStatusStruct.waitExitKey == PLAY_LOOP_MODE)
	{
		pause_flag = 1;
		LCDStatusStruct.waitExitKey = 1;
	}
extern int8_t vol;
	while(1){
		switch(LCDStatusStruct.waitExitKey)
		{
		case 0:
			return RET_PLAY_STOP;
			break;
		case VOL_UP:
			vol = ++vol < 6 ? vol : 6;
//			wm8731_left_headphone_volume_set(121 + vol);
			LCDStatusStruct.waitExitKey = 1;
			break;
		case VOL_DOWN:
			vol = --vol > -121 ? vol : -121;
//			wm8731_left_headphone_volume_set(121 + vol);
			LCDStatusStruct.waitExitKey = 1;
			break;
		case PLAY_PAUSE:
			ret = 1;
			LCDStatusStruct.waitExitKey = 1;
			goto PAUSE_EXIT;
			break;
		case PLAY_LOOP_MODE:
			Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode = ++music_control.b.navigation_loop_mode % 5);
			LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_NOBLOCKING);
			LCDStatusStruct.waitExitKey = 1;
			break;
		case PLAY_SW_HOLD_LEFT:
			media_data_totalBytes = video_stco.numEntry;
			seekBytes = *pv_src.videoStcoCount;
			media_data_denom = 100;
			swHoldCnt = SW_HOLD_CNT_VAL;
			while(HAL_GPIO_ReadPin(SW_PUSH_LEFT_PORT, SW_PUSH_LEFT_PIN) == GPIO_PIN_RESET){
				diff = seekBytes - media_data_totalBytes / media_data_denom;
				if(diff < 0){
					seekBytes = 2;
				} else {
					seekBytes += -media_data_totalBytes / media_data_denom;
				}

				mjpegTouch(id, seekBytes);

				HAL_Delay(20);
				media_data_denom = 100 / (++swHoldCnt / SW_HOLD_CNT_VAL);
			}
			ret = 1;
			LCDStatusStruct.waitExitKey = 1;
			if(!pause_flag){
				goto PAUSE_EXIT;
			}
			break;
		case PLAY_SW_HOLD_RIGHT:
			media_data_totalBytes = video_stco.numEntry;
			seekBytes = *pv_src.videoStcoCount;
		 	media_data_denom = 100;
			swHoldCnt = SW_HOLD_CNT_VAL;
			while(HAL_GPIO_ReadPin(SW_PUSH_RIGHT_PORT, SW_PUSH_RIGHT_PIN) == GPIO_PIN_RESET){
				if((seekBytes + media_data_totalBytes / media_data_denom) > media_data_totalBytes){
					continue;
				}
				seekBytes += media_data_totalBytes / media_data_denom;
				mjpegTouch(id, seekBytes);

	 	 		HAL_Delay(20);
	 	 		media_data_denom = 100 / (++swHoldCnt / SW_HOLD_CNT_VAL);
			}
			ret = 1;
			LCDStatusStruct.waitExitKey = 1;
			if(!pause_flag){
				goto PAUSE_EXIT;
			}
			break;
		case PLAY_NEXT:
			ret = RET_PLAY_NEXT;
			return ret;
		case PLAY_PREV:
			ret = RET_PLAY_PREV;
			return ret;
			break;
		default:
			break;
		}
		HAL_Delay(1);
	}

PAUSE_EXIT:
	if(media.video.width != LCD_WIDTH || media.video.height != LCD_HEIGHT){
		LCD_DrawSquare(0, 0, LCD_WIDTH, media.video.startPosY, BLACK);
		LCD_DrawSquare(0, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK);
		LCD_DrawSquare(media.video.startPosX + media.video.width, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK);
		LCD_DrawSquare(0, media.video.startPosY + media.video.height, LCD_WIDTH, LCD_HEIGHT - (media.video.startPosY + media.video.height), BLACK);
	}

	LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	while((SpiLcdHandle.State != HAL_SPI_STATE_READY)){};

	memset(dac_intr.buff, '\0', dac_intr.bufferSize);

	LCD_SetRegion(media.video.startPosX, media.video.startPosY, media.video.startPosX + media.video.width - 1, media.video.startPosY + media.video.height - 1);

	HAL_I2S_DMAResume(&haudio_i2s);
	DMA_SOUND_IT_ENABLE;

    return ret;
}
USE MENU

#ifdef USE_MENU

void mjpegTouch(int id, uint32_t pointed_chunk) // ? ? ? ? ?  ?  ? ?  ? ?        Touch pen interrupt processing
{
	uint32_t firstChunk, prevChunk, prevSamples, samples, totalSamples = 0, jFrameOffset;
	MY_FILE fp_stsc, fp_stsz, fp_stco, fp_frame, fp_frame_cp;
	uint8_t atombuf[12];

	raw_video_typedef raw;

	memcpy((void*)&fp_stsc, (void*)&video_stsc.fp, sizeof(MY_FILE));
	memcpy((void*)&fp_stsz, (void*)&video_stsz.fp, sizeof(MY_FILE));
	memcpy((void*)&fp_stco, (void*)&video_stco.fp, sizeof(MY_FILE));
	//DANI memcpy((void*)&fp_frame, (void*)&fp_global, sizeof(MY_FILE));

//		debug.printf("\r\npointed_chunk:%d video_stco.numEntry:%d", pointed_chunk, video_stco.numEntry);

	prevChunk = getSampleSize(atombuf, 12, &fp_stsc); // firstChunk samplesPerChunk sampleDescriptionID ????firstChunk?prevChunk?
	prevSamples = getAtomSize(&atombuf[4]); // ????samplesPerChunk?prevSamples?
	firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ????firstChunk

	while(1){
		if(prevChunk <= pointed_chunk && firstChunk >= pointed_chunk){
			samples = (firstChunk - pointed_chunk) * prevSamples;
			totalSamples += (pointed_chunk - prevChunk) * prevSamples;
			break;
		}
		samples = (firstChunk - prevChunk) * prevSamples;
		totalSamples += samples;

		prevChunk = firstChunk; // ???firstChunk?prevChunk?
		prevSamples = getSampleSize(atombuf, 8, &fp_stsc); // samplesPerChunk sampleDescriptionID
		firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ??firstChunk
	}

	my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR);
	jFrameOffset = getSampleSize(atombuf, 4, &fp_stco);

	memcpy((void*)&fp_stco, (void*)&video_stco.fp, sizeof(MY_FILE));
	my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR); //

	my_fseek(&fp_frame, jFrameOffset, SEEK_SET);

	memcpy((void*)&fp_frame_cp, (void*)&fp_frame, sizeof(MY_FILE));
	//DANI  my_fseek(&fp_frame, raw.frame_size, SEEK_CUR);

	*pv_src.firstChunk = firstChunk;
	*pv_src.prevChunk = prevChunk;
	*pv_src.prevSamples = prevSamples;
	*pv_src.samples = samples;
	*pv_src.totalSamples = totalSamples;
	*pv_src.videoStcoCount = pointed_chunk + 1;

	memcpy((void*)pv_src.fp_video_stsc, (void*)&fp_stsc, sizeof(MY_FILE));
	memcpy((void*)pv_src.fp_video_stsz, (void*)&fp_stsz, sizeof(MY_FILE));
	memcpy((void*)pv_src.fp_video_stco, (void*)&fp_stco, sizeof(MY_FILE));
	memcpy((void*)pv_src.fp_frame, (void*)&fp_frame, sizeof(MY_FILE));


	// Sound
	memcpy((void*)&fp_stsc, (void*)&sound_stsc.fp, sizeof(MY_FILE));
	memcpy((void*)&fp_stsz, (void*)&sound_stsz.fp, sizeof(MY_FILE));
	memcpy((void*)&fp_stco, (void*)&sound_stco.fp, sizeof(MY_FILE));
	//DANI memcpy((void*)&fp_frame, (void*)&fp_global, sizeof(MY_FILE));

//		debug.printf("\r\npointed_chunk:%d video_stco.numEntry:%d", pointed_chunk, video_stco.numEntry);

	prevChunk = getSampleSize(atombuf, 12, &fp_stsc); // firstChunk samplesPerChunk sampleDescriptionID ????firstChunk?prevChunk?
	prevSamples = getAtomSize(&atombuf[4]); // ????samplesPerChunk?prevSamples?
	firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ????firstChunk

	totalSamples = 0;
	while(1){
		if(prevChunk <= pointed_chunk && firstChunk >= pointed_chunk){
			samples = (firstChunk - pointed_chunk) * prevSamples;
			totalSamples += (pointed_chunk - prevChunk) * prevSamples;
			break;
		}
		samples = (firstChunk - prevChunk) * prevSamples;
		totalSamples += samples;

		prevChunk = firstChunk; // ???firstChunk?prevChunk?
		prevSamples = getSampleSize(atombuf, 8, &fp_stsc); // samplesPerChunk sampleDescriptionID
		firstChunk = getSampleSize(atombuf, 4, &fp_stsc); // ??firstChunk
	}
	my_fseek(&fp_stco, (pointed_chunk - 1) * 4, SEEK_CUR);

	*ps_src.firstChunk = firstChunk;
	*ps_src.prevChunk = prevChunk;
	*ps_src.prevSamples = prevSamples;
	*ps_src.samples = samples;
	*ps_src.soundStcoCount = pointed_chunk;

	memcpy((void*)ps_src.fp_sound_stsc, (void*)&fp_stsc, sizeof(MY_FILE));
	memcpy((void*)ps_src.fp_sound_stsz, (void*)&fp_stsz, sizeof(MY_FILE));
	memcpy((void*)ps_src.fp_sound_stco, (void*)&fp_stco, sizeof(MY_FILE));

	if(mjpeg_touch.resynch){
		return;
	}
        
        
/* //DANI
	if(media.video.width != LCD_WIDTH || media.video.height != LCD_HEIGHT){
		LCD_DrawSquare(0, 0, LCD_WIDTH, media.video.startPosY, BLACK);
		LCD_DrawSquare(0, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK);
		LCD_DrawSquare(media.video.startPosX + media.video.width, media.video.startPosY, (LCD_WIDTH - media.video.width) / 2, media.video.height, BLACK);
		LCD_DrawSquare(0, media.video.startPosY + media.video.height, LCD_WIDTH, LCD_HEIGHT - (media.video.startPosY + media.video.height), BLACK);
	}
*/
	int v;
	for(v = 0;v < media.video.height;v++)
        {
		//(&frame_buffer[media.video.startPosX + v * LCD_WIDTH + media.video.startPosY * LCD_WIDTH], 2, media.video.width, &fp_frame_cp);
               // read_file (FIL  *file, uint8_t *buf, uint32_t sizeofbuf)
	}


	int curX, prevX, duration = (int)((float)media.video.duration / (float)media.video.timeScale + 0.5f);
	int time = duration * (float)*pv_src.videoStcoCount / (float)video_stco.numEntry;
	char timeStr[20];

	LCDPutIcon(4, 100, 12, 12, pause_icon_12x12, pause_icon_12x12_alpha);
	LCDPutIcon(UI_POS_X, UI_POS_Y, 120, 14, seekbar_120x14, seekbar_120x14_alpha);

	drawBuff->navigation_loop.x = 140;
	drawBuff->navigation_loop.y = UI_POS_Y;
	drawBuff->navigation_loop.width = 18;
	drawBuff->navigation_loop.height = 14;
	LCDStoreBgImgToBuff(drawBuff->navigation_loop.x, drawBuff->navigation_loop.y, \
						drawBuff->navigation_loop.width, drawBuff->navigation_loop.height, drawBuff->navigation_loop.p);

	Update_Navigation_Loop_Icon(drawBuff, music_control.b.navigation_loop_mode);

	drawBuff->posision.width = 12;
	drawBuff->posision.height = 12;
	drawBuff->posision.x = UI_POS_X + 1;
	drawBuff->posision.y = UI_POS_Y + 1;
	prevX = UI_POS_X + 1;
	LCDStoreBgImgToBuff(prevX, drawBuff->posision.y, \
						drawBuff->posision.width, drawBuff->posision.height, drawBuff->posision.p);

	DRAW_SEEK_CIRCLE((float)time / (float)duration , seek_active_circle_12x12);

	pcf_typedef pcf;
	pcf.dst_gram_addr = (uint32_t)frame_buffer;
	pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565;
	pcf.size = 12;
	pcf.color = WHITE;
	pcf.colorShadow = GRAY;
	pcf.alphaSoftBlending = 1;
	pcf.enableShadow = 1;
	pcf_font.metrics.hSpacing = 2;

	char s[10];
	SPRINTF(s, "%d/%d", id, fat.fileCnt - 1);
	LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1);
	LCDPutString(s, &pcf);

	DRAW_MOV_TIME_STR();

	DRAW_MOV_REMAIN_TIME_STR();

	LCD_FRAME_BUFFER_Transmit(LCD_DMA_TRANSMIT_BLOCKING);
}
Example #6
0
void HandleEvent()
{
	U8 RefrashCounter;
	EVENT Evt = Player.Event;

	ClearEvent();
	switch(Evt)
	{
		case EV_NULL:
			break;

		case EV_DREQ:
			if(BufCnt>=32)
			{
				VS_Send32Byte(DataPtr);
				DataPtr += 32;
				BufCnt -= 32;
			}
			else
				GenerateEvent(EV_BUFEMPTY);
			break;

		case EV_BUFEMPTY:
			if(f_eof(Player.currFile))
				GenerateEvent(EV_END);
			else
			{
				f_read((Player.currFile), DataBuf, BUFSIZE, &BufCnt);
				DataPtr = DataBuf;
			}
			RefrashCounter++;
			if(RefrashCounter == Refrash){
			LCDClean();
			LCDPutString("Now Playing #");
			LCDPutUInt(Player.SongNum);}
			break;

		case EV_NEXT:
			VS_CancelDecoding();
			if(++Player.SongNum  > Player.TotalSongNum)
				Player.SongNum= 1;
			scan_files_open (Player.currFile,"/",Player.SongNum);
			GenerateEvent(EV_BUFEMPTY);
			RefrashCounter = Reset;
			break;

		case EV_PREVIOUS:
			VS_CancelDecoding();
			if(--Player.SongNum  == 0)
				Player.SongNum= Player.TotalSongNum;
			scan_files_open (Player.currFile,"/",Player.SongNum);
			GenerateEvent(EV_BUFEMPTY);
			RefrashCounter = Reset;
			break;

		case EV_MODE:
			Player.Mode++;
			Player.Mode %= 3;
			SetLED(Player.Mode);
			LCDClean();
			LCDPutString("Mode: ");
			if(Player.Mode==SM_BASS)
			LCDPutString("Bass");
			if(Player.Mode==SM_TREBLE)
			LCDPutString("Treble");
			if(Player.Mode==SM_SONG)
			LCDPutString("Song");
			RefrashCounter = Reset;
			break;

		case EV_BASSTREB:
			VS_SetBassTreble(Player.Bass,Player.Treble);
			LCDClean();
			LCDPutString("Bass: ");
			LCDPutUInt(Player.Bass);
			if(Player.Mode==SM_BASS)
			LCDPutString(" <--");
			LCDChangeLine();
			LCDPutString("Treble: ");
			LCDPutInt(Player.Treble);
			if(Player.Mode==SM_TREBLE)
			LCDPutString(" <--");
			RefrashCounter = Reset;
			break;

		case EV_VOLUME:
			VS_SetVol(Player.Volume);
			LCDClean();
			LCDPutString("Now Playing #");
			LCDPutUInt(Player.SongNum);
			LCDChangeLine();
			LCDPutString("Volume: ");
			LCDPutUInt(((ADC0+48)/41));//0~100
			LCD_DataWrite('%');
			RefrashCounter = Reset;
			break;

		case EV_PAUSE:
//			ConsoleWrite("Paused.\n");
			Player.Status = PS_PAUSED;
			LCDClean();
			LCDPutString("|| Paused....");
			break;

		case EV_PLAY:
//			ConsoleWrite("Resume Playing...\n");
			Player.Status = PS_PLAYING;
			LCDClean();
			LCDPutString("Now Playing: #");
			LCDPutUInt(Player.SongNum);
			break;

		case EV_END:
			Player.Event = EV_NEXT;
			LCDClean();
			LCDPutString("End.");
			break;

		default:
			break;
	}
}
int PlaySound(int id)
{
	int i, duration, curX, prevX, media_data_totalBytes;
	volatile int ret = RET_PLAY_NORM;

	uint32_t *dst32p;
	uint8_t *outbuf;
	char str[10];

	WAVEFormatStruct wav;
	WAVEFormatHeaderStruct wavHeader;
	WAVEFormatChunkStruct wavChunk;

	MY_FILE *infile;

	char timeStr[20];


	if(!(infile = my_fopen(id))){
		ret = RET_PLAY_STOP;
		goto EXIT_WAV;
	}

	my_fread(&wavHeader, 1, sizeof(WAVEFormatHeaderStruct), infile);

	debug.printf("\r\n\n[WAVE]");

	if(strncmp(wavHeader.headStrRIFF, "RIFF", 4) != 0){
		debug.printf("\r\nNot contain RIFF chunk");
		ret = RET_PLAY_STOP;
		goto EXIT_WAV;
	}

	debug.printf("\r\nFile Size:%d", wavHeader.fileSize);

	if(strncmp(wavHeader.headStrWAVE, "WAVE", 4) != 0){
		debug.printf("\r\nThis is not WAVE file.");
		ret = RET_PLAY_STOP;
		goto EXIT_WAV;
	}

	int restBytes = wavHeader.fileSize;

	while(1){ // loop until format chunk is found
		my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile);
		if(strncmp(wavChunk.chunkfmt, "fmt ", 4) == 0){
			break;
		}
		memset(str, '\0', sizeof(str));
		debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
		debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);
		restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);
		if(restBytes <= 0){
			debug.printf("\r\nNot Found Format Chunk.");
			ret = RET_PLAY_STOP;
			goto EXIT_WAV;
		}
		my_fseek(infile, wavChunk.chunkSize, SEEK_CUR);
	}

	my_fread(&wav, 1, sizeof(WAVEFormatStruct), infile);
	my_fseek(infile, wavChunk.chunkSize - sizeof(WAVEFormatStruct), SEEK_CUR);

	restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);

	while(1){ // loop until data chunk is found
		my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile);
		if(strncmp(wavChunk.chunkfmt, "data", 4) == 0){
			break;
		}
		memset(str, '\0', sizeof(str));
		debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
		debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);
		restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);
		if(restBytes <= 0){
			debug.printf("\r\nNot Found Format Chunk.");
			ret = RET_PLAY_STOP;
			goto EXIT_WAV;
		}
		my_fseek(infile, wavChunk.chunkSize, SEEK_CUR);
	}

	memset(str, '\0', sizeof(str));
	debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
	debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);

	debug.printf("\r\n\nformatID:%d", wav.formatID);
	debug.printf("\r\nNum Channel:%d", wav.numChannel);
	debug.printf("\r\nSampling Rate:%d", wav.sampleRate);
	debug.printf("\r\nData Speed:%d", wav.dataSpeed);
	debug.printf("\r\nBlock Size:%d", wav.blockSize);
	debug.printf("\r\nBit Per Sample:%d", wav.bitPerSample);
	debug.printf("\r\nBytes Wave Data:%d", wavChunk.chunkSize);

	if(wav.formatID != 1){
		debug.printf("\r\nthis media is not a PCM.");
		ret = RET_PLAY_STOP;
		goto EXIT_WAV;
	}

	int seekBytesSyncWord = infile->seekBytes;

	media_data_totalBytes = wavChunk.chunkSize;
	duration = wavChunk.chunkSize / wav.dataSpeed;
	setStrSec(timeStr, duration);
	debug.printf("\r\nplay time:%s", timeStr);

	LCDFadeIn(2, music_bgimg_160x128);
	memcpy((void*)frame_buffer, (void*)music_bgimg_160x128, sizeof(frame_buffer));

	short xTag = 5, yTag = 50, disp_limit = 150, strLen;

	pcf_typedef pcf;
	pcf.dst_gram_addr = (uint32_t)frame_buffer;
	pcf.pixelFormat = PCF_PIXEL_FORMAT_RGB565;
	pcf.size = 16;
	pcf.color = WHITE;
	pcf.colorShadow = BLACK;
	pcf.alphaSoftBlending = 1;
	pcf.enableShadow = 1;
	pcf_font.metrics.hSpacing = 2;


	uint8_t strNameLFN[80];

	if(setLFNname(strNameLFN, id, LFN_WITHOUT_EXTENSION, sizeof(strNameLFN))){
		strLen = LCDGetStringLFNPixelLength(strNameLFN, pcf.size);
		if((xTag + strLen) < LCD_WIDTH){
			disp_limit = LCD_WIDTH - 16;
		} else {
			disp_limit = LCD_WIDTH - 16;
			yTag -= 12;
		}
		LCD_GotoXY(xTag, yTag);
		LCDPutStringLFN(xTag, disp_limit - 1, 3, strNameLFN, &pcf);
	} else {
		char strNameSFN[9];
		memset(strNameSFN, '\0', sizeof(strNameSFN));
		setSFNname(strNameSFN, id);
		LCD_GotoXY(xTag, yTag);
		LCDPutString(strNameSFN, &pcf);
	}


	if(settings_group.music_conf.b.musicinfo && (wav.bitPerSample > 16) && (wav.sampleRate >= 48000)){
		pcf.size = 12;
		pcf.color = RED;
		pcf.colorShadow = WHITE;
		LCD_GotoXY(5, 19);
		LCDPutString("Hi-Res ", &pcf);

		LCDPutString(wav.bitPerSample == 24 ? "24bit" : "32bit", &pcf);
	}

	pcf.size = 12;
	pcf.color = WHITE;
	pcf.colorShadow = GRAY;

	char s[30], s1[10];
	SPRINTF(s, "%d/%d", id, fat.fileCnt - 1);
	LCD_GotoXY(5, MUSIC_INFO_POS_Y + 1);
	if(settings_group.music_conf.b.musicinfo){
		strcat(s, "  WAV ");
		SPRINTF(s1, "%.1fM ", (float)(wav.numChannel * wav.bitPerSample * wav.sampleRate) / 1000000.0f);
		strcat(s, s1);
		SPRINTF(s1, "%dkHz", (int)(wav.sampleRate / 1000));
		strcat(s, s1);
	}
	LCDPutString(s, &pcf);

	uint16_t SOUND_BUFFER[12288];
	uint8_t SOUND_BUFFER_24BIT[((sizeof(SOUND_BUFFER) / 2) / sizeof(uint32_t)) * 3];

    dac_intr.fp = infile;
	dac_intr.buff = (uint8_t*)SOUND_BUFFER;
    if(wav.bitPerSample <= 16){
    	dac_intr.bufferSize = sizeof(SOUND_BUFFER) / 2;
    } else {
    	dac_intr.bufferSize = sizeof(SOUND_BUFFER);
    }

    volatile int SoundDMAHalfBlocks = (dac_intr.bufferSize / (sizeof(int16_t) * 2)) / 2;

	FFT_Struct_Typedef FFT;
	FFT.bitPerSample = wav.bitPerSample;
	FFT.ifftFlag = 0;
	FFT.bitReverseFlag = 1;
	FFT.length = 16;
	FFT.samples = (dac_intr.bufferSize / (sizeof(int16_t) * wav.numChannel) / 2) / 1;
	if(wav.numChannel < 2){
		FFT.samples >>= 1;
	}
int PlaySound(int id)
{
	time.flags.enable = 0;
	TouchPenIRQ_Disable();
	TOUCH_PINIRQ_DISABLE;
	touch.func = touch_empty_func;

	int i;
	uint32_t *pabuf;
	uint8_t *outbuf;
	char str[10];

	int totalSec, remainTotalSec, media_data_totalBytes;
	int curX = 0, prevX = 0;
	volatile int ret = RET_PLAY_NORM;

	NVIC_InitTypeDef NVIC_InitStructure;
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;

	void *putCharTmp = '\0', *putWideCharTmp = '\0';
	drawBuff_typedef dbuf, *drawBuff;
	drawBuff = &dbuf;
	_drawBuff = drawBuff;

	char timeStr[20];

	WAVEFormatStruct wav;
	WAVEFormatHeaderStruct wavHeader;
	WAVEFormatChunkStruct wavChunk;

	MY_FILE *infile, file_covr;


	if(!(infile = my_fopen(id))){
		ret = RET_PLAY_STOP;
		goto EXIT_WAV;
	}

	my_fread(&wavHeader, 1, sizeof(WAVEFormatHeaderStruct), infile);

	debug.printf("\r\n\n[WAVE]");

	if(strncmp(wavHeader.headStrRIFF, "RIFF", 4) != 0){
		debug.printf("\r\nNot contain RIFF chunk");
		ret = RET_PLAY_STOP;
		goto END_WAV;
	}

	debug.printf("\r\nFile Size:%d", wavHeader.fileSize);

	if(strncmp(wavHeader.headStrWAVE, "WAVE", 4) != 0){
		debug.printf("\r\nThis is not WAVE file.");
		ret = RET_PLAY_STOP;
		goto END_WAV;
	}

	int restBytes = wavHeader.fileSize;

	while(1){ // loop until format chunk is found
		my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile);
		if(strncmp(wavChunk.chunkfmt, "fmt ", 4) == 0){
			break;
		}
		memset(str, '\0', sizeof(str));
		debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
		debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);
		restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);
		if(restBytes <= 0){
			debug.printf("\r\nNot Found Format Chunk.");
			ret = RET_PLAY_STOP;
			goto END_WAV;
		}
		my_fseek(infile, wavChunk.chunkSize, SEEK_CUR);
	}

	my_fread(&wav, 1, sizeof(WAVEFormatStruct), infile);
	my_fseek(infile, wavChunk.chunkSize - sizeof(WAVEFormatStruct), SEEK_CUR);

	restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);

	while(1){ // loop until data chunk is found
		my_fread(&wavChunk, 1, sizeof(WAVEFormatChunkStruct), infile);
		if(strncmp(wavChunk.chunkfmt, "data", 4) == 0){
			break;
		}
		memset(str, '\0', sizeof(str));
		debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
		debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);
		restBytes = restBytes - wavChunk.chunkSize - sizeof(WAVEFormatChunkStruct);
		if(restBytes <= 0){
			debug.printf("\r\nNot Found Format Chunk.");
			ret = RET_PLAY_STOP;
			goto END_WAV;
		}
		my_fseek(infile, wavChunk.chunkSize, SEEK_CUR);
	}

	music_src_p.curX = &curX;
	music_src_p.prevX = &prevX;
	music_src_p.media_data_totalBytes = &media_data_totalBytes;
	music_src_p.totalSec = &totalSec;
	music_src_p.drawBuff = drawBuff;
	music_src_p.fp = infile;

	LCDPutBgImgMusic();

	file_covr.clusterOrg = 0;

	dispArtWork(&file_covr);
	LCDPutIcon(0, 155, 320, 80, music_underbar_320x80, music_underbar_320x80_alpha);

	memset(str, '\0', sizeof(str));
	debug.printf("\r\n\nchunkType:%s", strncpy(str, wavChunk.chunkfmt, sizeof(wavChunk.chunkfmt)));
	debug.printf("\r\nchunkSize:%d", wavChunk.chunkSize);

	debug.printf("\r\n\nformatID:%d", wav.formatID);
	debug.printf("\r\nNum Channel:%d", wav.numChannel);
	debug.printf("\r\nSampling Rate:%d", wav.sampleRate);
	debug.printf("\r\nData Speed:%d", wav.dataSpeed);
	debug.printf("\r\nBlock Size:%d", wav.blockSize);
	debug.printf("\r\nBit Per Sample:%d", wav.bitPerSample);
	debug.printf("\r\nBytes Wave Data:%d", wavChunk.chunkSize);

	uint32_t data_offset = infile->seekBytes;

	if(wav.bitPerSample != 16){
		debug.printf("\r\n**Bit Per Sample must be 16bit**");
		debug.printf("\r\ndata offset:%d", data_offset);
		ret = RET_PLAY_STOP;
		goto END_WAV;
	}

	int xTag = 110, yTag = 87, disp_limit = 300, strLen;

	putCharTmp = LCD_FUNC.putChar;
	putWideCharTmp = LCD_FUNC.putWideChar;

	if(!pcf_font.c_loaded){
		LCD_FUNC.putChar = PCFPutChar16px;
		LCD_FUNC.putWideChar = PCFPutChar16px;
	} else {
		LCD_FUNC.putChar = C_PCFPutChar16px;
		LCD_FUNC.putWideChar = C_PCFPutChar16px;
	}
	disp_limit = 288;

	uint8_t strNameLFN[80];
	if(setLFNname(strNameLFN, id, LFN_WITHOUT_EXTENSION, sizeof(strNameLFN))){
		strLen = LCDGetStringLFNPixelLength(strNameLFN, 16);
		if((xTag + strLen) < LCD_WIDTH){
			disp_limit = LCD_WIDTH - 1;
		} else {
			disp_limit = LCD_WIDTH - 20;
			yTag -= 10;
		}
		LCDGotoXY(xTag + 1, yTag + 1);
		LCDPutStringLFN(xTag + 1, disp_limit, 2, strNameLFN, BLACK);
		LCDGotoXY(xTag, yTag);
		LCDPutStringLFN(xTag, disp_limit - 1, 2, strNameLFN, WHITE);
	} else {
		char strNameSFN[9];
		memset(strNameSFN, '\0', sizeof(strNameSFN));
		setSFNname(strNameSFN, id);
		LCDGotoXY(xTag + 1, yTag + 1);
		LCDPutString(strNameSFN, BLACK);
		LCDGotoXY(xTag, yTag);
		LCDPutString(strNameSFN, WHITE);
	}

	LCD_FUNC.putChar = putCharTmp;
	LCD_FUNC.putWideChar = putWideCharTmp;

	char s[20];
	SPRINTF((char*)s, "%d/%d", id, fat.fileCnt - 1);
	LCDGotoXY(21, MUSIC_INFO_POS_Y + 1);
	LCDPutString((char*)s, BLACK);
	LCDGotoXY(20, MUSIC_INFO_POS_Y);
	LCDPutString((char*)s, WHITE);

	if(settings_group.music_conf.b.musicinfo){
		LCDGotoXY(71, MUSIC_INFO_POS_Y + 1);
		LCDPutString("WAV", BLACK);
		LCDGotoXY(70, MUSIC_INFO_POS_Y);
		LCDPutString("WAV", WHITE);

		LCDGotoXY(111, MUSIC_INFO_POS_Y + 1);
		LCDPutString(wav.numChannel == 2 ? "Stereo" : "Mono", BLACK);
		LCDGotoXY(110, MUSIC_INFO_POS_Y);
		LCDPutString(wav.numChannel == 2 ? "Stereo" : "Mono", WHITE);

		SPRINTF(s, "%1.2fMbps", (float)(wav.dataSpeed * 8) / 1000000.0f);
		LCDGotoXY(171, MUSIC_INFO_POS_Y + 1);
		LCDPutString(s, BLACK);
		LCDGotoXY(170, MUSIC_INFO_POS_Y);
		LCDPutString(s, WHITE);

		SPRINTF(s, "%dHz", (int)wav.sampleRate);
		LCDGotoXY(241, MUSIC_INFO_POS_Y + 1);
		LCDPutString(s, BLACK);
		LCDGotoXY(240, MUSIC_INFO_POS_Y);
		LCDPutString(s, WHITE);
	}


	putCharTmp = LCD_FUNC.putChar;
	putWideCharTmp = LCD_FUNC.putWideChar;

	if(!pcf_font.c_loaded){
		LCD_FUNC.putChar = PCFPutCharCache;
		LCD_FUNC.putWideChar = PCFPutCharCache;

		extern uint16_t cursorRAM[];

		PCFSetGlyphCacheStartAddress((void*)cursorRAM);
		PCFCachePlayTimeGlyphs(12);
	} else {
		LCD_FUNC.putChar = C_PCFPutChar;
		LCD_FUNC.putWideChar = C_PCFPutChar;
	}

	media_data_totalBytes = wavChunk.chunkSize;
	totalSec = wavChunk.chunkSize / wav.dataSpeed;
	setStrSec(timeStr, totalSec);
	debug.printf("\r\nplay time:%s", timeStr);

	// time elapsed
	drawBuff->timeElapsed.x = 14;
	drawBuff->timeElapsed.y = 188;
	drawBuff->timeElapsed.width = 50;
	drawBuff->timeElapsed.height = 13;
	LCDStoreBgImgToBuff(drawBuff->timeElapsed.x, drawBuff->timeElapsed.y, \
			            drawBuff->timeElapsed.width, drawBuff->timeElapsed.height, drawBuff->timeElapsed.p);

	// time remain
	drawBuff->timeRemain.x = totalSec < 6000 ? 268 : 260;
	drawBuff->timeRemain.y = 188;
	drawBuff->timeRemain.width = 50;
	drawBuff->timeRemain.height = 13;
	LCDStoreBgImgToBuff(drawBuff->timeRemain.x, drawBuff->timeRemain.y, \
			            drawBuff->timeRemain.width, drawBuff->timeRemain.height, drawBuff->timeRemain.p);

	drawBuff->posision.x = 0;
	drawBuff->posision.y = 168;
	drawBuff->posision.width = 16;
	drawBuff->posision.height = 16;
	LCDStoreBgImgToBuff(drawBuff->posision.x, drawBuff->posision.y, \
						drawBuff->posision.width, drawBuff->posision.height, drawBuff->posision.p);

	drawBuff->navigation.x = 142;
	drawBuff->navigation.y = 189;
	drawBuff->navigation.width = 32;
	drawBuff->navigation.height = 32;
	LCDStoreBgImgToBuff(drawBuff->navigation.x, drawBuff->navigation.y, \
			            drawBuff->navigation.width, drawBuff->navigation.height, drawBuff->navigation.p);

	drawBuff->fft_analyzer_left.x = FFT_ANALYZER_LEFT_POS_X;
	drawBuff->fft_analyzer_left.y = FFT_ANALYZER_LEFT_POS_Y;
	drawBuff->fft_analyzer_left.width = 32;
	drawBuff->fft_analyzer_left.height = 32;
	LCDStoreBgImgToBuff(drawBuff->fft_analyzer_left.x, drawBuff->fft_analyzer_left.y, \
			            drawBuff->fft_analyzer_left.width, drawBuff->fft_analyzer_left.height, drawBuff->fft_analyzer_left.p);

	drawBuff->fft_analyzer_right.x = FFT_ANALYZER_RIGHT_POS_X;
	drawBuff->fft_analyzer_right.y = FFT_ANALYZER_RIGHT_POS_Y;
	drawBuff->fft_analyzer_right.width = 32;
	drawBuff->fft_analyzer_right.height = 32;
	LCDStoreBgImgToBuff(drawBuff->fft_analyzer_right.x, drawBuff->fft_analyzer_right.y, \
			            drawBuff->fft_analyzer_right.width, drawBuff->fft_analyzer_right.height, drawBuff->fft_analyzer_right.p);

	drawBuff->navigation_loop.x = 277;
	drawBuff->navigation_loop.y = 207;
	drawBuff->navigation_loop.width = 24;
	drawBuff->navigation_loop.height = 18;
	LCDStoreBgImgToBuff(drawBuff->navigation_loop.x, drawBuff->navigation_loop.y, \
			            drawBuff->navigation_loop.width, drawBuff->navigation_loop.height, drawBuff->navigation_loop.p);
	switch(navigation_loop_mode){
	case NAV_ONE_PLAY_EXIT: // 1 play exit
		LCDPutIcon(_drawBuff->navigation_loop.x, _drawBuff->navigation_loop.y, _drawBuff->navigation_loop.width, _drawBuff->navigation_loop.height, \
				navigation_bar_24x18, navigation_bar_24x18_alpha);
		break;
	case NAV_PLAY_ENTIRE: // play entire in directry
		LCDPutIcon(_drawBuff->navigation_loop.x, _drawBuff->navigation_loop.y, _drawBuff->navigation_loop.width, _drawBuff->navigation_loop.height, \
				navigation_entire_loop_24x18, navigation_entire_loop_24x18_alpha);
		break;
	case NAV_INFINITE_PLAY_ENTIRE: // infinite play entire in directry
		LCDPutIcon(_drawBuff->navigation_loop.x, _drawBuff->navigation_loop.y, _drawBuff->navigation_loop.width, _drawBuff->navigation_loop.height, \
				navigation_infinite_entire_loop_24x18, navigation_infinite_entire_loop_24x18_alpha);
		break;
	case NAV_INFINITE_ONE_PLAY: // infinite 1 play
		LCDPutIcon(_drawBuff->navigation_loop.x, _drawBuff->navigation_loop.y, _drawBuff->navigation_loop.width, _drawBuff->navigation_loop.height, \
				navigation_one_loop_24x18, navigation_one_loop_24x18_alpha);
		break;
	case NAV_SHUFFLE_PLAY: // shuffle
		LCDPutIcon(_drawBuff->navigation_loop.x, _drawBuff->navigation_loop.y, _drawBuff->navigation_loop.width, _drawBuff->navigation_loop.height, \
				navigation_shuffle_24x18, navigation_shuffle_24x18_alpha);
		break;
	default:
		break;
	}

	LCDPutIcon(drawBuff->navigation.x, drawBuff->navigation.y, \
			   drawBuff->navigation.width, drawBuff->navigation.height, \
			   navigation_pause_patch_32x32, navigation_pause_patch_32x32_alpha);


	/* Update Bass Boost Icon */
	drawBuff->bass_boost.x = 10;
	drawBuff->bass_boost.y = 3;
	drawBuff->bass_boost.width = 24;
	drawBuff->bass_boost.height = 18;
	LCDStoreBgImgToBuff(drawBuff->bass_boost.x, drawBuff->bass_boost.y, \
			            drawBuff->bass_boost.width, drawBuff->bass_boost.height, drawBuff->bass_boost.p);
	Update_Bass_Boost_Icon(bass_boost_mode);

	/* Update Reverb Effect Icon */
	drawBuff->reverb_effect.x = 60;
	drawBuff->reverb_effect.y = 2;
	drawBuff->reverb_effect.width = 24;
	drawBuff->reverb_effect.height = 18;
	LCDStoreBgImgToBuff(drawBuff->reverb_effect.x, drawBuff->reverb_effect.y, \
			            drawBuff->reverb_effect.width, drawBuff->reverb_effect.height, drawBuff->reverb_effect.p);
	Update_Reverb_Effect_Icon(reverb_effect_mode);

	/* Update Vocal Canceler Icon */
	drawBuff->vocal_cancel.x = 107;
	drawBuff->vocal_cancel.y = 5;
	drawBuff->vocal_cancel.width = 24;
	drawBuff->vocal_cancel.height = 18;
	LCDStoreBgImgToBuff(drawBuff->vocal_cancel.x, drawBuff->vocal_cancel.y, \
			            drawBuff->vocal_cancel.width, drawBuff->vocal_cancel.height, drawBuff->vocal_cancel.p);
	Update_Vocal_Canceler_Icon(vocal_cancel_mode);


	uint8_t SOUND_BUFFER[9216];
    dac_intr.fp = infile;
    dac_intr.buff = SOUND_BUFFER;
    dac_intr.bufferSize = sizeof(SOUND_BUFFER);
    int SoundDMAHalfBlocks = (dac_intr.bufferSize / (sizeof(int16_t) * 2)) / 2;

	int loop_icon_touched = 0, loop_icon_cnt = 0, boost = 0;
	int delay_buffer_filled = 0, DMA_Half_Filled = 0;


	float *fabuf, *fbbuf;
	float *float_buf = (float*)mempool;
	int fbuf_len = dac_intr.bufferSize / 2;

	memset(float_buf, '\0', fbuf_len * sizeof(float));

	/* variables for reverb effect
	 * delay_buffer is allocated in CCM.(64KB)
	 * Maximum length Stereo 16bit(4bytes/sample)
	 * 0.371s@44100Hz 0.341s@48000Hz */
	delay_buffer_typedef delay_buffer;
	delay_buffer.ptr = (uint32_t*)CCM_BASE;
	delay_buffer.size = 65536 / sizeof(uint32_t);
	delay_buffer.idx = 0;

	IIR_Filter_Struct_Typedef IIR;
	IIR.delay_buffer = &delay_buffer;
	IIR.sbuf_size = dac_intr.bufferSize / 2;
	IIR.num_blocks = SoundDMAHalfBlocks;
	IIR.fs = wav.sampleRate;
	IIR.number = bass_boost_mode;
	boost = bass_boost_mode;
	IIR_Set_Params(&IIR);

	REVERB_Struct_Typedef RFX;
	RFX.delay_buffer = &delay_buffer;
	RFX.num_blocks = SoundDMAHalfBlocks;
	RFX.fs = wav.sampleRate;
	RFX.number = reverb_effect_mode;
	REVERB_Set_Prams(&RFX);

	FFT_Struct_Typedef FFT;
	FFT.ifftFlag = 0;
	FFT.bitReverseFlag = 1;
	FFT.length = 64;
	FFT.samples = dac_intr.bufferSize / ((wav.bitPerSample / 8) * wav.numChannel) / 2;
	if(wav.numChannel < 2){
		FFT.samples >>= 1;
	}
Example #9
0
void main(void) {
  
  INIT_SLK_PBs;
  INIT_SLK_LEDs;
  INIT_APSLK_LEDs;
  INIT_SLK_POT;
  INIT_SLK_BUZZER; //Only Available when interfaced to Project Board
  INIT_SLK_FRTimer;
  LCDInit();       //Only Available when interfaced to Project Board
  SCIInit();
  
  EnableInterrupts;
  
   LCDPutString("  FSL\n");
   LCDPutString(" HCS12\n");
   SCITransmitStr("\r\rFreescale HCS12 Demo\n\r");     
  for(;;) {
    
    /* PB1 = LED1 */
    if (SLK_PB1 == 0)
    {
      SLK_LED1 = ON;	       //LED 1 Active
      APSLK_LED1 = !SLK_LED1;  //Follow the Project Board LEDs
      LCDPutString(" LED 1\n");
      LCDPutString("ENABLED\n");
    } 
    /* PB2 = LED2 */
    else if(SLK_PB2 == 0)
    {
      SLK_LED2 = ON;         //LED 2 Active
      APSLK_LED2 = !SLK_LED2;  //Follow the Project Board LEDs
      LCDPutString(" LED 2\n");
      LCDPutString("ENABLED\n");
      }
      /*Buzzer and PWM */ 
    else if(SLK_PB3 == 0)
    {
      LCDPutString("BUZZER\n");
      LCDPutString("ENABLED\n");
      TCTL2_OM0 = 1;
      SLK_BUZZER_VOLUME = SLK_POT +1;      
      } 
      /*The Bouncing Switch*/
    else if(SLK_PB4 == 0)
    {
     SCITransmitStr("\r\rHello World!!  \r");
     LCDPutString(" Hello\n");
     LCDPutString(" World\n");
      }
      /*The Blinking LED*/ 
    else if(PAFLG_PAOVF == 1)    //Polling Free Timer Overflow flag   
      {
      SLK_LED3 = !SLK_LED3;
      APSLK_LED3 = SLK_LED3;      
      PAFLG_PAOVF = 1;              //Clearing the Overflow flag
      TIMER_COUNT = 0x7fff;         //Setting count to 0x7FFF to increase flash rate.
     }
    else{   
      TCTL2_OM0 = 0;
      SLK_LED4 = ON;
      SLK_LED2 = OFF;
      SLK_LED1 = OFF;
      APSLK_LED4 = !SLK_LED4;
      APSLK_LED2 = !SLK_LED2;
      APSLK_LED1 = !SLK_LED1;
      LCDPutString("  FSL\n");
      LCDPutString(" HCS12\n");
   
    }
       } /* wait forever */
}