/*******************************************************************************
* Function name: DisplayPutIndicatorNetwork
********************************************************************************
*
* Summary:
*   print incator connect  from position row = 1, column = 15
*
* Parametrs:
*   state = CONNECT or state = DISCONNECT
*******************************************************************************/
void DisplayIndicatorNetwork(NetworkIndicator indicator)
{
    LCD_Position(1,14);
    if(indicator == CONNECT)
    {
        LCD_PutChar(LCD_CUSTOM_2);
    }
    else
    {
        LCD_PutChar(LCD_CUSTOM_3);
    }
}
/*******************************************************************************
* Function name: DisplayPutIndicatorSD
********************************************************************************
*
* Summary:
*   print incator SD card from position row = 1, column = 15
*
* Parametrs:
*   state = SD_INSERT or state = SD_NO_INSERT
*******************************************************************************/
void DisplayIndicatorSD(SDindicator indicator)
{
    LCD_Position(1,15);
    if(indicator == SD_INSERT)
    {
        LCD_PutChar(LCD_CUSTOM_0);
    }
    else
    {
        LCD_PutChar(LCD_CUSTOM_1);
    }
}
void DisplayTestMode(uint8_t state)
{
    LCD_Position(1,15);
    if(state == 1)
    {
        LCD_PutChar('t');
    }
    else
    {
        LCD_PutChar(' ');
    }
}
/*************************************************************
*	函数名称:LCD_PutString
*	功    能:在指定位置显示多个汉字或字符
*	参    数:
*				x:  窗体中X坐标中较小者
*	 		 	y:  窗体中Y坐标中较小者
*				*s:待显示的汉字或字符
*				fColor:字体颜色
*				bColor:背景颜色 
*	返 回 值:无
*************************************************************/
void LCD_PutString(u16 x, u16 y, u8 *s, u16 fColor, u16 bColor) 
{
	unsigned char l=0;
    uint16 b = 0;

    //if (!horizontal_or_vertical)
    {
        b = x;
        x = y;
        y = b;
    }
	while(*s) 
	{
		if( *s < 0x80) 								 //判断是否为字符
		{
			LCD_PutChar(x+l*8,y,*s,fColor,bColor);
			s++;
			l++;
		}
		else
		{
			LCD_PutGB1616(x+l*8,y,(u8 *)s,fColor,bColor);
			s+=2;
			l+=2;
		}
	}
}
Beispiel #5
0
void LCD_Spin ( int row, int col, int speed, int count ) {
    while (count-- > 0) {
        LCD_Position(row,col);
        LCD_PutChar('|');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('/');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('-');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('\\');
        CyDelay(speed/4);
    }
}
Beispiel #6
0
void main(){

	OUTPUT_LOW(LCD_RW); //Che do ghi 
	LCD_Init();        //Khoi tao LCD

	LCD_PutCmd(0x01);  //Xoa man hinh

	ENABLE_INTERRUPTS(INT_TIMER0); //Kich hoat ngat ngoai
	SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_32); //Xung kich noi va chia truoc 32
	ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc
	SET_TIMER0(100); //Bat dau dem tu 100, khi tran Timer0 duoc 1ms

	while (True){ //Duy tri hoat dong cua vi dieu khien

		if (dem > N_max){
			dem = 0;
			LCD_PutCmd(0x01);
		}

		LCD_SetPosition(0x00); //Cot 1 dong 1
		LCD_PutChar("Dem so:");
		LCD_SetPosition(0x07); //Cot 8 dong 1
		printf(LCD_PutChar,"%lu",dem);

	}
}
Beispiel #7
0
 /*******************************************************************************
 *  Function Name: LCD_PrintInt8
 ********************************************************************************
 *
 * Summary:
 *  Print a byte as two ASCII characters.
 *
 * Parameters:
 *  value:  The byte to be printed out as ASCII characters.
 *
 * Return:
 *  None.
 *
 *******************************************************************************/
 void LCD_PrintInt8(uint8 value) 
 {
     static char8 const CYCODE LCD_hex[16u] = "0123456789ABCDEF";
     
     LCD_PutChar((char8) LCD_hex[value >> LCD_BYTE_UPPER_NIBBLE_SHIFT]);
     LCD_PutChar((char8) LCD_hex[value & LCD_BYTE_LOWER_NIBBLE_MASK]);
 }
Beispiel #8
0
void main(){
    float distance = 0;
    
    OUTPUT_LOW(LCD_RW);
    LCD_Init();
    LCD_PutCmd(0x01);
    
    SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_4);
    SETUP_CCP1(CCP_CAPTURE_RE);
    
    ENABLE_INTERRUPTS(INT_CCP1);
    ENABLE_INTERRUPTS(GLOBAL);
    
    
    while (True){
        Trigger();
        
        while (echo == 0){
            ;
        }
        
        distance = value*0.8/58;
        LCD_PutCmd(0x01);
        LCD_SetPosition(0x00);
        LCD_PutChar("Distance:");
        LCD_SetPosition(0x40);
        printf(LCD_PutChar,"%.2fcm",distance);
        delay_ms(1000);
    }
}
Beispiel #9
0
void LCD_Spin ( uint8 row , uint8 col , uint8 speed , uint8 count ) {
    while (count-- > 0) {
        LCD_Position(row,col);
        LCD_PutChar('|');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('/');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('-');
        CyDelay(speed/4);
        LCD_Position(row,col);
        LCD_PutChar('\\');
        CyDelay(speed/4);
    }
}
Beispiel #10
0
/****************************************************************************
* Function Name  : LCD_PutString
* Description    : output string to screen
* Input          : x      X-coordinate
y      Y-coordinate
str     pointer to string
* Output         : None
* Return         : None
****************************************************************************/
void  LCD_PutString(unsigned long x, unsigned long y, char* str)
{
    while(1)
    {
        if( (*str)=='\0' ) break;
        if( LCD_PutChar(x, y, *str++) == 0 ) break;
        x += 6;								
    }
}
Beispiel #11
0
void showMenuItem(uchar index,bit selected){
	ClrScreen();

	LCD_PutString(3,1,"设置");
	LCD_PutString(2,2,configMenuStrArr[index]);
	if(selected){
		LCD_PutChar(1,2,26);//输出"->"
	}
} 
Beispiel #12
0
void LCD_PutStr( const char *s )
{
    char    ch;

    while (( ch = *s++ ) != '\0' )
    {
        LCD_PutChar( ch );
    }

} // LCD_PutStr
Beispiel #13
0
void LCD_PutStr_P( const char *s )
{
    char    ch;

    while (( ch = pgm_read_byte( s )) != '\0' )
    {
        LCD_PutChar( ch );

        s++;
    }

} // LCD_PutStr
Beispiel #14
0
void showMenuItem(uchar index,bit selected){
	ClrScreen();
	if(configValueArr[CONFIG_DEBUG]!=0){
		
		LCD_PutString(0,0,"调试");
	}
	LCD_PutString(3,0,"设置");
	LCD_PutString(2,1,configMenuStrArr[index]);
	if(selected){
		LCD_PutChar(1,2,26);//输出"->"
	}
} 
/*******************************************************************************
* Function name: DisplayPrintfLoading
********************************************************************************
*
* print loading from position row = 1, column = 0
*
*******************************************************************************/
void DisplayLoading(uint32_t numLoad)
{
    if(numLoad == 0)
    {
        /*clear row 1*/
        LCD_Position(1,0);
        LCD_PrintString("             ");
    }
    if((numLoad > 0) && numLoad < 16)
    {
        LCD_Position(1,numLoad-1);
        LCD_PutChar(LCD_CUSTOM_4);
    }
}
Beispiel #16
0
/*********************************************************************
 * Function: void LCD_PutString(char* inputString, uint16_t length);
 *
 * Overview: Puts a string on the LCD screen.  Unsupported characters will be
 *           discarded.  May block or throw away characters is LCD is not ready
 *           or buffer space is not available.  Will terminate when either a
 *           null terminator character (0x00) is reached or the length number
 *           of characters is printed, which ever comes first.
 *
 * PreCondition: already initialized via LCD_Initialize()
 *
 * Input: char* - string to print
 *        uint16_t - length of string to print
 *
 * Output: None
 *
 ********************************************************************/
void LCD_PutString ( char* inputString , uint16_t length )
{
    while (length--)
    {
        switch (*inputString)
        {
        case 0x00:
            return ;

        default:
            LCD_PutChar ( *inputString++ ) ;
            break ;
        }
    }
}
Beispiel #17
0
/*
 * Retargets the C library printf function to the LCD.
 * Pa3cio, 25.2.2013
 */
int fputc( int ch, FILE *f )
{
  /* Character counter - counts chars in the line: */
  static uint16_t usColumn = 0;
  /* Physical column - we allow the first char in the column to start in arbitrary column, 
     not only in the column that is divisible by COLUMN_INCREMENT */
  static uint16_t usRefColumn = COLUMN_START;
  /* Line counter */
  static uint16_t usLine = 0;

  if( ( usColumn == 0 ) && ( usLine == 0 ) )
  {
    LCD_Clear(BLACK);
  }

  if( ch != '\n' )
  {
    /* Display one character on LCD */
    LCD_PutChar( usRefColumn, usLine, (u8) ch );
		
    /* Increment the column position by mainCOLUMN_INCREMENT */
    usRefColumn += COLUMN_INCREMENT;
		
    /* Increment the character counter */
    usColumn += COLUMN_INCREMENT;
    if ( (MAX_COLUMN - usColumn) < COLUMN_INCREMENT ) /* Do we have enough place for the character?*/
    {
      usLine += ROW_INCREMENT;
      usRefColumn = COLUMN_START;
      usColumn = 0;
    }
  }
  else
  {
    /* Move back to the first column of the next line. */
    usLine += ROW_INCREMENT;
    usRefColumn = COLUMN_START;
    usColumn = 0;	
  }

  /* Wrap back to the top of the display. */
  if( usLine >= MAX_LINE )
  {
    usLine = 0;
  }
	
  return ch;
}
Beispiel #18
0
//================================================================================================
//	实现功能:	显示中英文字符串
//  输入参数:  x 横坐标
//              y 纵坐标
//		        *s 待显示的字符串,例如LCD_PutString(24,16,"123蓝芯",White,Blue);即把"123蓝芯"的第一个字符地址赋给指针变量s.
//		        bColor 字符背景颜色
//================================================================================================
void LCD_PutString(unsigned short x, unsigned short y, unsigned char *s, unsigned int fColor, unsigned int bColor) 
{
	 unsigned char l=0;                            //显示屏位置增量
     while(*s) 
	 {
		if( *s < 0x80)                             //判断s指向的字符串中的某字符的编码值是否小于128,如果小于,即为ASCII字符
		    {
			 LCD_PutChar(x+l*8,y,*s,fColor,bColor);//显示该字符
		     s++;l++;                              //指针加1,位置加1
			}
		else
		    {
			 Put16x16(x+l*8,y,(unsigned char*)s,fColor,bColor);//显示该汉字
		     s+=2;l+=2;                                        //因为汉字为编码为2字节,指针加2,显示16x16所以位置加2
			}
	 }
}
Beispiel #19
0
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
int main ( void )
{
    /* Call the System Intialize routine*/
    SYS_Initialize ( ) ;

    /*Initialize Timer*/
    TIMER_SetConfiguration ( TIMER_CONFIGURATION_RTCC ) ;

    TRISGbits.TRISG7 = 1; //in breakout pin RF2 (row 1)
    TRISGbits.TRISG2  = 1; //in breakout pin RA2 (row 2)
    TRISCbits.TRISC0 = 1; //in breakout pin RB8 (row 3)
    TRISCbits.TRISC1 = 1;//in breakout pin RB9 (row 4)                 
    TRISEbits.TRISE12 = 0; //in breakout pin RB12 (col 1)
    TRISCbits.TRISC2 = 0; //in breakout pin RB10 (col 2)
    TRISEbits.TRISE14 = 0; //in breakout pin RB14 (col 3)
    
    
    ANSELGbits.ANSG7 = 0; //Row 1-4        //configuring all pins as digital
    ANSELGbits.ANSG2 = 0;
    ANSELCbits.ANSC0 = 0;
    ANSELCbits.ANSC1 = 0;
    ANSELEbits.ANSE12 = 0; //Col 1-3
    ANSELCbits.ANSC2 = 0;
    ANSELEbits.ANSE14 = 0;
    
    char return_key;
    
    /* Infinite Loop */
    while ( 1 )
    {  
        return_key = 'X'; //initialize return key to default return variable from readKeyboard()
        
        while(return_key == 'X'){ //while nothing is pressed, keep on making calls
            return_key = readKeyboard();
        }
        
        if(return_key != 'X'){ //if return_key is not default key, print to LCD 
            //should transmit to UART at this point  
            LCD_PutChar(return_key);
        }
        
        while(readKeyboard() != 'X'){
            //no operation till next key is pressed.
        }
    }    
}
Beispiel #20
0
/*********************************************************************
 * Function: void LCD_PutChar(char);
 *
 * Overview: Puts a character on the LCD screen.  Unsupported characters will be
 *           discarded.  May block or throw away characters is LCD is not ready
 *           or buffer space is not available.
 *
 * PreCondition: already initialized via LCD_Initialize()
 *
 * Input: char - character to print
 *
 * Output: None
 *
 ********************************************************************/
void LCD_PutChar ( char inputCharacter )
{
    switch (inputCharacter)
    {
    case '\r':
        LCD_CarriageReturn ( ) ;
        break ;

    case '\n':
        if (row == 0)
        {
            LCD_ShiftCursorDown ( ) ;
        }
        else
        {
            LCD_ShiftCursorUp ( ) ;
        }
        break ;

    case '\b':
        LCD_ShiftCursorLeft ( ) ;
        LCD_PutChar ( ' ' ) ;
        LCD_ShiftCursorLeft ( ) ;
        break ;

    default:
        LCD_SendData ( inputCharacter ) ;
        column++ ;

        if (column == LCD_MAX_COLUMN)
        {
            column = 0 ;
            if (row == 0)
            {
                LCD_SendCommand ( LCD_COMMAND_ROW_1_HOME , LCD_S_INSTR ) ;
                row = 1 ;
            }
            else
            {
                LCD_SendCommand ( LCD_COMMAND_ROW_0_HOME , LCD_S_INSTR ) ;
                row = 0 ;
            }
        }
        break ;
    }
}
Beispiel #21
0
/*-----------------------------------------------------------*/
int fputc( int ch, FILE *f )
{
static unsigned portSHORT usColumn = 0, usRefColumn = mainCOLUMN_START;
static unsigned portCHAR ucLine = 0;

	if( ( usColumn == 0 ) && ( ucLine == 0 ) )
	{
		LCD_Clear(LCD_White);
	}

	if( ch != '\n' )
	{
		/* Display one character on LCD */
		LCD_PutChar(320 - usRefColumn, ucLine, (u8) ch, LCD_Red, LCD_White);

		/* Decrement the column position by 16 */
		usRefColumn -= mainCOLUMN_INCREMENT;

		/* Increment the character counter */
		usColumn++;
		if( usColumn == mainMAX_COLUMN )
		{
			ucLine += mainROW_INCREMENT;
			usRefColumn = mainCOLUMN_START;
			usColumn = 0;
		}
	}
	else
	{
		/* Move back to the first column of the next line. */
		ucLine += mainROW_INCREMENT;
		usRefColumn = mainCOLUMN_START;
		usColumn = 0;
	}

	/* Wrap back to the top of the display. */
	if( ucLine >= mainMAX_LINE )
	{
		ucLine = 0;
	}

	return ch;
}
Beispiel #22
0
void main_test_disp(){
    LCD_Start();					    // initialize lcd
    uint8 current;
    for (;;){
        LCD_ClearDisplay();
        
        LCD_Position(0,0); //move back to top row
        current = Pin0_Read(); //next, read a new value
        LCD_PrintString("P0: ");
        LCD_PrintNumber(current); //print value I am getting
        
        LCD_Position(1,0); //move to bot row
        current = Pin3_Read(); //next, read a new value
        LCD_PrintString("P3: ");
        LCD_PutChar(current); //print ascii value
        LCD_PrintString(" HEX: ");
        LCD_PrintNumber(current); //print value I am getting
        
        waiter(4);
    }
}
Beispiel #23
0
void Ir_work(void)
{
	
	switch (IRcord[2]){
	//600us计时模式下
	case IR_CHANNEL:
	if(setState==SET_STATE_NONE)
	{
		startSetting=1;	
	}
	break;


	case IR_EQ:
	
	if(setState==SET_STATE_INIT){
		setState=SET_STATE_MENU;
		curMenuIndex=0;
		showMenuItem(curMenuIndex,1);
		
	}
	else if(setState==SET_STATE_MENU){
		setState=SET_STATE_MENU_ITEM_SEL;
	
		curSelBit=0;
		
		
		showMenuItem(curMenuIndex,1);
		digiBuf[0]=configValueArr[curMenuIndex]/100;
		digiBuf[1]=(configValueArr[curMenuIndex]%100)/10;
		digiBuf[2]=configValueArr[curMenuIndex]%10;
		dispDigit();
	}
	else if(setState==SET_STATE_MENU_ITEM_SEL){
		setState=SET_STATE_MENU_ITEM_BIT_SEL;
		showMenuItem(curMenuIndex,0);
		LCD_PutChar(2,3,26);//输出"->"
		dispDigit();
		curSelBit=0;
		LCD_PutPosition(3+curSelBit,3);
	}
	else if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		if(curMenuIndex==CONFIG_EXIT){
		//	setState=SET_STATE_NONE;
			
		//	inSetting=0;			
		}
		else{
			configValueArr[curMenuIndex]=digiBuf[0]*100+digiBuf[1]*10+digiBuf[2];
			saveConfig();
			LCD_PutString(2,4,"设置完毕!");
			setState=SET_STATE_MENU_ITEM_FINISHED;
		
		
		}
	}		

		
	break;
	case IR_CHANNEL_MINUS:
	if(setState==SET_STATE_MENU||setState==SET_STATE_INIT){
		setState=SET_STATE_NONE;
		
		clearInfraredFlag();
		ClrScreen();//强行清屏
		inSetting=0;
		
		
	}
	else if(setState==SET_STATE_MENU_ITEM_SEL){
		setState=SET_STATE_MENU;
		showMenuItem(curMenuIndex,1);
	
	}
	else if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		setState=SET_STATE_MENU;
		showMenuItem(curMenuIndex,1);
	}
	else if(setState==SET_STATE_MENU_ITEM_FINISHED){
		setState=SET_STATE_MENU_ITEM_BIT_SEL;
		showMenuItem(curMenuIndex,0);
		LCD_PutChar(2,3,26);//输出"->"
		dispDigit();
		curSelBit=0;

		LCD_PutPosition(3+curSelBit,3);
	}
	break;
	case IR_NEXT:
	if(setState==SET_STATE_MENU){
		
		curMenuIndex=(curMenuIndex+1)%MENU_LEN;
	//	curMenu=curMenuArr[curMenuIndex];
		showMenuItem(curMenuIndex,1);
		
	}
	else if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		curSelBit=(curSelBit+1)%BITS_COUNT; 
		LCD_PutPosition(3+curSelBit,3);

	
		
	}
	break;
	case IR_PREV:
	if(setState==SET_STATE_MENU){
		
		curMenuIndex=(curMenuIndex+MENU_LEN-1)%MENU_LEN;
	//	curMenu=curMenuArr[curMenuIndex];
		showMenuItem(curMenuIndex,1);
		
	}
	else if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		curSelBit=(curSelBit+BITS_COUNT-1)%BITS_COUNT;
		LCD_PutPosition(3+curSelBit,3);
		
		
		
	}
	break;
	case IR_VOL_ADD:
	if(setState==SET_STATE_MENU){
		
		curMenuIndex=(curMenuIndex+1)%MENU_LEN;
	//	curMenu=curMenuArr[curMenuIndex];
		showMenuItem(curMenuIndex,1);
		
	} else 	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		
			digiBuf[curSelBit]=(digiBuf[curSelBit]+1)%10;
		  	dispDigit();
	}
	break;
	case IR_VOL_MINUS:
	if(setState==SET_STATE_MENU){
		
		curMenuIndex=(curMenuIndex+MENU_LEN-1)%MENU_LEN;
	//	curMenu=curMenuArr[curMenuIndex];
		showMenuItem(curMenuIndex,1);
		
	}else 	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
		
			digiBuf[curSelBit]=(digiBuf[curSelBit]+10-1)%10;
			dispDigit();
	}
	break;
	case IR_ZERO:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=0;
			dispDigit();
	}
	break;
	case IR_ONE:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=1;
			dispDigit();
	}
	break;
	case IR_TWO:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=2;
			dispDigit();
	}
	break;
	case IR_THREE:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=3;
			dispDigit();
	}
	break;
	case IR_FOUR:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=4;
			dispDigit();
	}
	break;
	case IR_FIVE:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=5;
			dispDigit();
	}
	break;
	case IR_SIX:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=6;
			dispDigit();
	}
	break;
	case IR_SEVEN:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=7;
			dispDigit();
	}
	break;
	case IR_EIGHT:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=8;
			dispDigit();
	}
	break;
	case IR_NINE:
	if(setState==SET_STATE_MENU_ITEM_BIT_SEL){
			digiBuf[curSelBit]=9;
			dispDigit();
	}
	break;

	default:
	
		break;
	
	}
	
}
Beispiel #24
0
void TARGET_LCD_Put(char data)
{
  LCD_PutChar(data);
}
Beispiel #25
0
int main(void)
{
    InitTimer();
    InitUART();

    LED_DDR |= LED_MASK;

    LCD_Init( CFG_LCD_NUM_LINES, CFG_LCD_NUM_COLUMNS );

    LCD_PutStr( "LCD Test\n" );
    LCD_PutStr( ">Line 2<\n" );

    fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );
    printf( "*****\n" );
    printf( "***** LCD Test program\n" );
    printf( "*****\n" );

    DDRB &= ~SW_ALL;
    PORTB |= SW_ALL;

    while( 1 )
    {
        LED_PORT |=  LED_MASK;

        ms_spin( 100 );

        LED_PORT &= ~LED_MASK;

        ms_spin( 100 );

        LED_PORT |=  LED_MASK;

        ms_spin( 100 );

        LED_PORT &= ~LED_MASK;

        ms_spin( 700 );

        LCD_MoveTo(0,1);
        uint8_t pinb = PINB;
        if ( pinb & SW_A )
        {
            printf("A is high ");
            LCD_PutChar('a');
        }
        else
        {
            printf("A is low ");
            LCD_PutChar('A');
        }
        if ( pinb & SW_B )
        {
            printf("B is high ");
            LCD_PutChar('b');
        }
        else
        {
            printf("B is low ");
            LCD_PutChar('B');
        }
        if ( pinb & SW_C )
        {
            printf("C is high\n");
            LCD_PutChar('c');
        }
        else
        {
            printf("C is low\n");
            LCD_PutChar('C');
        }
    }

    return 0;
}
Beispiel #26
0
//================================================================================================
//	函数名称:	主函数
//	实现功能:	控制TFT实现汉字,字符显示.
//	参数:		无
//	返回值:	无
//================================================================================================
main()
{
//        unsigned char  run_computer,direction_index_computer;
		unsigned int x,y,z,di;
		float total,angle;
		
		Device_code=0x9320;                //TFT控制IC型号
		
		TFT_Initial();                     //初始化LCD
	   
		PCON=0x80;		 //设置波特率及串口中断
		SCON=0x50;
		TMOD=0x20;		 //T0方式1
		TH1=0xF3;
		TL1=0xF3;
		IT0=1;
		IT1=1;
		TR1=1;
		EX1=1;
		EX0=1;
		ES=1;
		EA=1;	
		
		direction=1;
		Show_RGB(0,240,0,320,Blue);
		LCD_PutString(0,16,"        中 国 科 学 院        ",White,Blue);
		LCD_PutString(0,40,"    安徽光学精密机械研究所    ",White,Blue);
		LCD_PutString(0,72,"当前角度 ",White,Blue);
		LCD_PutString(110,72,"度",White,Blue);
		LCD_PutString(0,88,"当前值",White,Blue);
		LCD_PutString(0,120,"方向",White,Blue);
		LCD_PutString(0,152,"模式",White,Blue);
		LCD_PutString(0,184,"状态",White,Blue);
		LCD_PutString(0,304,"version 1,aiofm,hfcas",White,Blue);
		while(1)                                
		{	   
			LCD_PutChar(70,88,rec_line[11],White,Blue);
			LCD_PutChar(78,88,rec_line[12],White,Blue);
			LCD_PutChar(86,88,rec_line[13],White,Blue);
			LCD_PutChar(94,88,rec_line[14],White,Blue);		 

			total=(float)(((int)num[0])*1000+((int)num[1])*100+num[2]*10+((int)num[3])); //显示当前读数
			angle=total/4095.0*360.0;
			x=((int)angle)/100;
			y=((int)angle)/10%10;
			z=((int)angle)%10;
			di=((int)(angle*10))%10;	  
				 
			LCD_PutChar(70,72,display1[x],White,Blue);		  //显示当前角度
			LCD_PutChar(78,72,display1[y],White,Blue);
			LCD_PutChar(86,72,display1[z],White,Blue);
			LCD_PutChar(94,72,'.',White,Blue);
			LCD_PutChar(102,72,display1[di],White,Blue);
			if(boardorcomputer==1)
				{			
						if(run==0)
						{	
							LCD_PutString(40,184,"运行",White,Blue);	
							TH0 = (8192 - 200)/32	;  //给计数器装初值
							TL0 = (8192 - 200)%32	;	 
							ET0=1;
							TR0=1;
						}
						else
						{
							LCD_PutString(40,184,"停止",White,Blue);
							ET0 = 0;       
							TR0 = 0;
							motor=0;
						}
						if(direction_index==1)
						{
							LCD_PutString(40,120,"逆时针",White,Blue);
							direction=0;
						}
						else
						{
							LCD_PutString(40,120,"顺时针",White,Blue);
							direction=1;
						}
						if(modekey==1)
						{
							LCD_PutString(40,152,"常规",White,Blue);
						}
						else
						{
							LCD_PutString(40,152,"微调",White,Blue);
						}	
			
				}
				else
				{
					switch(computer_char)
					{
					   case 0xff:
					   {
							LCD_PutString(40,184,"运行",White,Blue);	
							TH0 = (8192 - 200)/32	;  //给计数器装初值
							TL0 = (8192 - 200)%32	;	 
							ET0=1;
							TR0=1;
					   		break;
					   }
					   case 0x00:
					   {
					   		LCD_PutString(40,184,"停止",White,Blue);
							ET0 = 0;       
							TR0 = 0;
							motor=0;
							break;
						}
						case 0xf0:
						{
							LCD_PutString(40,120,"逆时针",White,Blue);
							direction=0;
							break;
						}
						case 0x0f:
						{
							LCD_PutString(40,120,"顺时针",White,Blue);
							direction=1;
							break;
						}
						case 0x30:
						{
							computermode=0;
							LCD_PutString(40,152,"常规",White,Blue);
							break;
						}
						case 0x03:
						{
							computermode=1;
							LCD_PutString(40,152,"微调",White,Blue);
							break;
						}
					   defult:break;
					}
				}
		}
}
Beispiel #27
0
void MENU_Draw( void )
{
    char           *s;
    char            fmtStr[ 10 ];
    uint16_t        val = 0;
    uint16_t        maxVal = 0;
    int16_t         ival = 0;
    int16_t         maxIVal = 0;
    uint8_t         maxLen;
    uint8_t         valLen;
    MENU_MemItem_t  item;
    uint8_t         signedVal = 0;

    if ( !MENU_IsActive() )
    {
        return;
    }

    if ( MENU_IsEditing() )
    {
        MENU_GetItem( gMenuStack[ gMenuStackTop ], &item );
    }
    else
    {
        // By only drawing when we're not editing, we reduce flicker

        LCD_Clear();

        // First of all, draw the title of the containing menu

        MENU_GetItem( gMenuStack[ gMenuStackTop - 1 ], &item );
        LCD_PutStr_P( item.name );

        // Now draw the currently selected item

        LCD_MoveTo( 0, 1 );

        MENU_GetItem( gMenuStack[ gMenuStackTop ], &item );
        LCD_PutStr_P( item.name );
    }

    switch ( item.type )
    {
        case MENU_TYPE_BYTE:
        {
            if ( MENU_IsEditing() )
            {
                val = gMenuEditVal.uintVal;
            }
            else
            {
                val = *item.val.byteVal.bytePtr;
            }
            maxVal =  item.val.byteVal.maxVal;
            break;
        }

        case MENU_TYPE_UINT:
        {
            if ( MENU_IsEditing() )
            {
                val = gMenuEditVal.uintVal;
            }
            else
            {
                val = *item.val.uintVal.uintPtr;
            }
            maxVal =  item.val.uintVal.maxVal;
            break;
        }

        case MENU_TYPE_INT:
        {
            signedVal = 1;

            if ( MENU_IsEditing() )
            {
                ival = gMenuEditVal.intVal;
            }
            else
            {
                ival = *item.val.intVal.intPtr;
            }
            maxIVal =  item.val.intVal.maxVal;
            break;
        }

        default:
        {
            return;
        }
    }

    if ( signedVal )
    {
        snprintf( fmtStr, sizeof( fmtStr ), "%d", maxIVal );
        maxLen = strlen( fmtStr );
        snprintf( fmtStr, sizeof( fmtStr ), "%d", ival );
    }
    else
    {
        snprintf( fmtStr, sizeof( fmtStr ), "%u", maxVal );
        maxLen = strlen( fmtStr );
        snprintf( fmtStr, sizeof( fmtStr ), "%u", val );
    }

    LCD_MoveTo( LCD_NumCols() - maxLen - 2, LCD_NumLines() - 1 );

    LCD_PutChar( MENU_IsEditing() ? '[' : ' ' );

    valLen = strlen( fmtStr );
    while ( maxLen > valLen )
    {
        LCD_PutChar( ' ' );
        maxLen--;
    }

    s = fmtStr;
    while ( valLen > 0 )
    {
        LCD_PutChar( *s++ );
        valLen--;
    }

    LCD_PutChar( MENU_IsEditing() ? ']' : ' ' );

} // MENU_Draw
Beispiel #28
0
void main_flashing_tta_psoc(){
    // this is the function compatible with the cap sensor input. with 8051 interrupts
    LCD_Start();					    // initialize lcd
    LCD_ClearDisplay();
    UART_Start();                       // initialize UART
    UART_PutChar(0x81); // init connection; set to 16x12 image 
    
    struct disp_grid_81 disp; 
    disp_grid_init(&disp,0x3F); // init our display grid matrix to white  
    disp_grid_transmit(&disp);
    
    struct tic_tac_ai tta;
    tta_init(&tta,4,3,false,true); //first bool for player 1, second bool for player 2. true means is AI
    disp_grid_init_ttc(&disp, tta.game.grid);
    disp_grid_draw_tic(&disp,24,1,0x27); // draw tic
    disp_grid_draw_xia(&disp,26,16,0x30); // draw xia
    disp_grid_transmit(&disp);
    
    int x,y,z, count; uint8 Values; uint8 Values_prev;
    uint8 current;
    Values_prev = 0;
    x = 0; y = 0; z = 0; //test value
    count = 0;
    
    uint8 red_flash; //the temporary location flasher
    uint8 other_val;
    other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val
    red_flash = 0x30; //map to color red
    
    
    while (tta.game.game_not_won == 0){
        LCD_ClearDisplay();
        LCD_Position(1,0); //move to bot row
        LCD_PrintString("LAST:"); //first, we print last value
        LCD_PutChar(Values_prev); //print ascii value
        LCD_PrintString(" HEX: ");
        LCD_PrintNumber(Values_prev); //print value I am getting
        
        current = Pin3_Read(); //next, read a new value
        LCD_Position(0,0); //move back to top row
        LCD_PrintString("CURR:");
        LCD_PutChar(current); //print ascii value
        LCD_PrintString(" HEX: ");
        LCD_PrintNumber(current); //print value I am getting
        waiter(3);
        
        if (current != 255) {
            Values = current; // update values as last non
            Values_prev = Values;
        }
        
        if (Values != 0){
            if (Values == 54){
                if (tta.game.grid[z*16 + y*4 + x] == 0){ // make sure we can place there
                    tta_step(&disp,&tta,x,y,z); //increment a turn
                    disp_grid_transmit(&disp);
                    tta_step(&disp,&tta,x,y,z); //AI Increment also 
                    other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val
                }
            }
            else{
                disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val);
                if (Values == 53 && y != 0){ // up
                y--;
                }
                else if (Values == 52 && y != 3){ // down
                    y++;
                }
                else if (Values == 51 && x != 0){ // left
                    x--;
                }
                else if (Values == 50 && x != 3){ // right
                    x++;
                }
                else if (Values == 49){ // level shift
                    z++;
                    z = z % 4;
                }
                other_val = disp_grid_ttc_getval(&disp,z*16 + y*4 + x); // get the nonred val
            }
            Values = 0; // reset values;
            count = 0;
        }
        
        if (count == 0){ //decide print
            count = 1;
            disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,red_flash);
            disp_grid_transmit(&disp);
        }
//        else{
//            count = 0;
//            disp_grid_ttc_place_value(&disp,z*16 + y*4 + x,other_val);
//            disp_grid_transmit(&disp);
//        }
        
    }
    LCD_ClearDisplay();
    LCD_PrintString("GAME OVER!");  
    disp_grid_draw_win(&disp,27,9,tta.game.player); // draw tic
    disp_grid_transmit(&disp);
    
}