#include "spi_tft.h"
#include "spi_tft_FONT.h"
u8 RxBuf[64];
u8 cnt=0;
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;
//画笔颜色,背景颜色
u16 POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;
u16 DeviceCode;
//******************************************************************
//函数名: SPI_Master_Conf
//功能: 硬件SPI主设备初始化
//输入参数:无
//返回值: 无
//******************************************************************
void SPI_Master_Conf(void)
{
CLK_PCKENR1 |= 0x02; //打开SPI时钟
/*PC6、PC5设置为输出,最大10MHz*/
PC_DDR |= 0x60;
PC_CR1 |= 0x60;
PC_CR2 |= 0x60;
SPI_CR1 = 0x04;
SPI_CR2 = 0x03;
SPI_CR1|= 0x40;
/*
SPI_CR1_SPE = 0; //禁止SPI
SPI_CR1_LSBFIRST = 0; //先发送MSB
SPI_CR1_BR = 0; //波特率设为 fbus 16MHz
SPI_CR1_MSTR = 1; //主模式
SPI_CR1_CPOL = 1; //空闲状态时SCK为高电平
SPI_CR1_CPHA = 1; //数据从第二个时钟边沿开始采样
SPI_CR2_BDM = 0; //双线单向模式
SPI_CR2_SSM = 1; //使能软件从设备管理
SPI_CR2_SSI = 1; //内部从设备选择为主模式
SPI_CR1_SPE = 1; //使能SPI
*/
}
//******************************************************************
//函数名: SPI_Slave_Conf
//功能: 硬件SPI从设备初始化
//输入参数:无
//返回值: 无
//******************************************************************
void SPI_Slave_Conf(void)
{
// SPI_CR1_LSBFIRST = 0; //先发送MSB
// SPI_CR1_SPE = 0; //禁止SPI
SPI_CR1_BR = 3; //波特率设为 fbus/16 1MHz
SPI_CR1_MSTR = 0; //从模式
SPI_CR1_CPOL = 1; //空闲状态时SCK为高电平
SPI_CR1_CPHA = 1; //数据从第二个时钟边沿开始采样
// SPI_CR2_BDM = 0; //双线单向模式
SPI_CR2_SSM = 1; //使能软件从设备管理
SPI_CR2_SSI = 1; //内部从设备选择为从模式
SPI_ICR_RXIE = 1; //开启接收中断
SPI_CR1_SPE = 1; //使能SPI
}
//******************************************************************
//函数名: SPI_WriteByte
//功能: 硬件SPI读写一个字节数据
//输入参数:byte:数据
//返回值: 无
//******************************************************************
u8 SPI_WriteByte(u8 byte)
{
while(SPI_SR_TXE==0);
SPI_DR = byte;
while(SPI_SR_RXNE==0);
return SPI_DR;
}
#pragma vector=SPI_RXNE_vector
__interrupt void SPI_RXNE_IRQHandler(void)
{
RxBuf[cnt++]=SPI_DR;
if(cnt==64) cnt=0;
}
//******************************************************************
//函数名: LCD_GPIO_Init
//功能: LCD管脚初始化
//输入参数:无
//返回值: 无
//******************************************************************
void LCD_GPIO_Init(void)
{
PC_DDR|=0x1C; //PC4 PC3 PC2 输出
PC_CR1|=0x1C; //PC4 PC3 PC2 推挽
PC_CR2&=0xE3;
}
//******************************************************************
//函数名: LCD_WR_REG
//功能: 向液晶屏总线写入写16位指令
//输入参数:Reg:待写入的指令值
//返回值: 无
//******************************************************************
void LCD_WR_REG(u16 data)
{
LCD_CS_CLR;
LCD_RS_CLR;
SPI_WriteByte(data);
LCD_CS_SET;
}
//******************************************************************
//函数名: LCD_WR_DATA
//功能: 向液晶屏总线写入写8位数据
//输入参数:Data:待写入的数据
//返回值: 无
//******************************************************************
void LCD_WR_DATA(u8 data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteByte(data);
LCD_CS_SET;
}
//******************************************************************
//函数名: LCD_DrawPoint_16Bit
//功能: 8位总线下如何写入一个16位数据
//输入参数:(x,y):光标坐标
//返回值: 无
//******************************************************************
void LCD_WR_DATA_16Bit(u16 data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteByte(data>>8);
SPI_WriteByte(data);
LCD_CS_SET;
}
//******************************************************************
//函数名: LCD_WriteReg
//功能: 写寄存器数据
//输入参数:LCD_Reg:寄存器地址
// LCD_RegValue:要写入的数据
//返回值: 无
//******************************************************************
void LCD_WriteReg(u16 LCD_Reg, u16 LCD_RegValue)
{
LCD_WR_REG(LCD_Reg);
LCD_WR_DATA(LCD_RegValue);
}
//******************************************************************
//函数名: LCD_WriteRAM_Prepare
//功能: 开始写GRAM
// 在给液晶屏传送RGB数据前,应该发送写GRAM指令
//输入参数:无
//返回值: 无
//******************************************************************
void LCD_WriteRAM_Prepare(void)
{
LCD_WR_REG(lcddev.wramcmd);
}
//******************************************************************
//函数名: LCD_DrawPoint
//功能: 在指定位置写入一个像素点数据
//输入参数:(x,y):光标坐标
//返回值: 无
//******************************************************************
void LCD_DrawPoint(u16 x,u16 y)
{
LCD_SetCursor(x,y);//设置光标位置
LCD_WR_DATA_16Bit(POINT_COLOR);
}
//******************************************************************
//函数名: LCD_Reset
//功能: LCD复位函数,液晶初始化前要调用此函数
//输入参数:无
//返回值: 无
//******************************************************************
void LCD_RESET(void)
{
LCD_RST_CLR;
delay_nms(10);
LCD_RST_SET;
delay_nms(5);
}
//******************************************************************
//函数名: LCD_Init
//功能: LCD初始化
//输入参数:无
//返回值: 无
//******************************************************************
void LCD_Init(void)
{
SPI_Master_Conf();
LCD_GPIO_Init();
LCD_RESET(); //液晶屏复位
//************* Start Initial Sequence **********//
//开始初始化液晶屏
LCD_WR_REG(0x11);//Sleep exit
delay_nms(10);
//ST7735R Frame Rate
LCD_WR_REG(0xB1);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x2D);
LCD_WR_REG(0xB2);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x2D);
LCD_WR_REG(0xB3);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x2D);
LCD_WR_DATA(0x01);
LCD_WR_DATA(0x2C);
LCD_WR_DATA(0x2D);
LCD_WR_REG(0xB4); //Column inversion
LCD_WR_DATA(0x07);
//ST7735R Power Sequence
LCD_WR_REG(0xC0);
LCD_WR_DATA(0xA2);
LCD_WR_DATA(0x02);
LCD_WR_DATA(0x84);
LCD_WR_REG(0xC1);
LCD_WR_DATA(0xC5);
LCD_WR_REG(0xC2);
LCD_WR_DATA(0x0A);
LCD_WR_DATA(0x00);
LCD_WR_REG(0xC3);
LCD_WR_DATA(0x8A);
LCD_WR_DATA(0x2A);
LCD_WR_REG(0xC4);
LCD_WR_DATA(0x8A);
LCD_WR_DATA(0xEE);
LCD_WR_REG(0xC5); //VCOM
LCD_WR_DATA(0x0E);
LCD_WR_REG(0x36); //MX, MY, RGB mode
LCD_WR_DATA(0xC8);
//ST7735R Gamma Sequence
LCD_WR_REG(0xe0);
LCD_WR_DATA(0x0f);
LCD_WR_DATA(0x1a);
LCD_WR_DATA(0x0f);
LCD_WR_DATA(0x18);
LCD_WR_DATA(0x2f);
LCD_WR_DATA(0x28);
LCD_WR_DATA(0x20);
LCD_WR_DATA(0x22);
LCD_WR_DATA(0x1f);
LCD_WR_DATA(0x1b);
LCD_WR_DATA(0x23);
LCD_WR_DATA(0x37);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x07);
LCD_WR_DATA(0x02);
LCD_WR_DATA(0x10);
LCD_WR_REG(0xe1);
LCD_WR_DATA(0x0f);
LCD_WR_DATA(0x1b);
LCD_WR_DATA(0x0f);
LCD_WR_DATA(0x17);
LCD_WR_DATA(0x33);
LCD_WR_DATA(0x2c);
LCD_WR_DATA(0x29);
LCD_WR_DATA(0x2e);
LCD_WR_DATA(0x30);
LCD_WR_DATA(0x30);
LCD_WR_DATA(0x39);
LCD_WR_DATA(0x3f);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x07);
LCD_WR_DATA(0x03);
LCD_WR_DATA(0x10);
LCD_WR_REG(0x2a);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x7f);
LCD_WR_REG(0x2b);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x00);
LCD_WR_DATA(0x9f);
LCD_WR_REG(0xF0); //Enable test command
LCD_WR_DATA(0x01);
LCD_WR_REG(0xF6); //Disable ram power save mode
LCD_WR_DATA(0x00);
LCD_WR_REG(0x3A); //65k mode
LCD_WR_DATA(0x05);
LCD_WR_REG(0x29);//Display on
LCD_SetParam();//设置LCD参数
LCD_Clear(BLACK);
}
//******************************************************************
//函�
没有合适的资源?快使用搜索试试~ 我知道了~
stm8s_demo
共156个文件
o:29个
cout:29个
lst:29个
4星 · 超过85%的资源 需积分: 48 479 下载量 194 浏览量
2016-03-07
00:32:31
上传
评论 9
收藏 1.98MB ZIP 举报
温馨提示
stm8s在IAR环境下的项目工程,包括了SPI、IIC、PWM、AWU、USART、EEPROM等片上硬件的初始化代码。
资源推荐
资源详情
资源评论
收起资源包目录
stm8s_demo (156个子文件)
demo.cspy.bat 1KB
demo.pbd.browse 289KB
spi_tft.c 19KB
5110.c 9KB
sht2x.c 6KB
iic_bmp085.c 5KB
5110_font.c 5KB
iic.c 2KB
iic_hmc5883.c 2KB
clock.c 975B
pwm.c 960B
awu.c 857B
uart.c 824B
eeprom.c 789B
exit.c 682B
timer.c 652B
gpio.c 624B
adc.c 618B
delay.c 560B
led.c 386B
main.c 320B
stm8s_uart1.pbi.cout 10KB
stm8s_adc1.pbi.cout 10KB
stm8s_gpio.pbi.cout 10KB
stm8s_tim2.pbi.cout 10KB
stm8s_tim4.pbi.cout 10KB
stm8s_spi.pbi.cout 10KB
stm8s_i2c.pbi.cout 10KB
stm8s_clk.pbi.cout 10KB
iic_bmp085.pbi.cout 10KB
5110_font.pbi.cout 10KB
eeprom.pbi.cout 10KB
spi_tft.pbi.cout 10KB
timer.pbi.cout 10KB
clock.pbi.cout 10KB
exit.pbi.cout 10KB
uart.pbi.cout 10KB
main.pbi.cout 10KB
gpio.pbi.cout 10KB
awu.pbi.cout 10KB
pwm.pbi.cout 10KB
iic.pbi.cout 10KB
adc.pbi.cout 10KB
sht2x.pbi.cout 10KB
5110.pbi.cout 10KB
led.pbi.cout 10KB
iic_hmc5883.pbi.cout 10KB
delay.pbi.cout 10KB
font.pbi.cout 10KB
stm8s_it.pbi.cout 10KB
demo.dbgdt 6KB
demo.dep 16KB
demo.dni 1KB
demo.ewd 11KB
demo.ewp 44KB
demo.eww 158B
spi_tft_FONT.H 7KB
5110_font.h 5KB
spi_tft.h 4KB
5110.h 2KB
iic_bmp085.h 2KB
sht2x.h 1KB
main.h 749B
iic_hmc5883.h 529B
gpio.h 319B
eeprom.h 272B
iic.h 252B
delay.h 233B
clock.h 217B
led.h 154B
awu.h 148B
uart.h 142B
adc.h 118B
exit.h 105B
pwm.h 99B
timer.h 95B
demo.hex 15KB
cspycomm.log 39B
stm8s_tim2.lst 72KB
stm8s_i2c.lst 49KB
stm8s_uart1.lst 42KB
stm8s_adc1.lst 38KB
stm8s_clk.lst 38KB
spi_tft.lst 35KB
stm8s_it.lst 24KB
stm8s_spi.lst 24KB
stm8s_tim4.lst 22KB
5110.lst 17KB
stm8s_gpio.lst 15KB
sht2x.lst 12KB
iic_bmp085.lst 10KB
iic_hmc5883.lst 10KB
5110_font.lst 9KB
font.lst 8KB
iic.lst 6KB
pwm.lst 4KB
uart.lst 4KB
gpio.lst 4KB
clock.lst 4KB
awu.lst 4KB
共 156 条
- 1
- 2
DevinTT
- 粉丝: 268
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页