|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
哪位大虾帮帮我啊,我的1.6寸TFT液晶屏只显示几条彩色条纹,代码是厂家给的,我看了和网上挂的差不多,现在我不知道是代码问题还是屏的问题啊!
//#include <reg51.H>
#include <p18f6722.h>
#include <spi.h>
#include "ConfiguretionBit.h"
#include "ssd1283a.H"
#include "picture.H"
#include "ssd1283aFUNCTION.H"
#define PS LATBbits.LATB3
#define lcd_rst LATEbits.LATE3 //LATBbits.LATB1
unsigned char wo[32]=
{
0x04,0x80,0x0E,0xA0,0x78,0x90,0x08,0x90,0x08,0x84,0xFF,0xFE,0x08,0x80,0x08,0x90,
0x0A,0x90,0x0C,0x60,0x18,0x40,0x68,0xA0,0x09,0x20,0x0A,0x14,0x28,0x14,0x10,0x0C
};
rom unsigned char hello[]={"Hello world!\r\n"};
rom unsigned char men[]={"Hello,World!菜单"};
rom unsigned char num[]={"0123456789"};
rom unsigned char cha[]={"^_^ *_* @_@"};
rom unsigned char cha1[]={"[]{}:;',<>"};
rom unsigned char cha2[]={"^_^"};
rom unsigned char cha3[]={"`~!@#$%^&*()_+-="};
rom unsigned char cha4[]={"1.6'TFT Driver,This is a demo!"};
/*
void Delay(unsigned int MS)
{
unsigned char us,usn;
while(MS!=0) //for 12M
{
usn = 2;
while(usn!=0)
{
us = 0xf5;
while (us!=0)
{
us--;
};
usn--;
}
MS--;
}
}
*/
void Init(void)
{
OSCTUNEbits.PLLEN= 0;
//OSCTUNE= 0x48;
OSCCON = 0x7f;
//OSCCON = 0x77;
PORTA = 0x00;
LATA = 0x00;
ADCON0 = 0x00; // ad turn is off
ADCON1 = 0x00;
//CMCON = 0x0f; //cmp is off
TRISA = 0x00; //porat a is I/O OUTPUT except RA6
PORTB = 0x00;
LATB = 0x00;
//ADCON1 = 0x00;
TRISB = 0x00; // portB is out put
PORTC = 0x00;
LATC = 0x00;
TRISC = 0x80; //RC7, AS INPUT,
PORTD = 0x00;
LATD = 0x00;
TRISD = 0x1f; //portd is output
PORTE = 0x00;
LATE = 0x00;
TRISE = 0x00; //RE3,IS INPUT
PORTF = 0x00;
LATF = 0x00;
ADCON1 = 0x0f;
CMCON = 0x0f;
TRISF = 0x00;
PORTG = 0x00;
LATG = 0x00;
TRISG = 0xe4;
PORTA = 0xff;
PORTB = 0xff;
PORTC = 0xff;
PORTD = 0xff;
PORTE = 0xff;
PORTF = 0xff;
PORTG = 0xff;
Delay(10);
CloseSPI();
//OpenSPI1(SPI_FOSC_64,MODE_00,SMPMID);
//OpenI2C1(MASTER,SLEW_OFF);//MASRTER,100KHZ
//SSP1ADD=0x63;//40Mhz,100Khz
//SSP1ADD=0x13;
//=================================I2C 2=====================
//OpenI2C2(MASTER,SLEW_OFF);//MASRTER,100KHZ
//SSP1ADD=0x63;//40Mhz,100Khz
//SSP2ADD=0x13;
PIE1bits.SSP1IE =0;
PIE2bits.BCL1IE =0;
PIE3bits.SSP2IE =0;
PIE3bits.BCL2IE =0;
}
void Usart_Init(void)
{
//OSCTUNEbits.PLLEN=0;
TRISCbits.TRISC7=1;
TRISCbits.TRISC6=0;
TXSTA1=0x00;
RCSTA1=0x00;
//SPBRG=0x33; //baud rate is 9600
BAUDCON1bits.BRG16=0;
TXSTA1bits.BRGH=1; //high speed
TXSTA1bits.SYNC=0;
TXSTA1bits.TX9=0;
RCSTA1bits.CREN=0;
TXSTA1bits.TXEN=1;
RCSTA1bits.SPEN=1;
SPBRG1=0x0c; //baud rate is 38400
PIR1bits.TX1IF=0;
PIR1bits.RC1IF=0;
PIE1bits.RC1IE=0;
PIE1bits.TX1IE=0;
RCONbits.IPEN=0;
INTCONbits.GIE=0;
INTCONbits.PEIE=0;
}
void Usart1_printf(rom unsigned char *str)
{
unsigned char data;
data=*str;
while((*str)!='\0')
{
data=*str;
while(TXSTA1bits.TRMT==0); //等待发送移位寄存器为空
TXREG1=data; //装入数据
//TXREG2=data;
str++;
}
}
void DispBMP(unsigned char disX,unsigned char disY,rom unsigned char *puts) //disX disY图像显示起点坐标
{
unsigned int x=8;
unsigned char i,j,w,h;
w=puts[3];
h=puts[5];
Write_WDR(0x44,( 0x02+disX + ((unsigned int)((disX+1+w) << 8))));
Write_WDR(0x45,( 0x02+disY + ((unsigned int)((disY+1+h) << 8))));
Write_WDR(0x21,( 0x02+disX + ((unsigned int)((disY+2) << 8))));
Write_IR(0x22);
for(i=0;i<w;i++)
{
for(j=0;j<h;j++)
{
Write_Byte(puts[x]);
x++;
Write_Byte(puts[x]);
x++;
}
}
}
//Image2Lcd图像头数据结构
//typedef struct _HEADCOLOR
//{
// unsigned char scan;
// unsigned char gray;
// unsigned short w;
// unsigned short h;
// unsigned char is565;
// unsigned char rgb;
//}HEADCOLOR;
//w:
//图像的宽度。
//h:
//图像的高度。
void LCD_Init(void)
{
int i;
Write_WDR(0x10,0x2f8e);
Write_WDR(0x11,0x000c);
Write_WDR(0x07,0x0021);
Write_WDR(0x28,0x0006);
Write_WDR(0x28,0x0005);
Write_WDR(0x27,0x057f);
Write_WDR(0x29,0x89a1);
Write_WDR(0x00,0x0001);
Delay(100);
Write_WDR(0x29,0x80b0);
Delay(30);
Write_WDR(0x29,0xfffe);
Write_WDR(0x07,0x0023);
Delay(30);
Write_WDR(0x07,0x0033);
Write_WDR(0x01,0x2183);
Write_WDR(0x2f,0xffff);
Write_WDR(0x2c,0x8000);
Write_WDR(0x03,0x6830);
Write_WDR(0x27,0x0570);
Write_WDR(0x02,0x0300);
Write_WDR(0x0b,0x580c);
Write_WDR(0x12,0x0609);
Write_WDR(0x13,0x3100);
Write_WDR(0x2a,0x1dd0);
Write_WDR(0x2b,0x0a90);
Write_WDR(0x2d,0x310f);
Delay(100);
/*Write_WDR(0x45,0x8300);
Write_WDR(0x44,0x8300);
Write_WDR(0x21,0x0000);*/
Write_WDR(0x1e,0x00bf);
Delay(1);
Write_WDR(0x1e,0x0000);
Delay(100);
Write_WDR(0x45,0x8300);
Write_WDR(0x44,0x8300);
Write_WDR(0x21,0x0000);
Write_IR(0x22);
for (i=0;i<17424;i++)
{Write_Byte(0xff);
Write_Byte(0xff);}
}
void LCD_Reset(void)
{
lcd_rst=1;
Delay(10);
lcd_rst=0;
Delay(10);
lcd_rst=1;
Delay(10);
}
/*
void main(void)
{
unsigned int i;
Reset();
lcd_rd=1;
lcd_cs=0;
LCD_Init();
Write_WDR(0x21,0x0000);
Write_IR(0x44);
Write_Word(0x8300);
Write_IR(0x45);
Write_Word(0x8300);
Write_IR(0x22);
for (i=0;i<17424;i++)
Write_Word(0xbe5f);
Write_WDR(0x21,0x1010);
Write_IR(0x44);
Write_Byte(95+16);
Write_Byte(16);
// Write_Word(95+4+16,4+16);
Write_IR(0x45);
Write_Byte(96+16);
Write_Byte(16);
// Write_Word(96+16,16);
Write_IR(0x22);
for (i=0;i<18624;i++)
Write_Byte(AVR_LOGO);
// Delay(100);
while(1);
}*/
void main(void)
{
unsigned int i = 0,k = 0;
// unsigned char disp[16][16];
Init();
Usart_Init();
//lcd_led=1;
Usart1_printf(hello);
LCD_Reset();
LCD_Init();
PS=0;
Write_WDR(0x44,0x8300);
Write_WDR(0x45,0x8300);
Write_WDR(0x21,0x0000);
Write_IR(0x22);
// for (i=0;i<32768;i++)
// write_data16(0xbe5f);
// LCD_WR_REG(0x21,0x1014);
// write_cmd(0x44);
//write_data16(95+4+16,4+16);
//write_cmd(0x45);
//write_data16(96+16,16);
//write_cmd(0x22);
/*
for (i=0;i<16900;i++)
Write_Word(0xBE5F);*/
while(1)
{
Delay(1000);
//LCD_Display(0,0,men,RGB(0,63,0),RGB(0,0,31));
LCD_Display(0,0,men,0xFFFF,0x2000);
Usart1_printf(men);
// LCD_Display(16,16,num,RGB(31,0,31),RGB(31,63,0));
LCD_Display(16,16,num,0xFFFF,0x2000);
Usart1_printf(num);
//LCD_Display(0,32,cha,RGB(0,63,31),RGB(31,63,31));
LCD_Display(0,32,cha,0xFFFF,0x2000);
Usart1_printf(cha);
//LCD_Display(0,48,cha1,RGB(0,63,31),RGB(31,63,0));
LCD_Display(0,48,cha1,0xFFFF,0x2000);
Usart1_printf(cha1);
LCD_Display(32,64,cha2,0xFFFF,0x2000);
Usart1_printf(cha2);
//LCD_Display(0,80,cha3,0x0F0F,0xBE5F);
LCD_Display(0,80,cha3,0xFFFF,0x2000);
Usart1_printf(cha3);
//LCD_Display(0,96,cha4,RGB(31,0,0),RGB(0,63,0));
LCD_Display(0,96,cha4,0xFFFF,0x2000);
Usart1_printf(cha4);
//LCD_Display(0,112,"This is a demo!",0x0FF0,0xBE5F,0);
// LCD_HZ_Disp(96,32,GetHzIndex('菜'),RGB(0,63,0),RGB(31,31,31),0);
// LCD_HZ_Disp(96+16,32,GetHzIndex('单'),RGB(0,63,0),RGB(31,31,31),0);
//BKLIGHT_ON();
//Line(0,0,127,127,RGB(31,0,0),3);
//Line(127,0,0,127,RGB(0,0,31),3);
//Rectangle(0,10,50,50,RGB(0,63,21),5);
//Bar(1,38,120,120,RGB(31,0,0),3);
//Bar(10,60,100,120,RGB(31,0,0),1);
Delay(1000);
DispBMP(0,0,AVR_LOGO);
Delay(1000);
DispBMP(32,32,wo);
}
} |
|