?? 3510i.c
字號:
#include "3510i.h"
#include "math.h"
void LCD_Delay(void)
{
uint16_t i;
for(i = 0; i < 32768; i ++)
asm("NOP");
}
void LCD_Reset(void)
{
cbi(LCD_RST_PORT, LCD_RST); //set RST = L
LCD_Delay();
sbi(LCD_RST_PORT, LCD_RST); //set RST = H
LCD_Delay();
}
void LCD_SendCommand(uint8_t cmd)
{
sbi(LCD_SIO_DDR, LCD_SIO); //set SDI.DDR = 1
cbi(LCD_CS_PORT, LCD_CS); //set CS = L
cbi(LCD_SCL_PORT, LCD_SCL); //set SCK = L
cbi(LCD_SIO_PORT, LCD_SIO); //send 0, for command
sbi(LCD_SCL_PORT, LCD_SCL); //set SCK = H, latch data
//Bit 0(MSB)
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x80)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 1
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x40)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 2
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x20)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 3
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x10)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 4
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x08)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 5
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x04)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 6
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x02)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 7(LSB)
cbi(LCD_SCL_PORT, LCD_SCL);
if(cmd & 0x01)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//done
}
void LCD_SendData(uint8_t data)
{
sbi(LCD_SIO_DDR, LCD_SIO); //set SDI.DDR = 1
cbi(LCD_CS_PORT, LCD_CS); //set CS = L
cbi(LCD_SCL_PORT, LCD_SCL); //set SCK = L
sbi(LCD_SIO_PORT, LCD_SIO); //send 1, for command
sbi(LCD_SCL_PORT, LCD_SCL); //set SCK = H, latch data
//Bit 0(MSB)
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x80)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 1
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x40)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 2
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x20)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 3
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x10)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 4
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x08)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 5
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x04)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 6
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x02)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//Bit 7(LSB)
cbi(LCD_SCL_PORT, LCD_SCL);
if(data & 0x01)
sbi(LCD_SIO_PORT, LCD_SIO);
else
cbi(LCD_SIO_PORT, LCD_SIO);
sbi(LCD_SCL_PORT, LCD_SCL);
//done
}
void LCD_ReadDummy(void)
{
cbi(LCD_SIO_DDR, LCD_SIO); //set SDI.DDR = 0
sbi(LCD_SIO_PORT, LCD_SIO);
cbi(LCD_CS_PORT, LCD_CS); //set CS = L
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
}
uint8_t LCD_ReadData(void)
{
uint8_t r = 0;
cbi(LCD_SIO_DDR, LCD_SIO); //set SDI.DDR = 0
sbi(LCD_SIO_PORT, LCD_SIO);
cbi(LCD_CS_PORT, LCD_CS); //set CS = L
//Bit 0(MSB)
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x80;
else
r &= ~0x80;
//Bit 1
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x40;
else
r &= ~0x40;
//Bit 2
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x20;
else
r &= ~0x20;
//Bit 3
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x10;
else
r &= ~0x10;
//Bit 4
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x08;
else
r &= ~0x08;
//Bit 5
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x04;
else
r &= ~0x04;
//Bit 6
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x02;
else
r &= ~0x02;
//Bit 7(LSB)
cbi(LCD_SCL_PORT, LCD_SCL);
sbi(LCD_SCL_PORT, LCD_SCL);
if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
r |= 0x01;
else
r &= ~0x01;
//done
return r;
}
void LCD_Initialize(void)
{
uint8_t i;
sbi(LCD_RST_PORT, LCD_RST); //set RST = H
sbi(LCD_RST_DDR, LCD_RST); //set RST.DDR = 1
sbi(LCD_CS_PORT, LCD_CS); //set CS = H
sbi(LCD_CS_DDR, LCD_CS); //set CS.DDR = 1
cbi(LCD_SIO_PORT, LCD_SIO); //set SDI = L
cbi(LCD_SIO_DDR, LCD_SIO); //set SDI.DDR = 0
sbi(LCD_SCL_PORT, LCD_SCL); //set SCK = H
sbi(LCD_SCL_DDR, LCD_SCL); //set SCK.DDR = 1
LCD_Reset();
LCD_SendCommand(0x01); //software reset
LCD_DataOver();
LCD_Delay();
LCD_SendCommand(0xc6); //initial escape
LCD_DataOver();
LCD_SendCommand(0xb9); //refresh set
LCD_SendData(0x00);
LCD_DataOver();
LCD_SendCommand(0xb6); //display control
LCD_SendData(0x80);
LCD_SendData(0x7f);
LCD_SendData(0x14);
LCD_SendData(84);
LCD_SendData(69);
LCD_SendData(82);
LCD_SendData(67);
LCD_DataOver();
LCD_SendCommand(0xb3); //gray scale position set
LCD_SendData(1);
LCD_SendData(2);
LCD_SendData(4);
LCD_SendData(8);
LCD_SendData(16);
LCD_SendData(30);
LCD_SendData(40);
LCD_SendData(50);
LCD_SendData(60);
LCD_SendData(70);
LCD_SendData(80);
LCD_SendData(90);
LCD_SendData(100);
LCD_SendData(110);
LCD_SendData(127);
LCD_DataOver();
LCD_SendCommand(0xb5); //gamma curve set
LCD_SendData(0x01);
LCD_DataOver();
LCD_SendCommand(0xbd); //common driver output select
LCD_SendData(0x00);
LCD_DataOver();
LCD_SendCommand(0xbe); //power control
LCD_SendData(0x04);
LCD_DataOver();
LCD_SendCommand(0x11); //sleep out
LCD_DataOver();
LCD_SendCommand(0xba); //voltage control
LCD_SendData(127);
LCD_SendData(3);
LCD_DataOver();
LCD_SendCommand(0xb7); //temperature gradient set
for(i = 0; i < 14; i ++)
LCD_SendData(0x00);
LCD_DataOver();
LCD_SendCommand(0x29); //display ON
LCD_DataOver();
LCD_SendCommand(0x03); //booster voltage ON
LCD_DataOver();
LCD_Delay();
LCD_SendCommand(0x20); //display inversion OFF
LCD_DataOver();
LCD_SendCommand(0x3a); //interface pixel format
LCD_SendData(0x02);
LCD_DataOver();
LCD_SendCommand(0x2d); //colour set
//red
LCD_SendData(0x00);
LCD_SendData(0x02);
LCD_SendData(0x03);
LCD_SendData(0x04);
LCD_SendData(0x05);
LCD_SendData(0x06);
LCD_SendData(0x08);
//green
LCD_SendData(0x0f);
LCD_SendData(0x00);
LCD_SendData(0x02);
LCD_SendData(0x03);
LCD_SendData(0x04);
LCD_SendData(0x05);
LCD_SendData(0x06);
LCD_SendData(0x08);
LCD_SendData(0x0f);
//blue
LCD_SendData(0x00);
LCD_SendData(0x03);
LCD_SendData(0x06);
LCD_SendData(0x0f);
LCD_DataOver();
LCD_SendCommand(0x25); //write contrast
LCD_SendData(72);
LCD_DataOver();
LCD_BGColor = 0x00;
LCD_PenColor = 0xff;
}
void LCD_ClearScreen(void)
{
uint8_t x, y;
LCD_SendCommand(0x2a); //column address set
LCD_SendData(0);
LCD_SendData(97);
LCD_DataOver();
LCD_SendCommand(0x2b); //page address set
LCD_SendData(0);
LCD_SendData(66);
LCD_DataOver();
LCD_SendCommand(0x2c); //memory write
for(y = 0; y < 67; y ++)
for(x = 0; x < 98; x ++)
LCD_SendData(LCD_BGColor);
LCD_DataOver();
}
void LCD_ReadPixel(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t *b)
{
uint8_t x, y;
LCD_SendCommand(0x2a); //column address set
LCD_SendData(x1);
LCD_SendData(x2);
LCD_DataOver();
LCD_SendCommand(0x2b); //page address set
LCD_SendData(y1);
LCD_SendData(y2);
LCD_DataOver();
LCD_SendCommand(0x2e); //RAM data read
for(y = y1; y <= y2; y ++)
for(x = x1; x <= x2; x ++)
{
LCD_ReadDummy();
*(b ++) = LCD_ReadData();
}
LCD_DataOver();
LCD_SendCommand(0x00); //NOP
LCD_SendData(0x00);
LCD_DataOver();
}
void LCD_WritePixel(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t *b)
{
uint8_t x, y;
LCD_SendCommand(0x2a); //column address set
LCD_SendData(x1);
LCD_SendData(x2);
LCD_DataOver();
LCD_SendCommand(0x2b); //page address set
LCD_SendData(y1);
LCD_SendData(y2);
LCD_DataOver();
LCD_SendCommand(0x2c); //memory write
for(y = y1; y <= y2; y ++)
for(x = x1; x <= x2; x ++)
LCD_SendData(*(b ++));
LCD_DataOver();
}
void LCD_DrawPoint(uint8_t x, uint8_t y)
{
LCD_SendCommand(0x2a); //column address set
LCD_SendData(x);
LCD_SendData(x);
LCD_DataOver();
LCD_SendCommand(0x2b); //page address set
LCD_SendData(y);
LCD_SendData(y);
LCD_DataOver();
LCD_SendCommand(0x2c); //memory write
LCD_SendData(LCD_PenColor);
LCD_DataOver();
}
void LCD_DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
uint8_t x, y, t;
if((x1 == x2) && (y1 == y2))
LCD_DrawPoint(x1, y1);
else if(abs(y2 - y1) > abs(x2 - x1))
{
if(y1 > y2)
{
t = y1;
y1 = y2;
y2 = t;
t = x1;
x1 = x2;
x2 = t;
}
for(y = y1; y <= y2; y ++)
{
x = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
LCD_DrawPoint(x, y);
}
}
else
{
if(x1 > x2)
{
t = y1;
y1 = y2;
y2 = t;
t = x1;
x1 = x2;
x2 = t;
}
for(x = x1; x <= x2; x ++)
{
y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
LCD_DrawPoint(x, y);
}
}
}
void LCD_DrawRectangle(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
{
LCD_DrawLine(x1, y1, x2, y1);
LCD_DrawLine(x2, y1, x2, y2);
LCD_DrawLine(x2, y2, x1, y2);
LCD_DrawLine(x1, y2, x1, y1);
}
void LCD_TextOutASCII(uint8_t c, uint8_t x, uint8_t y)
{
uint8_t b[60];
uint8_t *buf = &b[0];
uint8_t font[8];
uint8_t i;
uint32_t offset;
for(i = 0; i < 60; i ++)
b[i] = LCD_BGColor;
offset = 512 + (c - 0x20) * 8;
FS_Seek(LCD_ASCIIFontFile, offset);
FS_Read(LCD_ASCIIFontFile, font, 8);
for(i = 0; i < 7; i ++)
{
if(font[i] & 0x80)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x40)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x20)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x10)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x08)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x04)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x02)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x01)
*buf = LCD_PenColor;
buf ++;
}
if(font[7] & 0x80)
*buf = LCD_PenColor;
buf ++;
if(font[7] & 0x40)
*buf = LCD_PenColor;
buf ++;
if(font[7] & 0x20)
*buf = LCD_PenColor;
buf ++;
if(font[7] & 0x10)
*buf = LCD_PenColor;
LCD_WritePixel(x, y, x + 5, y + 9, b);
}
void LCD_TextOutGB2312(uint8_t ch, uint8_t cl, uint8_t x, uint8_t y)
{
uint8_t b[121];
uint8_t *buf = &b[0];
uint8_t font[16];
uint8_t i;
uint32_t offset;
for(i = 0; i < 121; i ++)
b[i] = LCD_BGColor;
offset = 512 + (((uint32_t)ch - 0x81) * 192 + ((uint32_t)cl - 0x40)) * 16;
FS_Seek(LCD_GB2312FontFile, offset);
FS_Read(LCD_GB2312FontFile, font, 16);
for(i = 0; i < 15; i ++)
{
if(font[i] & 0x80)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x40)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x20)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x10)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x08)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x04)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x02)
*buf = LCD_PenColor;
buf ++;
if(font[i] & 0x01)
*buf = LCD_PenColor;
buf ++;
}
if(font[15] & 0x80)
*buf = LCD_PenColor;
LCD_WritePixel(x, y, x + 10, y + 10, b);
}
void LCD_TextOut(char *s, uint8_t x, uint8_t y)
{
while(*s)
{
if((*s < 0x80) && (*s >= 0x20))
{
LCD_TextOutASCII(*s, x, y + 2);
x += 6;
}
else if((*s > 0x80) && (*(s + 1) >= 0x40))
{
LCD_TextOutGB2312(*s, *(s + 1), x, y);
x += 12;
s ++;
}
if(x > 92)
{
x = 0;
y += 12;
}
s ++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -