AVR驱动3.2英寸tft LCD(ssd1289)
时间:11-20
来源:互联网
点击:
管脚连接
#include LCD.h>
#include
#include
#define Setbit(val,bitn) (val|=(1<(bitn)))
#define Clcbit(val,bitn) (val&=~(1<(bitn)))
void delay_Nms(int n)
{
unsigned int i;
for(i=1;i<(300*n);i++);
}
void LCD_WR_DATA(char VH,char VL)
{
Setbit(PORTB,1);//RS=1 PB1
Setbit(PORTB,3);//RD=1 PB3
Setbit(PORTB,2);//WR=1 PB2
PORTD=VH;
PORTA=VL;
Clcbit(PORTB,0);//CS=0 PB0
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,0);//CS=1 PB0
Setbit(PORTB,2);//WR=1 PB2
}
void LCD_WR_ADDR(char addr)
{
Clcbit(PORTB,1);//RS=0 PB1
Setbit(PORTB,3);//RD=1 PB3
Setbit(PORTB,2);//WR=1 PB2
PORTD=0;
PORTA=addr;
Clcbit(PORTB,0);//CS=0 PB0
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,0);//CS=1 PB0
Setbit(PORTB,2);//WR=1 PB2
}
void LCD_WR_CMD(char addr,char cmdH,char cmdL)
{
LCD_WR_ADDR(addr);
LCD_WR_DATA(cmdH,cmdL);
}
void LCD_SetCursor(short Xpos,short Ypos)
{
LCD_WR_CMD(0x4f,(Xpos>>8),Xpos);
LCD_WR_CMD(0x4e,(Ypos>>8),Ypos);
}
void LCD_DrawPoint(short Xpos,short Ypos,short POINT_COLOR)
{
LCD_SetCursor(Xpos,Ypos);
LCD_WR_CMD(0x22,(POINT_COLOR>>8),POINT_COLOR);
}
void LCD_Init(void)
{
LCD_WR_CMD(0x00,0x00,0x01);delay_Nms(10);
LCD_WR_CMD(0x03,0xA8,0xA4);delay_Nms(5);
LCD_WR_CMD(0x0C,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x0D,0x08,0x0C);delay_Nms(5);
LCD_WR_CMD(0x0E,0x2B,0x00);delay_Nms(5);
LCD_WR_CMD(0x1E,0x00,0xB0);delay_Nms(5);
LCD_WR_CMD(0x01,0x2B,0x3F);delay_Nms(5);
LCD_WR_CMD(0x02,0x06,0x00);delay_Nms(5);
LCD_WR_CMD(0x10,0x00,0x00);delay_Nms(30);
LCD_WR_CMD(0x11,0x60,0x70);delay_Nms(5);
LCD_WR_CMD(0x05,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x06,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x16,0xEF,0x1C);delay_Nms(5);//
LCD_WR_CMD(0x17,0x00,0x03);delay_Nms(5);
LCD_WR_CMD(0x07,0x01,0x33);delay_Nms(5);
LCD_WR_CMD(0x0B,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x0F,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x41,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x42,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x48,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x49,0x01,0x3F);delay_Nms(5);
LCD_WR_CMD(0x4A,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x4B,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x44,0xEF,0x00);delay_Nms(5);
LCD_WR_CMD(0x45,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x46,0x01,0x3F);delay_Nms(5);
LCD_WR_CMD(0x30,0x07,0x07);delay_Nms(5);
LCD_WR_CMD(0x31,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x32,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x33,0x05,0x02);delay_Nms(5);
LCD_WR_CMD(0x34,0x05,0x07);delay_Nms(5);
LCD_WR_CMD(0x35,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x36,0x02,0x04);delay_Nms(5);
LCD_WR_CMD(0x37,0x05,0x02);delay_Nms(5);
LCD_WR_CMD(0x3A,0x03,0x02);delay_Nms(5);
LCD_WR_CMD(0x3B,0x03,0x02);delay_Nms(5);
LCD_WR_CMD(0x23,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x24,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x25,0x80,0x00);delay_Nms(5);
LCD_WR_CMD(0x4F,0x00,0x00);delay_Nms(5);
LCD_WR_CMD(0x4E,0x00,0x00);delay_Nms(5);
}
void DispOneColor(unsigned int Color)
{
unsigned int i,j;
LCD_SetCursor(0,0);
LCD_WR_ADDR(0x22);
Setbit(PORTB,1);//RS=1 PB1
PORTD=Color>>8;
PORTA=Color;
Clcbit(PORTB,0);//CS=0 PB0
for(j=0;j<320;j++)
{
for(i=0;i<240;i++)
{
Clcbit(PORTB,2);//WR=0 PB2
asm("nop");
Setbit(PORTB,2);//WR=1 PB2
}
}
Setbit(PORTB,0);//CS=1 PB0
}
void DrawLine(short x0,short y0,short x1,short y1,short color)
{
short k;
short dx;
short dy;
short dx2;
short dy2;
short e;
short x;
short y;
if(x1 {
k=x0;
x0=x1;
x1=k;
k=y0;
y0=y1;
y1=k;
}
dx=x1-x0;
dy=y1-y0;
dx2=dx<1;
dy2=dy<1;
e=-dx;
x=x0;
y=y0;
if(y1>=y0)
{
for(x=x0;x {
LCD_DrawPoint(x,y,color);
e=e+dy2;
if(e>0)
{
y++;
e=e-dx2;
}
}
}
else
{
e=dx;
for (x=x0;x {
LCD_DrawPoint(x, y,color);
e=e+dy2;
if (e<0)
{
y--;
e=e+dx2;
}
}
}
}
void main(void)
{
DDRA=0xff;
//DDRC=0xff;
DDRB=0xff;
DDRD=0xff;
//PORTD=0x00;
//PORTC=0x00;
Clcbit(PORTB,4);//RES=0
asm("nop");
Setbit(PORTB,4);//RES=1
LCD_Init();
DispOneColor(0x0000);
//LCD_DrawPoint(180,150,0x0000);////
DrawLine(180,150,60,200,0xFFFF);
while(1);
}
D0 | PA0 | D5 | PA5 | D10 | PD2 | D15 | PD7 |
D1 | PA1 | D6 | PA6 | D11 | PD3 | CS | PB0 |
D2 | PA2 | D7 | PA7 | D12 | PD4 | RS | PB1 |
D3 | PA3 | D8 | PD0 | D13 | PD5 | WR | PB2 |
D4 | PA4 | D9 | PD1 | D14 | PD6 | RD | PB3 |
RESET | PB4 |
#include LCD.h>
#include
#include
#define Setbit(val,bitn) (val|=(1<(bitn)))
#define Clcbit(val,bitn) (val&=~(1<(bitn)))
void delay_Nms(int n)
{
}
void LCD_WR_DATA(char VH,char VL)
{
}
void LCD_WR_ADDR(char addr)
{
}
void LCD_WR_CMD(char addr,char cmdH,char cmdL)
{
}
void LCD_SetCursor(short Xpos,short Ypos)
{
}
void LCD_DrawPoint(short Xpos,short Ypos,short POINT_COLOR)
{
}
void LCD_Init(void)
{
}
void DispOneColor(unsigned int Color)
{
}
void DrawLine(short x0,short y0,short x1,short y1,short color)
{
}
void main(void)
{
}
AVR3 2英寸tftLCDssd128 相关文章:
- 案例分析:基于AVR32的隧道环境监测系统(03-18)
- 科技帮我们远离灾难:灾难检测飞行器(03-18)
- DIY你的电子玩具:网络音乐电台,给你系统解决方案、软硬件设计实现(04-16)
- DIY智能家庭营养专家系统解决方案,我的健康我做主(04-19)
- 完整的家庭安全卫士系统方案,提供硬件框图、软件流程(06-03)
- 智能传感器节点能有多强大,这个方案告诉你(06-03)