|
本帖最后由 424778940 于 2013-7-9 14:07 编辑
如题,买了块ssd1289的液晶,从stm32 51都移植过驱动,但是毫无进展,上电无论干嘛都是给我一张大白脸看
我可以确定接线没有问题,都是杜邦线走的,全部用万用表量过,时序上有些代码不太一样,我都不清楚到底哪个是对的了
芯片用的avr mega128a 内部8m晶振,可以确定单片机肯定没问题
程序比较长,我用代码格式,求看看到底哪里有问题
- /*
- * lib_lcd_HY32C.h
- *
- * Created: 2013/7/5 13:31:27
- * Author: Adam
- */
- #ifndef LIB_LCD_HY32C_H_
- #define LIB_LCD_HY32C_H_
- #ifndef LIB_DELAY_H_
- # error "Not define LIB_DELAY_H_ ; LIB_LCD_HY32C_H_ can not work"
- #endif
- /* LCD color */
- #define White 0xFFFF
- #define Black 0x0000
- #define Grey 0xF7DE
- #define Blue 0x001F
- #define Blue2 0x051F
- #define Red 0xF800
- #define Magenta 0xF81F
- #define Green 0x07E0
- #define Cyan 0x7FFF
- #define Yellow 0xFFE0
- #define lib_lcd_hy32c_max_x 320
- #define lib_lcd_hy32c_max_y 240
- #define lib_lcd_hy32c_CONFIG_PORT PORTD
- #define lib_lcd_hy32c_CONFIG_DDR DDRD
- #define lib_lcd_hy32c_DB0_PORT PORTA
- #define lib_lcd_hy32c_DB0_DDR DDRA
- #define lib_lcd_hy32c_DB1_PORT PORTC
- #define lib_lcd_hy32c_DB1_DDR DDRC
- #define lib_lcd_hy32c_CS PD0
- #define lib_lcd_hy32c_WR PD1
- #define lib_lcd_hy32c_RESET PD2
- #define lib_lcd_hy32c_RS PD3
- #define lib_lcd_hy32c_RD PD4
- #define lib_lcd_hy32c_BLCNT PD5
- //相关引脚控制
- void lib_lcd_hy32c_bit_ctrl_CS(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_CS);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_CS);
- }
- }
- void lib_lcd_hy32c_bit_ctrl_RS(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_RS);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_RS);
- }
- }
- void lib_lcd_hy32c_bit_ctrl_RD(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_RD);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_RD);
- }
- }
- void lib_lcd_hy32c_bit_ctrl_WR(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_WR);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_WR);
- }
- }
- void lib_lcd_hy32c_bit_ctrl_RESET(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_RESET);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_RESET);
- }
- }
- void lib_lcd_hy32c_bit_ctrl_BLCNT(unsigned char bit)
- {
- if (bit == 0)
- {
- lib_lcd_hy32c_CONFIG_PORT &= ~(1<<lib_lcd_hy32c_BLCNT);
- }
-
- if (bit == 1)
- {
- lib_lcd_hy32c_CONFIG_PORT |= (1<<lib_lcd_hy32c_BLCNT);
- }
- }
- void lib_lcd_hy32c_write_reg(unsigned int reg)
- {
- lib_lcd_hy32c_bit_ctrl_CS(0);
- lib_lcd_hy32c_bit_ctrl_RS(0);
- //lib_lcd_hy32c_bit_ctrl_RD(1);
-
- lib_lcd_hy32c_DB0_PORT = (reg >> 8);
- lib_lcd_hy32c_DB1_PORT = reg;
-
- lib_lcd_hy32c_bit_ctrl_WR(0);
- lib_lcd_hy32c_bit_ctrl_WR(1);
- lib_lcd_hy32c_bit_ctrl_CS(1);
- }
- void lib_lcd_hy32c_write_data(unsigned int data)
- {
- lib_lcd_hy32c_bit_ctrl_CS(0);
- lib_lcd_hy32c_bit_ctrl_RS(1);
-
- lib_lcd_hy32c_DB0_PORT = (data >> 8);
- lib_lcd_hy32c_DB1_PORT = data;
-
- lib_lcd_hy32c_bit_ctrl_WR(0);
- lib_lcd_hy32c_bit_ctrl_WR(1);
- lib_lcd_hy32c_bit_ctrl_CS(1);
- }
- void lib_lcd_hy32c_write_reg_data(unsigned int reg,unsigned int data)
- {
- lib_lcd_hy32c_write_reg(reg);
- lib_lcd_hy32c_write_data(data);
- delay_reduce(1000);
- }
- void lib_lcd_hy32c_set_cursor(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2)
- {
- lib_lcd_hy32c_write_reg_data(0x0044,(x2<<8)+x1);
- lib_lcd_hy32c_write_reg_data(0x0045,y1);
- lib_lcd_hy32c_write_reg_data(0x0046,y2);
- lib_lcd_hy32c_write_reg_data(0x004e,x1);
- lib_lcd_hy32c_write_reg_data(0x004f,y1);
- lib_lcd_hy32c_write_reg(0x0022);
- }
- void lib_lcd_hy32c_clear()
- {
- //lib_lcd_hy32c_set_cursor(0,0);
- lib_lcd_hy32c_write_reg(0x0022);
-
- lib_lcd_hy32c_bit_ctrl_RS(1);
- lib_lcd_hy32c_bit_ctrl_CS(0);
-
- for(unsigned int i = 0;i < lib_lcd_hy32c_max_y;i++)
- {
- for(unsigned int j = 0;j < lib_lcd_hy32c_max_x;j++)
- {
- lib_lcd_hy32c_bit_ctrl_WR(0);
- lib_lcd_hy32c_bit_ctrl_WR(1);
- }
- }
-
- lib_lcd_hy32c_bit_ctrl_CS(1);
- }
- void lib_lcd_hy32c_init()
- {
- //config db ddr
- lib_lcd_hy32c_DB0_DDR = 0xff;
- lib_lcd_hy32c_DB1_DDR = 0xff;
-
- //config db port
- lib_lcd_hy32c_DB0_PORT = 0x00;
- lib_lcd_hy32c_DB1_PORT = 0x00;
-
- //config config ddr and port
- lib_lcd_hy32c_CONFIG_DDR = 0xff;
- lib_lcd_hy32c_CONFIG_DDR |= ((1<<lib_lcd_hy32c_CS) | (1<<lib_lcd_hy32c_RS) | (1<<lib_lcd_hy32c_BLCNT));
- lib_lcd_hy32c_CONFIG_DDR &= ~((1<<lib_lcd_hy32c_WR) | (1<<lib_lcd_hy32c_RESET) | (1<<lib_lcd_hy32c_RD));
- lib_lcd_hy32c_CONFIG_PORT = 0x00;
-
- //backlight open
- lib_lcd_hy32c_bit_ctrl_BLCNT(1);
-
- lib_lcd_hy32c_bit_ctrl_CS(1);
- lib_lcd_hy32c_bit_ctrl_RD(1);
- lib_lcd_hy32c_bit_ctrl_WR(1);
- delay_reduce(5500);
- lib_lcd_hy32c_bit_ctrl_RESET(0);
- delay_reduce(1500);
- lib_lcd_hy32c_bit_ctrl_RESET(1);
- lib_lcd_hy32c_write_reg_data(0x0000,0x0001); //打开晶振
- lib_lcd_hy32c_write_reg_data(0x0003,0x08A4); //电源控制1 ;0xA8A4
- lib_lcd_hy32c_write_reg_data(0x000C,0x0000); //电源控制2 ;0xA8A4
- lib_lcd_hy32c_write_reg_data(0x000D,0x080C); //电源控制3 ;0xA8A4
- lib_lcd_hy32c_write_reg_data(0x000E,0x2B00); //电源控制4 ;0xA8A4
- lib_lcd_hy32c_write_reg_data(0x001E,0x00B0); //电源控制5 ;0xA8A4
- lib_lcd_hy32c_write_reg_data(0x0001,0x233F); //驱动输出控制320*240 0x6B3F RGB
- lib_lcd_hy32c_write_reg_data(0x0002,0x0600); //液晶驱动邋AC控制
- lib_lcd_hy32c_write_reg_data(0x0010,0x0000); //睡眠控制
- lib_lcd_hy32c_write_reg_data(0x0011,0x6070); //0x4030 //定义数据格式 16位色
- lib_lcd_hy32c_write_reg_data(0x0005,0x0000); //共享寄存器1
- lib_lcd_hy32c_write_reg_data(0x0006,0x0000); //共享寄存器2
- lib_lcd_hy32c_write_reg_data(0x0016,0xEF1C); //水平玄关
- lib_lcd_hy32c_write_reg_data(0x0017,0x0003); //垂直玄关
- lib_lcd_hy32c_write_reg_data(0x0007,0x0233); //显示控制 0x0233
- lib_lcd_hy32c_write_reg_data(0x000B,0x0000); //帧周期控制
- lib_lcd_hy32c_write_reg_data(0x000F,0x0000); //扫描开始地址
- lib_lcd_hy32c_write_reg_data(0x0041,0x0000); //垂直卷轴控制 1
- lib_lcd_hy32c_write_reg_data(0x0042,0x0000); //垂直卷轴控制 2
- lib_lcd_hy32c_write_reg_data(0x0048,0x0000); //第一个窗口开始
- lib_lcd_hy32c_write_reg_data(0x0049,0x013F); //第一个窗口结束
- lib_lcd_hy32c_write_reg_data(0x004A,0x0000); //第二个窗口开始
- lib_lcd_hy32c_write_reg_data(0x004B,0x0000); //第二个窗口结束
- lib_lcd_hy32c_write_reg_data(0x0044,0xEF00); //水平RAM地址
- lib_lcd_hy32c_write_reg_data(0x0045,0x0000); //垂直RAM起始地址
- lib_lcd_hy32c_write_reg_data(0x0046,0x013F); //垂直RAM结束地址
- lib_lcd_hy32c_write_reg_data(0x0030,0x0707); //伽马控制1
- lib_lcd_hy32c_write_reg_data(0x0031,0x0204); //伽马控制2
- lib_lcd_hy32c_write_reg_data(0x0032,0x0204); //伽马控制3
- lib_lcd_hy32c_write_reg_data(0x0033,0x0502); //伽马控制4
- lib_lcd_hy32c_write_reg_data(0x0034,0x0507); //伽马控制5
- lib_lcd_hy32c_write_reg_data(0x0035,0x0204); //伽马控制6
- lib_lcd_hy32c_write_reg_data(0x0036,0x0204); //伽马控制7
- lib_lcd_hy32c_write_reg_data(0x0037,0x0502); //伽马控制8
- lib_lcd_hy32c_write_reg_data(0x003A,0x0302); //伽马控制9
- lib_lcd_hy32c_write_reg_data(0x003B,0x0302); //伽马控制10
- lib_lcd_hy32c_write_reg_data(0x0023,0x0000); //RAM write data mask (1)
- lib_lcd_hy32c_write_reg_data(0x0024,0x0000); //RAM write data mask (2)
- lib_lcd_hy32c_write_reg_data(0x0025,0x8000);
- lib_lcd_hy32c_write_reg_data(0x004f,0); //行首址0
- lib_lcd_hy32c_write_reg_data(0x004e,0); //列首址0
- lib_lcd_hy32c_write_reg(0x0022);
- }
- void paint(unsigned int color)
- {
- unsigned char x;
- unsigned int y;
-
- for(y=320;y>0;y--)
- {
- for (x=240;x>0;x--)
- {
- lib_lcd_hy32c_write_data(color);
- }
- }
- }
- void lib_lcd_hy32c_display_test()
- {
- lib_lcd_hy32c_init();
- lib_lcd_hy32c_set_cursor(0,0,239,319);
- paint(0xf800);
- paint(0x07e0);
- paint(0x001f);
- }
- #endif /* LIB_LCD_HY32C_H_ */
复制代码 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|