//---------------------------------------------------------------
// * Copyright (c) 2013, Biox
// * All rights reserved.
// * 文件名称: ST7735R-V02.h
// * 摘 要: 1.77TFT液晶横屏驱动
// * 当前版本: 1.0, yijian, 2013.03.19
// * 历史版本:
// (0,0)---------------------------(159,0)
// | |
// | |
// | |
// (0,127)-------------------------(159,127)
//---------------------------------------------------------------
#include "ST7735R-V02.h"
/*********************************************************************
* 函 数 名: ST7735_WriteData
* 功能描述: ST7735写数据
* 函数说明: 底层函数
* 调用函数: 无
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_WriteData(unsigned char n)
{
SET_RD;
SET_DC;
CLR_CS;
CLR_WR;
P4OUT = n;
SET_WR;
SET_CS;
}
/*********************************************************************
* 函 数 名: ST7735_WriteCommand
* 功能描述: ST7735写命令
* 函数说明: 底层函数
* 调用函数: 无
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_WriteCommand(unsigned char n)
{
SET_RD;
CLR_DC;
CLR_CS;
CLR_WR;
P4OUT = n;
SET_WR;
SET_CS;
}
/*********************************************************************
* 函 数 名: ST7735_ReadData
* 功能描述: ST7735读数据
* 函数说明: 底层函数
* 调用函数: 无
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
unsigned char ST7735_ReadData(unsigned char n)
{
}
/*********************************************************************
* 函 数 名: ST7735_Clr
* 功能描述: ST7735整屏填充(清屏)
* 函数说明: 底层函数
* 调用函数: 无
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_Clr(unsigned int color)
{
unsigned char x, y, ch, cl;
x = 0;
y = 0;
ch = (color&0xff00)>>8;
cl = color&0x00ff;
ST7735_WriteCommand(0x2A); //设置范围
ST7735_WriteData(0x00); //起始列
ST7735_WriteData(0x00);
ST7735_WriteData(0x00); //终止列
ST7735_WriteData(0x9f);
ST7735_WriteCommand(0x2B); //设置范围
ST7735_WriteData(0x00); //起始排
ST7735_WriteData(0x00);
ST7735_WriteData(0x00); //终止排
ST7735_WriteData(0x7f);
ST7735_WriteCommand(0x2C); //往GRAM写颜色
for(y=0;y<128;y++)
{
for(x=0;x<160;x++)
{
ST7735_WriteData(ch);
ST7735_WriteData(cl);
}
}
}
/*********************************************************************
* 函 数 名: ST7735_DrawPixel
* 功能描述: ST7735画点函数
* 函数说明: x:横坐标(0-160) ,y:纵坐标(0-128), Color:颜色
* 调用函数: ST7735_WriteCommand,ST7735_WriteData
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_DrawPixel(unsigned char x, unsigned char y, unsigned int Color)
{
ST7735_WriteCommand(0x2a); //设置点横坐标
ST7735_WriteData(0);
ST7735_WriteData(x);
ST7735_WriteCommand(0x2b); //设置点纵坐标
ST7735_WriteData(0);
ST7735_WriteData(y);
ST7735_WriteCommand(0x2c); //写点颜色
ST7735_WriteData(Color>>8);
ST7735_WriteData(Color&0xff);
}
/*********************************************************************
* 函 数 名: ST7735_DrawHorizonLine
* 功能描述: ST7735画横线
* 函数说明: x: 横坐标(0-160) ,y:纵坐标(0-128)
* Length:长度(0-160), Color: 颜色
* 调用函数: ST7735_WriteCommand,ST7735_WriteData
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_DrawHorizonLine(unsigned char x, unsigned char y, unsigned char Length,unsigned int Color)
{
unsigned char i;
ST7735_WriteCommand(0x2a); //设置点横坐标范围
ST7735_WriteData(0);
ST7735_WriteData(x);
ST7735_WriteData(0);
ST7735_WriteData(x+Length);
ST7735_WriteCommand(0x2b); //设置纵坐标范围
ST7735_WriteData(0);
ST7735_WriteData(y);
ST7735_WriteData(0);
ST7735_WriteData(y);
ST7735_WriteCommand(0x2c); //写颜色
for (i=0;i<Length;i++)
{
ST7735_WriteData(Color>>8);
ST7735_WriteData(Color&0xff);
}
}
/*********************************************************************
* 函 数 名: ST7735_DrawHorizonLine
* 功能描述: ST7735画竖线
* 函数说明: x: 横坐标(0-160) ,y:纵坐标(0-128)
* Length:长度(0-128), Color: 颜色
* 调用函数: ST7735_WriteCommand,ST7735_WriteData
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_DrawVerticalLine(unsigned int x, unsigned int y, unsigned int Length,unsigned int Color)
{
unsigned char i;
ST7735_WriteCommand(0x2a);
ST7735_WriteData(0);
ST7735_WriteData(x);
ST7735_WriteData(0);
ST7735_WriteData(x);
ST7735_WriteCommand(0x2b);
ST7735_WriteData(0);
ST7735_WriteData(y);
ST7735_WriteData(0);
ST7735_WriteData(y+Length);
ST7735_WriteCommand(0x2c);
for (i=0;i<Length;i++)
{
ST7735_WriteData(Color>>8);
ST7735_WriteData(Color&0xff);
}
}
/*********************************************************************
* 函 数 名: ST7735_DrawRectFill
* 功能描述: ST7735矩形填充
* 函数说明: x: 横坐标(0-160) ,y:纵坐标(0-128)
* Length:长度(0-160), Width:宽度(0-128), Color: 颜色
* 调用函数: ST7735_WriteCommand,ST7735_WriteData
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_DrawRectFill(unsigned char x, unsigned char y, unsigned char xLength, unsigned char yLength,unsigned Color)
{
unsigned char i,j;
ST7735_WriteCommand(0x2a);
ST7735_WriteData(0);
ST7735_WriteData(x);
ST7735_WriteData(0);
ST7735_WriteData(x+xLength-1);
ST7735_WriteCommand(0x2b);
ST7735_WriteData(0);
ST7735_WriteData(y);
ST7735_WriteData(0);
ST7735_WriteData(y+yLength-1);
ST7735_WriteCommand(0x2c);
for (i=0;i<yLength;i++)
{
for (j=0;j<xLength;j++)
{
ST7735_WriteData(Color>>8);
ST7735_WriteData(Color&0xff);
}
}
}
/*********************************************************************
* 函 数 名: ST7735_SleepIn
* 功能描述: ST7735进入睡眠模式
* 函数说明: 无
* 调用函数: ST7735_WriteCommand
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_SleepIn(void)
{
ST7735_WriteCommand(0x10);
}
/*********************************************************************
* 函 数 名: ST7735_SleepOut
* 功能描述: ST7735退出睡眠模式
* 函数说明: 无
* 调用函数: ST7735_WriteCommand
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_SleepOut(void)
{
ST7735_WriteCommand(0x11);
}
/*********************************************************************
* 函 数 名: ST7735_Init
* 功能描述: ST7735初始化
* 函数说明: 无
* 调用函数: ST7735_WriteCommand,ST7735_WriteData
* 全局变量: 无
* 输 入:
* 返 回:
***********************************************************************/
void ST7735_Init(void)
{
unsigned int i;
P4OUT = 0X00;
CLR_RD;
CLR_WR;
SET_CS;
CLR_DC;
SET_RES; //复位延时
for(i=0;i<1000;i++);
CLR_RES;
for(i=0;i<50000;i++);
SET_RES;
for(i=0;i<50000;i++);
ST7735_WriteCommand(0x11); //Sleep out
for(i=0;i<50000;i++);
//ST7735R Frame Rate
ST7735_WriteCommand(0xB1);ST7735_WriteData(0x01);ST7735_WriteData(0x2C);ST7735_WriteData(0x2D);
ST7735_WriteCommand(0xB2);ST7735_WriteData(0x01);ST7735_WriteData(0x2C);ST7735_WriteD