// Converter para character e mostrar no display
int displayNumber(int c, unsigned char pos_x, unsigned char pos_y){

	unsigned int i = 1;
	unsigned int index = 0;
	unsigned int DIV = 0;
	unsigned int RES;
	
	if( c<0 ){ // por o sinal negativo
		LCDPutChar( '-', pos_x, pos_y+DIGIT_SIZE*index, BLACK, WHITE);
		++index;
		c *= -1;
	}
	
	for( DIV=c/10; DIV>0; ++i)
		DIV = DIV / 10;
	
	DIV = index;
	while( i ){ //Escrever
		RES = c%10;
		c /= 10;
		LCDPutChar( RES+'0', pos_x, pos_y+DIGIT_SIZE*(i+index-1), BLACK, WHITE);
		--i;
		++DIV;		
	}
	
	return DIV; // retorna o num de caracteres escritos
}
Exemple #2
0
// Function to write unsigned char to LCD
void writeChar(unsigned int row, unsigned char outchar)
{
    LCDGoto(0,row);
    sprintf(dispStr,"%02d", outchar);
    LCDPutChar(dispStr[0]);
    LCDPutChar(dispStr[1]);
}
void display_current(float v){
	
	int v_int, v_quo;
	
	v_int = v; //inteiro
	int num_pos = displayNumber(v_int, I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 ));
	LCDPutChar( '.', I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 ) + DIGIT_SIZE*(num_pos), BLACK, WHITE);
	++num_pos;
	v -= v_int;
	v_quo = v * 100; //-inteiro
	if( v_quo>0 && v_quo<10 )
		displayNumber(0, I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 )+DIGIT_SIZE*( num_pos++ ));
	displayNumber(v_quo, I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 )+DIGIT_SIZE*( num_pos ));
	
	//v -= v_quo;
	//v_quo = v * 10;
	//v_quo *= 10;
	//v_quo %= 100;
	//displayNumber(v_quo, I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 )+DIGIT_SIZE*( num_pos+2 ));
	
	/*if( v_quo ){
		LCDPutChar( '.', I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 ) + DIGIT_SIZE*(num_pos), BLACK, WHITE);
		displayNumber(v_quo, I_X, I_Y+DIGIT_SIZE*( sizeof(corrente)-1 )+DIGIT_SIZE*( num_pos+1 ));
	}*/
}
//Humidade
void display_humidade(unsigned char h_int, unsigned char h_quo){
	
	int num_pos = displayNumber(h_int, HUM_X, HUM_Y+DIGIT_SIZE*( sizeof(humidade)-1 ) );
	if( h_quo ){
		LCDPutChar( '.', HUM_X, HUM_Y+DIGIT_SIZE*( sizeof(humidade)-1 )+DIGIT_SIZE*(num_pos), BLACK, WHITE);
		displayNumber(h_quo, HUM_X, HUM_Y+DIGIT_SIZE*( sizeof(humidade)-1)+DIGIT_SIZE*( num_pos+1 ));
	}
}
//Escrever temperatura	
void display_temperatura(char t_int, unsigned char t_quo){

	int num_pos = displayNumber(t_int, T_X, T_Y+DIGIT_SIZE*( sizeof(temperatura)-1 ) );
	if( t_quo ){
		LCDPutChar( '.', T_X, T_Y+DIGIT_SIZE*( sizeof(temperatura)-1 )+DIGIT_SIZE*(num_pos), BLACK, WHITE);
		displayNumber(t_quo, T_X, T_Y+DIGIT_SIZE*( sizeof(temperatura)-1 )+DIGIT_SIZE*( num_pos+1 ));
	}
}
Exemple #6
0
void LCDPrintNumWithPoint(UCHAR inX, UCHAR inY, UCHAR inNum) // prints a int to the screen. convert the int to string and prints it with Point in the middle
{

	char str[4];
	_itoa(inNum, &str[0], 10);
	if (inNum < 10)
	{
		LCDPutNum(inX, inY, 0);
		LCDPutChar(inX + 1, inY, LCD_POINT);
		LCDPutNum(inX + 2, inY, str[0]-48);
	}
	else
	{
		LCDPutNum(inX, inY, str[0]-48);
		LCDPutChar(inX + 1, inY, LCD_POINT);
		LCDPutNum(inX + 2, inY, str[1]-48);
	}
}
Exemple #7
0
void LCDPrintNumBigWithPoint(UCHAR inX, UCHAR inY, UCHAR inNum) // prints a int to the screen. Big Fonts, with Point in the middle
{
#ifdef HIDEBIGNUMBERS
	LCDPrintNumWithPoint(inX,inY,inNum);
#else
	char str[4];
	_itoa(inNum, &str[0], 10);
	if (inNum < 10)
	{
		LCDDrawBigNumber(inX, inY, 0);
		LCDPutChar(inX + 3, inY+16, LCD_POINT);
		LCDDrawBigNumber(inX + 4, inY, str[0]-48);
	}
	else
	{
		LCDDrawBigNumber(inX, inY, str[0]-48);
		LCDPutChar(inX + 3, inY+16, LCD_POINT);
		LCDDrawBigNumber(inX + 4, inY, str[1]-48);
	}
#endif

}
Exemple #8
0
void LCDPrintTimeBigM(UCHAR inX, UCHAR inY) // prints a int to the screen. Big Fonts, with Point in the middle
{
	_XDATA UCHAR val;
	_XDATA UINT v = gTimerMonoCurValSec;
	val = v / 60;

	LCDPrintNum2CharBig(inX, inY, val);

	LCDPutChar(inX + 6, inY + 16, LCD_COLONS);

	val = v - (val * 60);
	LCDPrintNum2Char(inX + 7, inY + 16, val);

}
Exemple #9
0
// Function to write analog voltage to LCD using 10-bit to 5V conversion
void writeVolt(unsigned int row, unsigned int volt) {
    LCDGoto(0,row);
    sprintf(dispStr,"%04d",volt*49/10); //Approximate conversion to 0-5V
    LCDPutChar(dispStr[0]);
    LCDPutChar('.');
    LCDPutChar(dispStr[1]);
    LCDPutChar(dispStr[2]);
    LCDPutChar(dispStr[3]);
    LCDPutChar('V');
}
Exemple #10
0
// Function to write unsigned int to LCD
void writeUInt(unsigned int row, unsigned int Tick)
{
    LCDGoto(0,row);
    sprintf(dispStr,"%06d", Tick);
    LCDPutChar(dispStr[0]);
    LCDPutChar(dispStr[1]);
    LCDPutChar(dispStr[2]);
    LCDPutChar(dispStr[3]);
    LCDPutChar(dispStr[4]);
    LCDPutChar(dispStr[5]);
}
//Consumo
void display_consumo(float v){
	
	int v_int, v_quo;
	
	v_int = v; //inteiro
	
	int num_pos = displayNumber(v_int, P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 ));
	LCDPutChar( '.', P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 ) + DIGIT_SIZE*(num_pos), BLACK, WHITE);
	v -= v_int;
	v_quo = v * 10; //-inteiro
	displayNumber(v_quo, P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 )+DIGIT_SIZE*( num_pos+1 ));
	/*v_quo = v*100;
	v_quo %= 100;
	
	int num_pos = displayNumber(v_int, P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 ));
	if( v_quo ){
		LCDPutChar( '.', P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 ) + DIGIT_SIZE*(num_pos), BLACK, WHITE);
		displayNumber(v_quo, P_X, P_Y+DIGIT_SIZE*( sizeof(consumo)-1 )+DIGIT_SIZE*( num_pos+1 ));
	}*/
}	
Exemple #12
0
/*显示一行,查找字库将对应的模填入到LCDbuf中
x0-127  y0-3
*/
void Display1Line(u8 x , u8 y ,const u8 *buf)
{
	u8 *tempbuf;
	u8 i=0;
	for(tempbuf = (u8 *)buf ; *tempbuf!='\0';)
	{
		if(*tempbuf < 0x80)	  
		{
			LCDPutChar(6*i+x , 2*y ,tempbuf);  //asc码字符库
			tempbuf++;
			i++;
		}
		else
		{
			LCDPutCH(6*i+x , 2*y , tempbuf);//汉字字符集
			i+=2;
			tempbuf+=2;
		}
	}
}
Exemple #13
0
void LCDPrint(UCHAR inX, UCHAR inY, char *fmt)	// this function prints all letters and numbers and space
{
	char* ptr;
	char ch;
	UCHAR xpos;
	xpos = inX;
	ptr = fmt;
	// we go over the string until we get to 0x00
	while (*ptr != 0)
	{
		ch = *ptr;	
		if ((ch >= 'a') && (ch<='z'))
		{
			LCDPutChar(xpos, inY, ch-97);
		}
		else if ((ch >= 'A') && (ch<='Z'))
		{
			LCDPutChar(xpos, inY, ch-65);
		}
		else if ((ch >= '0') && (ch<='9'))
		{
			LCDPutNum(xpos, inY, ch-48);
		}
		else if (ch == ' ')
		{
			LCDPutChar(xpos, inY, LCD_SPACE);
		}
		else if (ch == '.')
		{
			LCDPutChar(xpos, inY, LCD_POINT);
		}
		else if (ch == '-')
		{
			LCDPutChar(xpos, inY, LCD_DASH);
		}
		else if (ch == ':')
		{
			LCDPutChar(xpos, inY, LCD_COLONS);
		}
		
		xpos++;
		ptr++;
	}
}
void LCDPut( char a)
{
    switch ( a)
    {
      case '\b':
        LCDShiftCursorLeft();
        SetColor( BLACK);
        Bar( _cx * FONT_W, _cy * FONT_H, (_cx+1) * FONT_W, (_cy+1) * FONT_H);
        SetColor( GREEN);
        break;
      case '\n': 
        LCDShiftCursorDown();
        break;
      case '\r':
        _cx = 0;
        break;
      case '\t':
        _cx = ((_cx/8)+1)*8;
        break;
      default:
        LCDPutChar( a);
        break;
    } // switch    
} // LCDPut
void displayMenu_temperatura(){
	LCDPutStr( (char *)temperatura, T_X, T_Y, BLACK, WHITE);
	LCDPutChar( grau, T_X, GRAU_POS_STRING * DIGIT_SIZE, BLACK, WHITE);	
}
int main (void) {

  SPIDDR=(1<<SDA)|(1<<CLK)|(1<<CS)|(1<<RESET); //Port-Direction Setup


  //Init Uart and send OK
  UCR = (1<<RXEN)|(1<<TXEN);
  UBRR=(F_CPU / (BAUD_RATE * 16L) - 1);
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'O';
  loop_until_bit_is_set(USR, UDRE);
  UDR = 'K';


  CS0
  SDA0
  CLK1

  RESET1
  RESET0
  RESET1

  CLK1
  SDA1
  CLK1

  waitms(10);

  //Software Reset
  sendCMD(0x01);

  //Sleep Out
  sendCMD(0x11);

  //Booster ON
  sendCMD(0x03);

  waitms(10);

  //Display On
  sendCMD(0x29);

  //Normal display mode
  sendCMD(0x13);

  //Display inversion on
  sendCMD(0x21);

  //Data order
  sendCMD(0xBA);

  //Memory data access control
  sendCMD(0x36);

  sendData(8);   //rgb + MirrorX
 //sendData(8|64);   //rgb + MirrorX
 // sendData(8|128);   //rgb + MirrorY

#ifdef MODE565
  sendCMD(0x3A);
  sendData(5);   //16-Bit per Pixel
#else
  sendCMD(0x3A);
  sendData(3);   //12-Bit per Pixel (default)
#endif


  //Set Constrast
  sendCMD(0x25);
  sendData(55);


LCDClearScreen();

 LCDSetRect(50,0,100,50,1,ORANGE);
 unsigned char i=30;
 
 while (i>5){
 LCDSetCircle(100,100,i,BLACK);
 i = i-5;
 }
 
 LCDPutChar('A', 20, 20, SMALL, RED, BLUE);
 LCDPutChar('N', 20, 26, SMALL, RED, BLUE);
 LCDPutChar('D', 20, 32, 0, RED, BLUE);
 LCDPutChar('-', 20, 38, SMALL, RED, BLUE);
 LCDPutChar('T', 20, 42, SMALL, RED, BLUE);
 LCDPutChar('E', 20, 48, 0, RED, BLUE);
 LCDPutChar('C', 20, 54, SMALL, RED, BLUE);
 LCDPutChar('H', 20, 60, SMALL, RED, BLUE);
 LCDPutChar('.', 20, 66, 0, RED, BLUE);
 LCDPutChar('P', 20, 72, SMALL, RED, BLUE);
 LCDPutChar('L', 20, 78, 0, RED, BLUE);
 //LCDPutChar("Hello World!", 20, 20, SMALL, WHITE, BLACK);
 
 LCDSetLine(30,120,70,90,GREEN);
 LCDSetLine(70,90,30,70,GREEN);
 LCDSetLine(30,70,30,120,GREEN);
}