想试试attiny13能否驱动spi的320*135的ips高清屏,没想到真的成功了,一直担心1k的flash不够用,看来是完全没问题.
Program Memory Usage : 716 bytes 69.9 % Full
Data Memory Usage : 0 bytes 0.0 % Full
源码是从stm32移植的,没怎么整理,将就看吧,开发环境是atmel官方的avr studio7
/*
* lcd.c
*
* Created: 2020/3/27 22:27:25
* Author : Administrator
*/
#include <avr/io.h>
#include <util/delay.h>
//»±ÊÑÕÉ«
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //×ØÉ«
#define BRRED 0XFC07 //×غìÉ«
#define GRAY 0X8430 //»ÒÉ«
#define DARKBLUE 0X01CF //ÉîÀ¶É«
#define LIGHTBLUE 0X7D7C //dzÀ¶É«
#define GRAYBLUE 0X5458 //»ÒÀ¶É«
#define LIGHTGREEN 0X841F //dzÂÌÉ«
#define LGRAY 0XC618 //dz»ÒÉ«(PANNEL),´°Ìå±³¾°É«
#define LGRAYBLUE 0XA651 //dz»ÒÀ¶É«(Öмä²ãÑÕÉ«)
#define LBBLUE 0X2B12 //dz×ØÀ¶É«(Ñ¡ÔñÌõÄ¿µÄ·´É«)
#define USE_HORIZONTAL 2 //ÉèÖúáÆÁ»òÕßÊúÆÁÏÔʾ 0»ò1ΪÊúÆÁ 2»ò3ΪºáÆÁ
#define LCD_W 240
#define LCD_H 135
#define LCD_SCLK_Clr() PORTB&=0xfe//SCL=SCLK
#define LCD_SCLK_Set() PORTB|=0x01
#define LCD_MOSI_Clr() PORTB&=0xfd//SDA=MOSI
#define LCD_MOSI_Set() PORTB|=0x02
#define LCD_RES_Clr() PORTB&=0xfb//RES
#define LCD_RES_Set() PORTB|=0x04
#define LCD_DC_Clr() PORTB&=0xf7//DC
#define LCD_DC_Set() PORTB|=0x08
#define LCD_CS_Clr() PORTB&=0xef//CS
#define LCD_CS_Set() PORTB|=0x10
int main(void)
{
LCD_Init();
LCD_Fill(0,0,LCD_W,LCD_H,BLUE);
LCD_DrawPoint(20,20,WHITE);
/* Replace with your application code */
while (1)
{
LCD_Fill(0,0,LCD_W,LCD_H,BLUE);
LCD_Fill(0,0,LCD_W,LCD_H,GREEN);
LCD_Fill(0,0,LCD_W,LCD_H,RED);
}
}
void LCD_GPIO_Init(void){
DDRB=0xFF;
PORTB=0xff;
}
/******************************************************************************
º¯Êý˵Ã÷£ºLCD´®ÐÐÊý¾ÝдÈ뺯Êý
Èë¿ÚÊý¾Ý£ºdat ҪдÈëµÄ´®ÐÐÊý¾Ý
·µ»ØÖµ£º ÎÞ
******************************************************************************/
void LCD_Writ_Bus(uint8_t dat)
{
uint8_t i;
LCD_CS_Clr();
for(i=0;i<8;i++)
{
LCD_SCLK_Clr();
if(dat&0x80)
{
LCD_MOSI_Set();
}
else
{
LCD_MOSI_Clr();
}
LCD_SCLK_Set();
dat<<=1;
}
LCD_CS_Set();
}
void LCD_WR_REG(uint8_t dat){
LCD_DC_Clr();//дÃüÁî
LCD_Writ_Bus(dat);
LCD_DC_Set();//дÊý¾Ý
}
void LCD_WR_DATA8(uint8_t dat){
LCD_Writ_Bus(dat);
}
void LCD_Init(void)
{
LCD_GPIO_Init();//³õʼ»¯GPIO
LCD_RES_Clr();//¸´Î»
_delay_ms(100);
LCD_RES_Set();
_delay_ms(100);
LCD_WR_REG(0x11);
_delay_ms(120);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x19);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x54);
LCD_WR_DATA8(0x4C);
LCD_WR_DATA8(0x18);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x44);
LCD_WR_DATA8(0x51);
LCD_WR_DATA8(0x2F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x20);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x29);
}
/******************************************************************************
º¯Êý˵Ã÷£ºLCDдÈëÊý¾Ý
Èë¿ÚÊý¾Ý£ºdat дÈëµÄÊý¾Ý
·µ»ØÖµ£º ÎÞ
******************************************************************************/
void LCD_WR_DATA(uint16_t dat)
{
LCD_Writ_Bus(dat>>8);
LCD_Writ_Bus(dat);
}
/******************************************************************************
º¯Êý˵Ã÷£ºÉèÖÃÆðʼºÍ½áÊøµØÖ·
Èë¿ÚÊý¾Ý£ºx1,x2 ÉèÖÃÁеÄÆðʼºÍ½áÊøµØÖ·
y1,y2 ÉèÖÃÐеÄÆðʼºÍ½áÊøµØÖ·
·µ»ØÖµ£º ÎÞ
******************************************************************************/
void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
{
if(USE_HORIZONTAL==0)
{
LCD_WR_REG(0x2a);//ÁеØÖ·ÉèÖÃ
LCD_WR_DATA(x1+52);
LCD_WR_DATA(x2+52);
LCD_WR_REG(0x2b);//ÐеØÖ·ÉèÖÃ
LCD_WR_DATA(y1+40);
LCD_WR_DATA(y2+40);
LCD_WR_REG(0x2c);//´¢´æÆ÷д
}
else if(USE_HORIZONTAL==1)
{
LCD_WR_REG(0x2a);//ÁеØÖ·ÉèÖÃ
LCD_WR_DATA(x1+53);
LCD_WR_DATA(x2+53);
LCD_WR_REG(0x2b);//ÐеØÖ·ÉèÖÃ
LCD_WR_DATA(y1+40);
LCD_WR_DATA(y2+40);
LCD_WR_REG(0x2c);//´¢´æÆ÷д
}
else if(USE_HORIZONTAL==2)
{
LCD_WR_REG(0x2a);//ÁеØÖ·ÉèÖÃ
LCD_WR_DATA(x1+40);
LCD_WR_DATA(x2+40);
LCD_WR_REG(0x2b);//ÐеØÖ·ÉèÖÃ
LCD_WR_DATA(y1+53);
LCD_WR_DATA(y2+53);
LCD_WR_REG(0x2c);//´¢´æÆ÷д
}
else
{
LCD_WR_REG(0x2a);//ÁеØÖ·ÉèÖÃ
LCD_WR_DATA(x1+40);
LCD_WR_DATA(x2+40);
LCD_WR_REG(0x2b);//ÐеØÖ·ÉèÖÃ
LCD_WR_DATA(y1+52);
LCD_WR_DATA(y2+52);
LCD_WR_REG(0x2c);//´¢´æÆ÷д
}
}
/******************************************************************************
º¯Êý˵Ã÷£ºÔÚÖ¸¶¨ÇøÓòÌî³äÑÕÉ«
Èë¿ÚÊý¾Ý£ºxsta,ysta Æðʼ×ø±ê
xend,yend ÖÕÖ¹×ø±ê
color ÒªÌî³äµÄÑÕÉ«
·µ»ØÖµ£º ÎÞ
******************************************************************************/
void LCD_Fill(uint16_t xsta,uint16_t ysta,uint16_t xend,uint16_t yend,uint16_t color)
{
uint16_t i,j;
LCD_Address_Set(xsta,ysta,xend-1,yend-1);//ÉèÖÃÏÔʾ·¶Î§
for(i=ysta;i<yend;i++)
{
for(j=xsta;j<xend;j++)
{
LCD_WR_DATA(color);
}
}
}
void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color)
{
LCD_Address_Set(x,y,x,y);//ÉèÖùâ±êλÖÃ
LCD_WR_DATA(color);
}
离线
这个屏有购买链接吗?
离线
挺漂亮的, 围观围观
离线
纯色刷屏并不需要多大flash,但想存点图案或文字就有点紧张了。
离线