예제 #1
0
static void init_adc()
{
    LCDclr();
    LCDGotoXY(3,0); 
    LCDstring((uint8_t *)"Initing...",10);
    AD7793_Reset();

    if(!AD7793_Init())
    {
        LCDclr();
        LCDGotoXY(2,0);
        LCDstring((uint8_t *)"ADC Error!",10);     
        return;
    }
    
    LCDGotoXY(0,1); 
    LCDstring((uint8_t *)"S1...",5);
    adc_init_channel(AD7793_CH_AIN1P_AIN1M);
    LCDstring((uint8_t *)"OK  S2...",9);
    adc_init_channel(AD7793_CH_AIN2P_AIN2M);    
    LCDstring((uint8_t *)"OK",2);
    adc_current_channel = AD7793_CH_AIN1P_AIN1M;
    adc_change_channel_and_trigger_delay(adc_current_channel);
    LCDclr();
}
예제 #2
0
//Display the Temperature on the LCD
void displayTemp(void* args) 
{	
	//String constants
	const uint8_t LCDTemp[5] = "TEMP\0";
	
	//LCD locations
	const uint8_t T_FOOD_REF_LOC = 0;
	const uint8_t T_FOOD = 5;
	
	uint8_t tempRefLen;
	uint8_t tempLen;
	float localTemp;
	float localTempRef;
	
	//String buffers
	uint8_t LCDTempRef[4];
	uint8_t LCDTempMeas[5];
	
	//flags indicating whether a variable needs to be updated
	uint8_t updateTempRefRef;
	
	//make local copies of the system parametes
	trtWait(SEM_T_REF);
	localTempRef = waterTempRef;
	trtSignal(SEM_T_REF);
	
	trtWait(SEM_T);
	localTemp = waterTemp;
	trtSignal(SEM_T);
	
	trtWait(SEM_THICKNESS);
	float localThickness = thickness;
	trtSignal(SEM_THICKNESS);
	
	trtWait(SEM_MAT_PROP);
	float localK = k;
	trtSignal(SEM_MAT_PROP);
	
	LCDGotoXY(0,0);
	LCDstring(LCDTemp, 4);
	
	uint32_t rel, dead;
	while(1){
		//trtWait(SEM_T_WATER);
		//trtSignal(SEM_T_WATER);

		
		sprintf(LCDTempMeas, "%f", localTemp);
		LCDGotoXY(0, 0);
		LCDstring(LCDTempMeas, 5);
		
		rel = trtCurrentTime() + SECONDS2TICKS(0.2);
		dead = trtCurrentTime() + SECONDS2TICKS(0.225);
		trtSleepUntil(rel, dead);
	}
}
예제 #3
0
void showClock()
{
    LCDGotoXY(0,0) ;
    showTime() ;
    
    LCDGotoXY(0,1) ;
    showDate() ;
    
    // only show the running time when we arn't selecting a menu
    if (menuFunction == MENU_NONE)
        showRunningTime();
}
예제 #4
0
파일: avr.c 프로젝트: olcai/sommar
void lcd_init(void)
{
  /* setup LCD on portB and display greeting */
  LCDinit(); 
  LCDclr();
  LCDGotoXY(0,0);
  LCDcursorOFF(); 

  LCDstring((uint8_t*)"System online", 13);
  LCDGotoXY(0,1);
  if(config.flags.mode == CONFIG_MODE_BASE)
    LCDstring((uint8_t*)"base", 4);
  else
    LCDstring((uint8_t*)"node", 4);
}
예제 #5
0
void clearPrompt()
{
  next_menu_clear = 0 ;
  menuFunction = MENU_NONE ;
  LCDGotoXY(9,0);
  LCDWriteString("       ");              
}
예제 #6
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);
}
예제 #7
0
//Initialize the LCD
void InitLCD(void){
  LCDinit();  //initialize the display
  LCDcursorOFF();
  LCDclr();        //clear the display
  LCDGotoXY(0,0);
  CopyStringtoLCD(LCDHello, 0, 0);
  CopyStringtoLCD(LCDHello2, 0, 1);
}
예제 #8
0
파일: CharMenu.c 프로젝트: firdanas/tombol
///Clears block with whitespace replacing
void LcdDelete(uint8_t xawal, uint8_t xakhir, uint8_t _Y)
{
	LCDGotoXY(xawal,_Y);
	for (uint8_t i=xawal;i<=xakhir;i++)
	{
		LCDstring((uint8_t*)" ",1);
	}
}
예제 #9
0
//Copies string from flash memory to LCD at x y position
//const uint8_t welcomeln1[] PROGMEM="AVR LCD DEMO\0";
//CopyStringtoLCD(welcomeln1, 3, 1);	
void CopyStringtoLCD(const uint8_t *FlashLoc, uint8_t x, uint8_t y)
{
	uint8_t i;
	LCDGotoXY(x,y);
	for(i=0;(uint8_t)pgm_read_byte(&FlashLoc[i]);i++)
	{
		LCDsendChar((uint8_t)pgm_read_byte(&FlashLoc[i]));
	}
}
예제 #10
0
int main (void){
	usartInit();
	initLCD();
	while (1){
	LCDGotoXY(0,0);
	LCDstring(LCDBuffer, 1);
	}
	return 0;
}
예제 #11
0
파일: system.c 프로젝트: olcai/sommar
void panic(const char* msg)
{
    unsigned char panic_msg[] = "KERNEL PANIC!";
    cli();
    PORTC=0xFF;
    LCDinit(); 
    LCDclr();
    LCDGotoXY(0,0);
    LCDcursorOFF(); 
    LCDstring(panic_msg, sizeof(panic_msg)-1);
    LCDGotoXY(0,1);
    while(*msg)
	LCDsendChar(*(msg++));
    while(1)
    {
        PORTC = ~PORTC;
        _delay_ms(500);
    }
}
예제 #12
0
void showRunningTime()
{
    LCDGotoXY(10,0) ;
    if (runningHours > 1000)
    {
        LCDWriteInt(runningHours / 1000,1);
        LCDData(',') ;
    }
    LCDWriteInt(runningHours % 1000,1);
}
예제 #13
0
void displayAntShort(uint8_t id, const char* name, const char* decor)
{
	uint8_t x = (id * 8);
	uint8_t len = strLen(name);
	x += (6 - len) / 2;
	LCDGotoXY(x,1);
	LCDWriteString(decor);
 	LCDWriteString(name);
	LCDWriteString(decor);
}
예제 #14
0
//Initialize the LCD
void initLCD(){
	LCDinit();	//initialize the display
	LCDcursorOFF();
	LCDclr();				//clear the display
	LCDGotoXY(0,0);
	const uint8_t LCDHelloTop[] PROGMEM = "Water Cooler v9000\0";
	const uint8_t LCDHelloBot[] PROGMEM = "\0";
	CopyStringtoLCD(LCDHelloTop, 0, 0);
	CopyStringtoLCD(LCDHelloBot, 0, 1);
}
예제 #15
0
파일: CharMenu.c 프로젝트: firdanas/tombol
void DrawNumber(uint16_t bil, uint8_t x, uint8_t y,uint8_t _c)
{
	uint8_t pjg;
	char lcdchar[30];
			LCDGotoXY(x,y);
			if (_c!=0)
			{
				
				for (uint8_t i=1; i<=_c; i++)
				{
					LCDstring((uint8_t*)" ",1);
				}
				LCDGotoXY(x,y);
			}
			snprintf(lcdchar,15, "%d",bil);
			pjg = strlen(lcdchar);
			LCDstring((uint8_t*)lcdchar,pjg);
	
}
예제 #16
0
void LCDInit(uint8_t style)
{
	/*****************************************************************
	
	This function Initializes the lcd module
	must be called before calling lcd related functions

	Arguments:
	style = LS_BLINK,LS_ULINE(can be "OR"ed for combination)
	LS_BLINK :The cursor is blinking type
	LS_ULINE :Cursor is "underline" type else "block" type

	*****************************************************************/
	
	//After power on Wait for LCD to Initialize
	_delay_ms(30);
	
	//Set IO Ports
	LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS);
	LCD_E_DDR|=(1<<LCD_E_POS);
	LCD_RS_DDR|=(1<<LCD_RS_POS);
	LCD_RW_DDR|=(1<<LCD_RW_POS);

	LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));
	CLEAR_E();
	CLEAR_RW();
	CLEAR_RS();

	//Set 4-bit mode
	_delay_us(0.3);	//tAS

	SET_E();
	LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was using LCD_DATA_PORT|=0b00100000
	_delay_us(1);
	CLEAR_E();
	_delay_us(1);
	
	//Wait for LCD to execute the Functionset Command
	LCDBusyLoop();                                    //[B] Forgot this delay

	//Now the LCD is in 4-bit mode

	LCDCmd(0b00001100|style);	//Display On
	LCDCmd(0b00101000);			//function set 4-bit,2 line 5x7 dot format

	/* Custom Char */
	LCDCmd(0b01000000);

	uint8_t __i;
	for(__i=0;__i<sizeof(__cgram);__i++)
		LCDData(__cgram[__i]);
	
	LCDGotoXY(0,0);

}
예제 #17
0
void LCDSmartWrite(int x,int y,char *str) {
	int j=0;
 	while(str[j]) {
  		if(x>15) {
    		x=0;
			y++;
   		}

		LCDGotoXY(x,y);
  		LCDData(str[j]);
  		j++;
  		x++;
 	}
}
예제 #18
0
파일: CharMenu.c 프로젝트: firdanas/tombol
void PrintScroll(uint8_t sNum, uint8_t sMax)
{
	uint8_t mulai = 0;
	uint8_t nScroll = 1;
	LcdDelete(0,15,1);
	mulai = 8-(sMax/2);
	LCDGotoXY(mulai,1);
	for (nScroll = 1; nScroll<=sMax; nScroll++)
	{
		if (nScroll == sNum)
		{
			LCDstring((uint8_t*)"#",1);
		}
		else
		{
			LCDstring((uint8_t*)"-",1);
		}
	}
}
예제 #19
0
int main(void)
{
	/* Variables */
	uint16_t ad_value = 0;
    char ad_value_text[8];
	
	init_LCD();
	init_ADC();
	
	DDRD = 0xFF;
	PORTD = 0;
	
    while(1)
    {
		ad_value = read_ADC();
		itoa(ad_value,ad_value_text,10);
		LCDGotoXY(0,1);
		LCDstring((uint8_t*) ad_value_text, (uint8_t) strlen(ad_value_text));
		
    }
}
예제 #20
0
파일: Logic.c 프로젝트: 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();
		}
	}
}
예제 #21
0
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;
	}
예제 #22
0
void LCDPrintLines(char *line1, char *line2){
	LCDClear();
	LCDPrint (line1);
	LCDGotoXY(0, 1);
	LCDPrint (line2);
}
예제 #23
0
void main(void) 
{
    // initialise the RTC communication line
    I2C_Init() ;
    // initialise the LCD display
    LCDInit(LS_NONE);
    // initialise the actual RTC
    DS1307_Init() ;

    //clear the display
    LCDClear();
    
    // read back our running time
    DS1307_readRam(&runningMinutes,0,2) ;
    DS1307_readRam(&runningHours,2,2) ;
    
    LCDWriteString("Starting counter");
    LCDGotoXY(0,1) ;
    LCDWriteString("at ");
    LCDWriteInt(runningHours,1);
    LCDWriteString(":");
    LCDWriteInt(runningMinutes,1);
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;
    __delay_ms(750) ;

    // compensate for our handling on the first run of the readClock routine
    runningMinutes-- ;

    LCDClear();
    // infinite loop, read the clock, display on the LCD, check for the button, and if needed, process the menus
   while(1)
  {       
      readClock();
      
      showClock() ;           
      
      readInputs() ;
      
      if (bButton)
        doMenu();
      else if (state & 0x30)
      {
          // rotate the encoder to select a menu function, well, that was the aim, but encoder reading
          // seems a tad slow or inaccurate.
          //
          // there is a timeout if the button isn't pressed after selecting the menu option
          
          if (state & DIR_CW)
          {
              menuFunction++ ;
              if (menuFunction == MENU_LAST)
                  menuFunction = MENU_NONE ;
          }
          else if (state & DIR_CCW)
          {
              menuFunction-- ;
              if (menuFunction < MENU_NONE)
                  menuFunction = MENU_LAST-1 ;
          }
          
          if (menuFunction != MENU_NONE)
          {
              next_menu_clear = minute * 60 + seconds + 20 ;
              LCDGotoXY(9,0);
              if (menuFunction == MENU_TIME)
                LCDWriteString("Time ?");
              if (menuFunction == MENU_DATE)
                LCDWriteString("Date ?");
          }
          else
              clearPrompt();
      }
      else if (next_menu_clear && ((minute * 60 + seconds) > next_menu_clear))
      {
          clearPrompt();
      }
  }
}
예제 #24
0
void doMenu()
{   
    while(bButton)
        readInputs();
    
    // set the new time
    if (menuFunction == MENU_NONE | menuFunction == MENU_TIME)
    {
        int h,m,s ;
        
        h = hour ;
        m = minute ;
        s = seconds ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Hours");
        
        LCDGotoXY(0,1) ;
        showTime();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                hour++;
                if (hour > 23)
                    hour = 0 ;
            }
            else if (state & DIR_CCW)
            {
                hour--;
                if (hour < 0)
                    hour = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Minutes");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                minute++;
                if (minute > 59)
                    minute = 0 ;
            }
            else if (state & DIR_CCW)
            {
                minute--;
                if (minute < 0)
                    minute = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Seconds");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                seconds++;
                if (seconds > 59)
                    seconds = 0 ;
            }
            else if (state & DIR_CCW)
            {
                seconds--;
                if (seconds < 0)
                    seconds = 0 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showTime();
            }
        }
        
        // save changes
        if (h != hour || m != minute || s != seconds)
        { // we only update the RTC if changes have been made
            h = ((hour / 10) << 4) + hour % 10 ;
            m = ((minute / 10) << 4) + minute % 10 ;
            s = ((seconds / 10) << 4) + seconds % 10 ;

            DS1307_SetTime(h,m,s) ;
            
            runningMinute = minute ;
        }
        
        while(bButton)
            readInputs();
    }
    
    // set the new date
    if (menuFunction == MENU_NONE | menuFunction == MENU_DATE)
    {
        int n,d,m,y ;
        
        n = day ;
        d = date ;
        m = month ;
        y = year ;
        
        LCDClear();
        LCDWriteString(setText);
        LCDWriteString("Year");
        
        LCDGotoXY(0,1) ;
        showDate();

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                year++;
                if (year > 99)
                    year = 0 ;
            }
            else if (state & DIR_CCW)
            {
                year--;
                if (year < 0)
                    date = 99 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();
    
        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Month");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                month++;
                if (month > 12)
                    month = 1 ;
            }
            else if (state & DIR_CCW)
            {
                month--;
                if (!month)
                    month = 12 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Date ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                date++;
                if (date > monthDays[month-1])
                    date = 1 ;
            }
            else if (state & DIR_CCW)
            {
                date--;
                if (date < 0)
                    date = monthDays[month-1] ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }
        
        while(bButton)
            readInputs();

        LCDGotoXY(0,0) ;
        LCDWriteString(setText);
        LCDWriteString("Day  ");

        while(!bButton)
        {
            readInputs();
            
            if (state & DIR_CW)
            {
                day++;
                if (day > 7)
                    day = 1 ;
            }
            else if (state & DIR_CCW)
            {
                day--;
                if (day < 0)
                    day = 7 ;
            }
            
            if (state & 0x30)
            {
                LCDGotoXY(0,1) ;
                showDate();
            }
        }

        if (n != day || d != date || m != month || y != year)
        { // again, we only update the RTC if changes have been made
            n = ((day / 10) << 4) + day % 10 ;
            d = ((date / 10) << 4) + date % 10 ;
            m = ((month / 10) << 4) + month % 10 ;
            y = ((year / 10) << 4) + year % 10 ;

            DS1307_SetDate(n,d,m,y) ;
        }

        
        while(bButton)
            readInputs();
    }
}
예제 #25
0
파일: lcd.c 프로젝트: cillino25/SENSE
void LCDWriteStringXY(uint8_t x, uint8_t y, const char *msg) {
    LCDGotoXY(x, y);
    LCDWriteString(msg);
}
예제 #26
0
int main(void)
{
	//var
	uint8_t answer;
	uint8_t http_respon_data[64];

	//init pa sbg in
	DDRA = 0;
	PORTA = 0xff;

	//init lcd
	LCDinit();

	LCDclr();
	LCDcursorOFF();
	LCDhome();
	
	//init uart
	sim900_init_uart(38400);
	
	//enable isr
	sei();

	LCDGotoXY(0, 0);
	fprintf(&LCDInputOutputStream, "setup modem = %d", sim900_setup(SETUP_WAIT_INFINITE));
	_delay_ms(1000);
	
	while(1)
	{
		//krm sms pa0
		if (bit_is_clear(PINA, PA0))
		{
			_delay_ms(100);
			loop_until_bit_is_set(PINA, PA0);
			
			LCDclr();
			LCDhome();
			fprintf(&LCDInputOutputStream, "open gprs = %d", sim900_gprs_open_connection(
			(const uint8_t*)"internet", (const uint8_t*)" ", (const uint8_t*)" "));
		}
		
		//open gprs
		if (bit_is_clear(PINA, PA1))
		{
			_delay_ms(100);
			loop_until_bit_is_set(PINA, PA1);

			//answer = sim900_gprs_open_bearer((const uint8_t*)"internet", (const uint8_t*)" ", (const uint8_t*)" ");
			//answer = sim900_gprs_open_bearer("internet", " ", " ");
			//answer = sim900_gprs_is_opened();
			//answer = sim900_gprs_closed();
			//answer = sim900_http_get((const uint8_t*)
			//"http://ex4-tech.id.or.id/sim900/data.php", (const uint8_t*)"c=1", 64,
			//http_respon_data);
			answer = sim900_http_send_data(
			HTTP_POST,
			(const uint8_t*)"http://ex4-tech.id.or.id/sim900/data.php",
			(const uint8_t*)"c=1",
			64,
			http_respon_data);
			LCDclr();
			LCDhome();
			fprintf(&LCDInputOutputStream, "post = %d", answer);
			LCDGotoXY(0, 1);
			fprintf(&LCDInputOutputStream, "%s", http_respon_data);
			_delay_ms(5000);
		}


		if (bit_is_clear(PINA, PA2))
		{
			_delay_ms(100);
			loop_until_bit_is_set(PINA, PA2);

			answer = sim900_gprs_close_connection();
			LCDclr();
			LCDhome();
			fprintf(&LCDInputOutputStream, "close gprs = %d", answer);
		}
	}
}
예제 #27
0
파일: vending.c 프로젝트: sureshgh/vending
int main()
{

 char msg[128],pin[10],machine[10],item[10],success[30];
 uint8_t number;
 uint8_t motorCounter=0;

 DDRB=0xff;
 DDRD=0xf8;
 
 DDRC=0xff;
 DDRA=0b11111110;
 PORTA=0b00000001;
 PORTC=0x00;

 sei();

 initLCD();
 _delay_ms(50);
 LCDClear();
 LCDGotoXY(0,0);
 _delay_ms(50);

 if(initGSM())
  LCDPrint("Vending Machine");
 
 LCDGotoXY(0,0);

 sendCommand(ENABLE_TEXT_MODE); //Enable Text Mode

// uint8_t j=0;

 while(1)
  {
   number=isMessageNotification();

   if(number)
    {

	 readMsg(2,msg);
	 LCDGotoXY(0,0);
	 LCDPrint(msg);
	 //extractPinCode(msg,pin);
     //extractMachineCode(msg,machine);
     //extractItemCode(msg,item);
	 
	 //CDGotoXY(1,1);
	
	 if(!strcmp(machine,"vm001"))
	  {

	   //LCDGotoXY(0,0);
	   //LCDPrint("Good one");
	   //j++;
	   //LCDGotoXY(0,1);
	   //LCDData(j+48);
	  
	   /* motorCounter=item[2]-48;
	  
	   if(motorCounter<9)
	    {
	     PORTC=(1<<(motorCounter-1));
		 LCDPrint(product[motorCounter-1]);
		 LCDPrint("                ");
		}
	   else
	    {
	     PORTA|=(1<<PA7);
		 LCDPrint(product[8]);
		}
	  
	   while(!(PINA&(1<<PA0)));
	   
	   LCDGotoXY(1,1);
	   LCDPrint("Completed       ");

		PORTC=0;
		PORTA&=~(1<<PA7);
		
		strcpy(success,pin);
		strcat(success," SUCCESS");*/
		//deleteMsg();
		//_delay_ms(500);
		//sendMsg(pin);
		//_delay_ms(500);

		machine[0]=0;
		item[0]=0;
		pin[0]=0;
	  }
	}
  }
 
 return 0;

}
예제 #28
0
int main (void)
{
    /* Initialize TWI master. */
    TWI_MasterInit(&twiMaster,&TWIF,TWI_MASTER_INTLVL_LO_gc,TWI_BAUDSETTING);
    TWIF.SLAVE.CTRLA=0;  //slave disabled
    //board_init();

    En_RC32M();

    //Enable LowLevel & HighLevel Interrupts
    PMIC_CTRL |= PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm |PMIC_MEDLVLEN_bm;

    PORT_init();
    TimerD0_init();
    TimerC0_init();
    //USARTE0_init();
    //ADCB_init();
    LCDInit();
    //wdt_enable();


    // Globally enable interrupts
    sei();

    LED_Green_Time	= 3000;
    LED_Green_Speed = 500;
    LED_Red_Time	= 3000;
    LED_Red_Speed	= 100;
    LED_White_Time	= 1000;
    LED_White_Speed = 200;
    Buzzer_Time		= 2000;
    Buzzer_Speed	= 150;




    ///////////////////////////////////////////////////////////////////////////////////////////////Begin NRF Initialize
    NRF24L01_L_CE_LOW;       //disable transceiver modes

    SPI_Init();

    _delay_us(10);
    _delay_ms(100);      //power on reset delay needs 100ms
    NRF24L01_L_Clear_Interrupts();
    NRF24L01_L_Flush_TX();
    NRF24L01_L_Flush_RX();
    NRF24L01_L_CE_LOW;
    NRF24L01_L_Init_milad(_TX_MODE, _CH, _2Mbps, Address, _Address_Width, _Buffer_Size, RF_PWR_MAX);
    NRF24L01_L_WriteReg(W_REGISTER | DYNPD,0x01);
    NRF24L01_L_WriteReg(W_REGISTER | FEATURE,0x06);

    NRF24L01_L_CE_HIGH;
    _delay_us(130);
    ///////////////////////////////////////////////////////////////////////////////////////////////END   NRF Initialize

    // Insert application code here, after the board has been initialized.
    while(1)
    {

        LCDGotoXY(0,0);
        sprintf("salam");
        //LCDStringRam(str);
        ////////TWI
        //tx1[0]=Robot_D[RobotID].M1;
        //tx2[0]=Robot_D[RobotID].M2;
        //tx3[0]=Robot_D[RobotID].M3;
        //tx4[0]=Robot_D[RobotID].M4;

        tx1[0]=0x0F;
        tx2[0]=0x12;
        tx3[0]=0x01;
        tx4[0]=0x02;


        //	TWI_MasterWriteRead(&twiMaster,SLAVE1_ADDRESS,&tx1[0],1,3);
        //	TWI_MasterWriteRead(&twiMaster,SLAVE2_ADDRESS,&tx2[0],1,3);
        TWI_MasterWriteRead(&twiMaster,SLAVE3_ADDRESS,&tx3[0],1,3);
        rx3[0]=twiMaster.readData[0];
        if (rx3[0]==1)
        {
            LED_White(ON);
        }

        //	TWI_MasterWriteRead(&twiMaster,SLAVE4_ADDRESS,&tx4[0],1,3);
        /////////////////////


        NRF24L01_L_Write_TX_Buf(Buf_Tx_L, _Buffer_Size);
        NRF24L01_L_RF_TX();
        if (Buf_Rx_L[0]=='f')
        {
            LED_Green_PORT.OUTTGL = LED_Green_PIN_bm;
        }
        _delay_ms(10);
    }
}
예제 #29
0
//**********************************************************
//Entry point and task scheduler loop
int main(void){
   initialize();
  // Check if R (for ReactionMaster) is written. Write default score if not
  if (eeprom_read_byte((uint8_t*)EEPROM_TRUE_ADDR) != 'R'){
    eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,DEFAULT_SCORE);
    eeprom_write_byte((uint8_t*)EEPROM_TRUE_ADDR,'R');
  }

  // main task scheduler loop
  // set LEDs corresponding to state
  // LED7 is used as reaction timer LED
  while(1){
    switch (gameState){
      case INITIAL:
        PORTB = ~0x01; //led0
        break;

      case READY:
        if (!readyDisplayed){
          pressedAndReleased = 0;
          scoreDisplayed = 0;
          PORTB = ~0x02; //led1
          LCDclr();
          LCDGotoXY(0,0);
          CopyStringtoLCD(LCDReady, 0, 0);
          readyDisplayed = 1;
        }
        break;

      case WAITING:
        if (!randomTimeChosen){
          pressedAndReleased = 0;
          readyDisplayed = 0;
          cheatDisplayed = 0;
          cheatState = 0;
          PORTB = ~0x04; //led2
          LCDclr();
          //assign a random time to waitTime
          waitTime = rand() % (RND_MAX - RND_MIN + 1) + 1000;
          randomTimeChosen = 1;
        }
        break;

      case LED_ON:
        if (!ledTurnedOn){
          randomTimeChosen = 0;
          rxnCount = 0;
          PORTB = ~(0x08 | 0x80); //led7 and led3
          // PORTB = ~0x80; // led7
          // turn the buzzer on
          buzzer = 1;
          ledTurnedOn = 1;
        }
        break;

      case DISPLAY:
        if (!scoreDisplayed){
          PORTB = ~0x10; //led4
          // PORTB = ~0x00; // All off

          buzzer = 0;
          pressedAndReleased = 0;
          ledTurnedOn = 0;

          if(rxnCount == 1000) {
            CopyStringtoLCD(LCDTooSlow, 0, 0);
          } else {
            CopyStringtoLCD(LCDScore, 0, 0);
            //Display the player's score
            //eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,rxnCount);
            sprintf(LCDBuffer, "%i", rxnCount);
            LCDGotoXY(7, 0);
            LCDstring(LCDBuffer, strlen(LCDBuffer));
          }
          CopyStringtoLCD(LCDHighScore, 0, 1);
          //Display the high score
          uint16_t highScore = eeprom_read_word((uint16_t*)EEPROM_DATA_ADDR);
          sprintf(LCDBuffer, "%i", highScore);
          LCDGotoXY(11, 1);
          LCDstring(LCDBuffer, strlen(LCDBuffer));
          scoreDisplayed = 1;

          //Store the player's score if it is larger than the current high score
          if (rxnCount < highScore){
            eeprom_write_word((uint16_t*)EEPROM_DATA_ADDR,rxnCount);
          }

        }
        break;

      case CHEAT:
        if (!cheatDisplayed){
          PORTB = ~0x20; //led5
          // PORTB = ~0x00; // All off
          randomTimeChosen = 0;
          cheatState = 0;
          buzzer = 0;
          LCDGotoXY(0, 0);
          CopyStringtoLCD(LCDCheat, 0, 0);
          cheatDisplayed = 1;
        }
        break;
    }
  }
}
예제 #30
0
파일: CharMenu.c 프로젝트: firdanas/tombol
void CharMenuDraw()
{
	if (MenuMain[gState].actFunction!=0)
	{
		MenuMain[gState].actFunction();
		_delay_ms(500);
		while (!ButtonBack());
		gCursor = MenuMain[gState].cursorNum;
		gState = MenuMain[gState].parentIndex;
		return;
	}
	uint8_t x=0;
	///Catch the current menu and cursor, x start from 1 (not main menu)
	for (x=1;x<TOTAL_MENU;x++)
	{
		///current state is gState, find children of MenuMain[gState]
		if ((MenuMain[x].parentIndex == gState) && ((MenuMain[x].cursorNum) == gCursor))
		{
			///Draw the current menu at current cursor
			LCDGotoXY(0,0);
			LCDstring((uint8_t*)(MenuMain[x].menuText),16);
			PrintScroll(gCursor,MenuMain[MenuMain[x].parentIndex].numOfChildren);
			
			///wait signal
			uint8_t action = ButtonRead();
			if (action == BUTTON_ENTER_DOWN)
			{
				gState = x;
				gCursor = 1;
				//~ DrawNumber(gState,0,1,3);
				//~ uint8_t ii;
				//~ for (ii=1;ii<TOTAL_MENU;ii++)
				//~ {
					//~ if ((MenuMain[ii].parentIndex==x) && (MenuMain[ii].cursorNum==1))
					//~ {
						//~ gCursor = 1;
						//~ gState = ii;
						//~ break;
					//~ }
				//~ }
				//~ _delay_ms(1000);
			}
			else if (action == BUTTON_NEXT_DOWN)
			{
				gCursor++;
				if (gCursor>MenuMain[MenuMain[x].parentIndex].numOfChildren)
					gCursor = 1;
			}
			else if (action == BUTTON_PREV_DOWN)
			{
				gCursor--;
				if (gCursor<1)
					gCursor = MenuMain[MenuMain[x].parentIndex].numOfChildren;
			}
			else if (action == BUTTON_BACK_DOWN)
			{
				gCursor = MenuMain[gState].cursorNum;
				gState = MenuMain[gState].parentIndex;
				//~ DrawNumber(MenuMain[gState].cursorNum,3,1,2);
				//~ gCursor = 1;
				//~ return;
			}
			return;
		}
	}
}