AVR驱动3.2英寸tft LCD(ssd1289)
2016-04-25 来源:eefocus
管脚连接
#include
#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
#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)
{
}
下一篇:AVR的中断问题
相关文章
- 基于 Microchip AVR DA MCU 的带加热 HoD 离手检测+触摸多功能方向盘方案
- Microchip推出AVR® DU系列USB单片机,支持增强型代码保护和高达15W 的 功率输出
- 贸泽电子开售面向工业和汽车应用的Microchip Technology AVR64EA 8位AVR MCU
- 天龙DENON AVR-1507功放机内部拆解
- AVR32 MCU上的ABDAC外设音频播放设计
- AVR基础知识:ATMEGA的SPI总线 - 第1部分
- AVR基础知识:ATMEGA的SPI总线 - 第2部分
- 使用AVR微控制器控制GSM模块实现发送和接收短信
- 如何使用USBASP烧写器和Atmel Studio 7.0对AVR微控制器进行编程
- 使用AVR微控制器Atmega16连接伺服电机的方法