for(bit_ctr=0;bit_ctr<8;bit_ctr++) // Êä³ö8λ
{
LCD_SCK=0;
LCD_MOSI=(byte&0x80); // MSB TO MOSI
byte=(byte<<1); // shift next bit to MSB
LCD_SCK=1;
byte|=LCD_MISO; // capture current MISO bit
}
return byte;
}
void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy)
{
LCD_WR_REG(0x2A);
LCD_WR_DATA(stx>>8);
LCD_WR_DATA(stx&0xff);
LCD_WR_DATA(endx>>8);
LCD_WR_DATA(endx&0xff);
Authors: Albert.Miao & Loovee,
Visweswara R (with initializtion code from TFT vendor)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc.,51 Franklin St,Fifth Floor, Boston, MA 02110-1301 USA
e2 = err;
if (e2 <= y) {
err += ++y*2+1;
if (-x == y && e2 <= x) e2 = 0;
}
if (e2 > x) err += ++x*2+1;
} while (x <= 0);
}
void TFT::drawTraingle( int poX1, int poY1, int poX2, int poY2, int poX3, int poY3, INT16U color)
{
drawLine(poX1, poY1, poX2, poY2,color);
drawLine(poX1, poY1, poX3, poY3,color);
drawLine(poX2, poY2, poX3, poY3,color);
}
#include "stc12c5a60s2.h"
#include <intrins.h>
#define RED 0XF800 //ºìÉ«
#define GREEN 0X07E0 //ÂÌÉ«
#define BLUE 0X001F //À¶É«
#define WHITE 0XFFFF //°×É«
#define DATA_H P2
#define DATA_L P0
sbit LCD_CS = P3^2;
sbit LCD_RESET = P3^6;
sbit LCD_MOSI = P1^5;
sbit LCD_MISO = P1^6;
sbit LCD_SCK = P1^7;//¾ÍÊÇTFTÉϵÄLCD_RSÒý½Å
void Delay1ms() //@12.000MHz
{
unsigned char i, j;
i = 12;
j = 169;
do
{
while (--j);
} while (--i);
}
void delay_ms(unsigned int ms)
{
while(ms--)
{
Delay1ms();
}
}
unsigned char SPI_RW(unsigned char byte)
{
unsigned char bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // Êä³ö8λ
{
LCD_SCK=0;
LCD_MOSI=(byte&0x80); // MSB TO MOSI
byte=(byte<<1); // shift next bit to MSB
LCD_SCK=1;
byte|=LCD_MISO; // capture current MISO bit
}
return byte;
}
void LCD_WR_DATA(unsigned char val)
{
LCD_CS=0;
LCD_SCK=0;
LCD_MOSI=1;
LCD_SCK=1;
SPI_RW(val);
LCD_CS=1;
}
void LCD_WR_REG(unsigned char reg)
{
LCD_CS=0;
LCD_SCK=0;
LCD_MOSI=0;
LCD_SCK=1;
SPI_RW(reg);
LCD_CS=1;
}
void LCD_Init()
{
P0=0;
P2=0;
LCD_RESET=0;
delay_ms(10);
LCD_RESET=1;
delay_ms(120);
LCD_WR_REG(0xCF);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0xC1);
LCD_WR_DATA(0X30);
LCD_WR_REG(0xED);
LCD_WR_DATA(0x64);
LCD_WR_DATA(0x03);
LCD_WR_DATA(0X12);
LCD_WR_DATA(0X81);
LCD_WR_REG(0xE8);
LCD_WR_DATA(0x85);
LCD_WR_DATA(0x10);
LCD_WR_DATA(0x7A);
LCD_WR_REG(0xCB);
LCD_WR_DATA(0x39);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x34);
LCD_WR_DATA(0x02);
LCD_WR_REG(0xF7);
LCD_WR_DATA(0x20);
LCD_WR_REG(0xEA);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_REG(0xC0); //Power control
LCD_WR_DATA(0x1B); //VRH[5:0]
LCD_WR_REG(0xC1); //Power control
LCD_WR_DATA(0x01); //SAP[2:0];BT[3:0]
LCD_WR_REG(0xC5); //VCM control
LCD_WR_DATA(0x30); //3F
LCD_WR_DATA(0x30); //3C
LCD_WR_REG(0xC7); //VCM control2
LCD_WR_DATA(0XB7);
LCD_WR_REG(0x36); // Memory Access Control
LCD_WR_DATA(0x48);
LCD_WR_REG(0x3A);
LCD_WR_DATA(0x55);
LCD_WR_REG(0xB1);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x1A);
LCD_WR_REG(0xB6); // Display Function Control
LCD_WR_DATA(0x0A);
LCD_WR_DATA(0xA2);
LCD_WR_REG(0xF2); // 3Gamma Function Disable
LCD_WR_DATA(0x00);
LCD_WR_REG(0x26); //Gamma curve selected
LCD_WR_DATA(0x01);
LCD_WR_REG(0xE0); //Set Gamma
LCD_WR_DATA(0x0F);
LCD_WR_DATA(0x2A);
LCD_WR_DATA(0x28);
LCD_WR_DATA(0x08);
LCD_WR_DATA(0x0E);
LCD_WR_DATA(0x08);
LCD_WR_DATA(0x54);
LCD_WR_DATA(0XA9);
LCD_WR_DATA(0x43);
LCD_WR_DATA(0x0A);
LCD_WR_DATA(0x0F);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_REG(0XE1); //Set Gamma
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x15);
LCD_WR_DATA(0x17);
LCD_WR_DATA(0x07);
LCD_WR_DATA(0x11);
LCD_WR_DATA(0x06);
LCD_WR_DATA(0x2B);
LCD_WR_DATA(0x56);
LCD_WR_DATA(0x3C);
LCD_WR_DATA(0x05);
LCD_WR_DATA(0x10);
LCD_WR_DATA(0x0F);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x3F);
LCD_WR_DATA(0x0F);
LCD_WR_REG(0x2B);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x3f);
LCD_WR_REG(0x2A);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0xef);
LCD_WR_REG(0x11); //Exit Sleep
delay_ms(120);
LCD_WR_REG(0x29); //display on
}
void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy)
{
LCD_WR_REG(0x2A);
LCD_WR_DATA(stx>>8);
LCD_WR_DATA(stx&0xff);
LCD_WR_DATA(endx>>8);
LCD_WR_DATA(endx&0xff);
LCD_WR_REG(0x2B);
LCD_WR_DATA(sty>>8);
LCD_WR_DATA(sty&0xff);
LCD_WR_DATA(endy>>8);
LCD_WR_DATA(endy&0xff);
}
void LCD_Clear(unsigned int color)
{
unsigned int i,j;
LCD_SetArea(0,0,239,319);
LCD_WR_REG(0x2C);
for(i=0;i<320;i++)
{
for(j=0;j<240;j++)
{
LCD_WR_DATA(color>>8);
LCD_WR_DATA(color);
}
}
}
void main()
{
delay_ms(100);
LCD_Init();
while(1)
{
LCD_Clear(RED);
delay_ms(300);
LCD_Clear(WHITE);
delay_ms(300);
LCD_Clear(BLUE);
delay_ms(300);
LCD_Clear(GREEN);
delay_ms(300);
}
}
/* Adafruit 2.8" TFT LCD Sample
*
* Created: Tue Nov 4 2014
* Processor: ATmega328P
* Compiler: Arduino AVR
*/
#include <stdint.h>
#include <TFTv2.h>
#include <SPI.h>
void setup()
{ Serial.begin(9600);
SPSR |= (1 << SPI2X); // 2x SPI speed
TFT_BL_ON; // turn on the background light
Tft.TFTinit(); //init TFT library
Tft.drawLine(0,0,239,319,RED); //start: (0, 0) end: (239, 319), color : RED
Tft.drawVerticalLine(60,100,100,GREEN); // Draw a vertical line
// start: (60, 100) length: 100 color: green
Tft.drawHorizontalLine(30,60,150,BLUE); //Draw a horizontal line
//start: (30, 60), high: 150, color: blue
Tft.drawCircle(100, 100, 30,YELLOW); //center: (100, 100), r = 30 ,color : YELLOW
Tft.drawCircle(100, 200, 40,CYAN); // center: (100, 200), r = 10 ,color : CYAN
Tft.fillCircle(200, 100, 30,RED); //center: (200, 100), r = 30 ,color : RED
Tft.fillCircle(200, 200, 30,BLUE); //center: (200, 200), r = 30 ,color : BLUE
Tft.drawString("Hello",0,180,3,CYAN); // draw string: "hello", (0, 180), size: 3, color: CYAN
Tft.drawString("World!!",60,220,4,WHITE); // draw string: "world!!", (80, 230), size: 4, color: WHITE
// Vertical Scrolling Definition
Tft.sendCMD(0x33);
Tft.sendData(100);
Tft.sendData(200);
Tft.sendData(20);
}
unsigned int t = 0;
unsigned int pos = 0;
void loop()
{ t++;
if (t == 1000)
{ t = 0;
pos++;
// Vertical Scrolling Start Address
Tft.sendCMD(0x37);
Tft.sendData(100 + (pos % 200));
}
}
/*
2012 Copyright (c) Seeed Technology Inc.
Authors: Albert.Miao & Loovee,
Visweswara R (with initializtion code from TFT vendor)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc.,51 Franklin St,Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <TFTv2.h>
#include <SPI.h>
#define FONT_SPACE 6
#define FONT_X 8
#define FONT_Y 8
void TFT::sendCMD(INT8U index)
{
TFT_DC_LOW;
TFT_CS_LOW;
SPI.transfer(index);
TFT_CS_HIGH;
}
void TFT::WRITE_DATA(INT8U data)
{
TFT_DC_HIGH;
TFT_CS_LOW;
SPI.transfer(data);
TFT_CS_HIGH;
}
void TFT::sendData(INT16U data)
{
INT8U data1 = data>>8;
INT8U data2 = data&0xff;
TFT_DC_HIGH;
TFT_CS_LOW;
SPI.transfer(data1);
SPI.transfer(data2);
TFT_CS_HIGH;
}
void TFT::WRITE_Package(INT16U *data, INT8U howmany)
{
INT16U data1 = 0;
INT8U data2 = 0;
TFT_DC_HIGH;
TFT_CS_LOW;
INT8U count=0;
for(count=0;count<howmany;count++)
{
data1 = data[count]>>8;
data2 = data[count]&0xff;
SPI.transfer(data1);
SPI.transfer(data2);
}
TFT_CS_HIGH;
}
INT8U TFT::Read_Register(INT8U Addr, INT8U xParameter)
{
INT8U data=0;
sendCMD(0xd9); /* ext command */
WRITE_DATA(0x10+xParameter); /* 0x11 is the first Parameter */
TFT_DC_LOW;
TFT_CS_LOW;
SPI.transfer(Addr);
TFT_DC_HIGH;
data = SPI.transfer(0);
TFT_CS_HIGH;
return data;
}
void TFT::TFTinit (void)
{
SPI.begin();
TFT_CS_HIGH;
TFT_DC_HIGH;
INT8U i=0;
for(i=0;i<3;i++)
{
readID();
}
delay(500);
sendCMD(0x01);
delay(200);
sendCMD(0xCF);
WRITE_DATA(0x00);
WRITE_DATA(0x8B);
WRITE_DATA(0X30);
sendCMD(0xED);
WRITE_DATA(0x67);
WRITE_DATA(0x03);
WRITE_DATA(0X12);
WRITE_DATA(0X81);
sendCMD(0xE8);
WRITE_DATA(0x85);
WRITE_DATA(0x10);
WRITE_DATA(0x7A);
sendCMD(0xCB);
WRITE_DATA(0x39);
WRITE_DATA(0x2C);
WRITE_DATA(0x00);
WRITE_DATA(0x34);
WRITE_DATA(0x02);
sendCMD(0xF7);
WRITE_DATA(0x20);
sendCMD(0xEA);
WRITE_DATA(0x00);
WRITE_DATA(0x00);
sendCMD(0xC0); /* Power control */
WRITE_DATA(0x1B); /* VRH[5:0] */
sendCMD(0xC1); /* Power control */
WRITE_DATA(0x10); /* SAP[2:0];BT[3:0] */
sendCMD(0xC5); /* VCM control */
WRITE_DATA(0x3F);
WRITE_DATA(0x3C);
sendCMD(0xC7); /* VCM control2 */
WRITE_DATA(0XB7);
sendCMD(0x36); /* Memory Access Control */
WRITE_DATA(0x08);
sendCMD(0x3A);
WRITE_DATA(0x55);
sendCMD(0xB1);
WRITE_DATA(0x00);
WRITE_DATA(0x1B);
sendCMD(0xB6); /* Display Function Control */
WRITE_DATA(0x0A);
WRITE_DATA(0xA2);
sendCMD(0xF2); /* 3Gamma Function Disable */
WRITE_DATA(0x00);
sendCMD(0x26); /* Gamma curve selected */
WRITE_DATA(0x01);
sendCMD(0xE0); /* Set Gamma */
WRITE_DATA(0x0F);
WRITE_DATA(0x2A);
WRITE_DATA(0x28);
WRITE_DATA(0x08);
WRITE_DATA(0x0E);
WRITE_DATA(0x08);
WRITE_DATA(0x54);
WRITE_DATA(0XA9);
WRITE_DATA(0x43);
WRITE_DATA(0x0A);
WRITE_DATA(0x0F);
WRITE_DATA(0x00);
WRITE_DATA(0x00);
WRITE_DATA(0x00);
WRITE_DATA(0x00);
sendCMD(0XE1); /* Set Gamma */
WRITE_DATA(0x00);
WRITE_DATA(0x15);
WRITE_DATA(0x17);
WRITE_DATA(0x07);
WRITE_DATA(0x11);
WRITE_DATA(0x06);
WRITE_DATA(0x2B);
WRITE_DATA(0x56);
WRITE_DATA(0x3C);
WRITE_DATA(0x05);
WRITE_DATA(0x10);
WRITE_DATA(0x0F);
WRITE_DATA(0x3F);
WRITE_DATA(0x3F);
WRITE_DATA(0x0F);
sendCMD(0x11); /* Exit Sleep */
delay(120);
sendCMD(0x29); /* Display on */
fillScreen();
}
INT8U TFT::readID(void)
{
INT8U i=0;
INT8U data[3] ;
INT8U ID[3] = {0x00, 0x93, 0x41};
INT8U ToF=1;
for(i=0;i<3;i++)
{
data[i]=Read_Register(0xd3,i+1);
if(data[i] != ID[i])
{
ToF=0;
}
}
if(!ToF) /* data!=ID */
{
Serial.print("Read TFT ID failed, ID should be 0x09341, but read ID = 0x");
for(i=0;i<3;i++)
{
Serial.print(data[i],HEX);
}
Serial.println();
}
return ToF;
}
void TFT::setCol(INT16U StartCol,INT16U EndCol)
{
sendCMD(0x2A); /* Column Command address */
sendData(StartCol);
sendData(EndCol);
}
void TFT::setPage(INT16U StartPage,INT16U EndPage)
{
sendCMD(0x2B); /* Column Command address */
sendData(StartPage);
sendData(EndPage);
}
void TFT::fillScreen(INT16U XL, INT16U XR, INT16U YU, INT16U YD, INT16U color)
{
unsigned long XY=0;
unsigned long i=0;
if(XL > XR)
{
XL = XL^XR;
XR = XL^XR;
XL = XL^XR;
}
if(YU > YD)
{
YU = YU^YD;
YD = YU^YD;
YU = YU^YD;
}
XL = constrain(XL, MIN_X,MAX_X);
XR = constrain(XR, MIN_X,MAX_X);
YU = constrain(YU, MIN_Y,MAX_Y);
YD = constrain(YD, MIN_Y,MAX_Y);
XY = (XR-XL+1);
XY = XY*(YD-YU+1);
Tft.setCol(XL,XR);
Tft.setPage(YU, YD);
Tft.sendCMD(0x2c); /* start to write to display ra */
/* m */
TFT_DC_HIGH;
TFT_CS_LOW;
INT8U Hcolor = color>>8;
INT8U Lcolor = color&0xff;
for(i=0; i < XY; i++)
{
SPI.transfer(Hcolor);
SPI.transfer(Lcolor);
}
TFT_CS_HIGH;
}
void TFT::fillScreen(void)
{
Tft.setCol(0, 239);
Tft.setPage(0, 319);
Tft.sendCMD(0x2c); /* start to write to display ra */
/* m */
TFT_DC_HIGH;
TFT_CS_LOW;
for(INT16U i=0; i<38400; i++)
{
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
}
TFT_CS_HIGH;
}
void TFT::setXY(INT16U poX, INT16U poY)
{
setCol(poX, poX);
setPage(poY, poY);
sendCMD(0x2c);
}
void TFT::setPixel(INT16U poX, INT16U poY,INT16U color)
{
setXY(poX, poY);
sendData(color);
}
void TFT::drawChar( INT8U ascii, INT16U poX, INT16U poY,INT16U size, INT16U fgcolor)
{
if((ascii>=32)&&(ascii<=127))
{
;
}
else
{
ascii = '?'-32;
}
for (int i =0; i<FONT_X; i++ ) {
INT8U temp = pgm_read_byte(&simpleFont[ascii-0x20][i]);
for(INT8U f=0;f<8;f++)
{
if((temp>>f)&0x01)
{
fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
}
}
}
}
void TFT::drawString(const char *string,INT16U poX, INT16U poY, INT16U size,INT16U fgcolor)
{
while(*string)
{
drawChar(*string, poX, poY, size, fgcolor);
string++;
if(poX < MAX_X)
{
poX += FONT_SPACE*size; /* Move cursor right */
}
}
}
//fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
void TFT::fillRectangle(INT16U poX, INT16U poY, INT16U length, INT16U width, INT16U color)
{
fillScreen(poX, poX+length, poY, poY+width, color);
}
void TFT::drawHorizontalLine( INT16U poX, INT16U poY,
INT16U length,INT16U color)
{
setCol(poX,poX + length);
setPage(poY,poY);
sendCMD(0x2c);
for(INT16U i=0; i<length; i++)
sendData(color);
}
void TFT::drawLine( INT16U x0,INT16U y0,INT16U x1, INT16U y1,INT16U color)
{
int x = x1-x0;
int y = y1-y0;
int dx = abs(x), sx = x0<x1 ? 1 : -1;
int dy = -abs(y), sy = y0<y1 ? 1 : -1;
int err = dx+dy, e2; /* error value e_xy */
for (;;){ /* loop */
setPixel(x0,y0,color);
e2 = 2*err;
if (e2 >= dy) { /* e_xy+e_x > 0 */
if (x0 == x1) break;
err += dy; x0 += sx;
}
if (e2 <= dx) { /* e_xy+e_y < 0 */
if (y0 == y1) break;
err += dx; y0 += sy;
}
}
}
void TFT::drawVerticalLine( INT16U poX, INT16U poY, INT16U length,INT16U color)
{
setCol(poX,poX);
setPage(poY,poY+length);
sendCMD(0x2c);
for(INT16U i=0; i<length; i++)
sendData(color);
}
void TFT::drawRectangle(INT16U poX, INT16U poY, INT16U length, INT16U width,INT16U color)
{
drawHorizontalLine(poX, poY, length, color);
drawHorizontalLine(poX, poY+width, length, color);
drawVerticalLine(poX, poY, width,color);
drawVerticalLine(poX + length, poY, width,color);
}
void TFT::drawCircle(int poX, int poY, int r,INT16U color)
{
int x = -r, y = 0, err = 2-2*r, e2;
do {
setPixel(poX-x, poY+y,color);
setPixel(poX+x, poY+y,color);
setPixel(poX+x, poY-y,color);
setPixel(poX-x, poY-y,color);
e2 = err;
if (e2 <= y) {
err += ++y*2+1;
if (-x == y && e2 <= x) e2 = 0;
}
if (e2 > x) err += ++x*2+1;
} while (x <= 0);
}
void TFT::fillCircle(int poX, int poY, int r,INT16U color)
{
int x = -r, y = 0, err = 2-2*r, e2;
do {
drawVerticalLine(poX-x, poY-y, 2*y, color);
drawVerticalLine(poX+x, poY-y, 2*y, color);
e2 = err;
if (e2 <= y) {
err += ++y*2+1;
if (-x == y && e2 <= x) e2 = 0;
}
if (e2 > x) err += ++x*2+1;
} while (x <= 0);
}
void TFT::drawTraingle( int poX1, int poY1, int poX2, int poY2, int poX3, int poY3, INT16U color)
{
drawLine(poX1, poY1, poX2, poY2,color);
drawLine(poX1, poY1, poX3, poY3,color);
drawLine(poX2, poY2, poX3, poY3,color);
}
INT8U TFT::drawNumber(long long_num,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor)
{
INT8U char_buffer[10] = "";
INT8U i = 0;
INT8U f = 0;
if (long_num < 0)
{
f=1;
drawChar('-',poX, poY, size, fgcolor);
long_num = -long_num;
if(poX < MAX_X)
{
poX += FONT_SPACE*size; /* Move cursor right */
}
}
else if (long_num == 0)
{
f=1;
drawChar('0',poX, poY, size, fgcolor);
return f;
if(poX < MAX_X)
{
poX += FONT_SPACE*size; /* Move cursor right */
}
}
while (long_num > 0)
{
char_buffer[i++] = long_num % 10;
long_num /= 10;
}
f = f+i;
for(; i > 0; i--)
{
drawChar('0'+ char_buffer[i - 1],poX, poY, size, fgcolor);
if(poX < MAX_X)
{
poX+=FONT_SPACE*size; /* Move cursor right */
}
}
return f;
}
INT8U TFT::drawFloat(float floatNumber,INT8U decimal,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor)
{
INT16U temp=0;
float decy=0.0;
float rounding = 0.5;
INT8U f=0;
if(floatNumber<0.0)
{
drawChar('-',poX, poY, size, fgcolor);
floatNumber = -floatNumber;
if(poX < MAX_X)
{
poX+=FONT_SPACE*size; /* Move cursor right */
}
f =1;
}
for (INT8U i=0; i<decimal; ++i)
{
rounding /= 10.0;
}
floatNumber += rounding;
temp = (INT16U)floatNumber;
INT8U howlong=drawNumber(temp,poX, poY, size, fgcolor);
f += howlong;
if((poX+8*size*howlong) < MAX_X)
{
poX+=FONT_SPACE*size*howlong; /* Move cursor right */
}
if(decimal>0)
{
drawChar('.',poX, poY, size, fgcolor);
if(poX < MAX_X)
{
poX+=FONT_SPACE*size; /* Move cursor right */
}
f +=1;
}
decy = floatNumber-temp; /* decimal part, 4 */
for(INT8U i=0;i<decimal;i++)
{
decy *=10; /* for the next decimal */
temp = decy; /* get the decimal */
drawNumber(temp,poX, poY, size, fgcolor);
floatNumber = -floatNumber;
if(poX < MAX_X)
{
poX+=FONT_SPACE*size; /* Move cursor right */
}
decy -= temp;
}
f +=decimal;
return f;
}
INT8U TFT::drawFloat(float floatNumber,INT16U poX, INT16U poY,INT16U size,INT16U fgcolor)
{
INT8U decimal=2;
INT16U temp=0;
float decy=0.0;
float rounding = 0.5;
INT8U f=0;
if(floatNumber<0.0) /* floatNumber < 0 */
{
drawChar('-',poX, poY, size, fgcolor); /* add a '-' */
floatNumber = -floatNumber;
if(poX < MAX_X)
{
poX+=FONT_SPACE*size; /* Move cursor right */
}
f =1;
}
for (INT8U i=0; i<decimal; ++i)
{
rounding /= 10.0;
}
floatNumber += rounding;
temp = (INT16U)floatNumber;
INT8U howlong=drawNumber(temp,poX, poY, size, fgcolor);
f += howlong;
if((poX+8*size*howlong) < MAX_X)
{
poX+=FONT_SPACE*size*howlong; /* Move cursor right */
}
if(decimal>0)
{
drawChar('.',poX, poY, size, fgcolor);
if(poX < MAX_X)
{
poX += FONT_SPACE*size; /* Move cursor right */
}
f +=1;
}
decy = floatNumber-temp; /* decimal part, */
for(INT8U i=0;i<decimal;i++)
{
decy *=10; /* for the next decimal */
temp = decy; /* get the decimal */
drawNumber(temp,poX, poY, size, fgcolor);
floatNumber = -floatNumber;
if(poX < MAX_X)
{
poX += FONT_SPACE*size; /* Move cursor right */
}
decy -= temp;
}
f += decimal;
return f;
}
TFT Tft=TFT();
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
不错啊!有进步,慢慢来。
求4线SPI代码参考,我调了几天了,都是白屏啊?
一周热门 更多>