搜索
bottom↓
回复: 2

stm32&SSD1298,求大神们帮我看一下,什么地方不对的……

[复制链接]

出0入0汤圆

发表于 2012-5-13 18:21:58 | 显示全部楼层 |阅读模式
RT,显示器上不能显示任何东西啊!是什么地方错掉了?

#include "stm32f10x.h"

#define CS_0                    GPIO_ResetBits ( GPIOC, GPIO_Pin_6 );
#define CS_1           GPIO_SetBits ( GPIOC, GPIO_Pin_6 );

#define red                  0xf800
#define blue                 0x001f
#define green                0x7e00
#define yellow               0xffe0
#define purple               0xf81f
#define white                0xffff
#define black                0x0000
#define cyan                 0x07ff
#define grey                 0x7bef

void delay ( u32 count )
{
        for ( ; count > 0; count -- );
}
uint8_t CLK_Init ( void )
{
        ErrorStatus HSEStartUpStatus;                                                                           //不知道干嘛的
        RCC_DeInit ();                                                                                                           //将RCC恢复为默认值
        RCC_HSEConfig ( RCC_HSE_ON );                                                                           //打开外部高速晶体振荡器
        HSEStartUpStatus = RCC_WaitForHSEStartUp ();                                           //等待外部高速晶振振荡器的起振
        if ( HSEStartUpStatus == SUCCESS )                                                                   //判断外部高速晶体振荡器是否起振
        {                                                                                                                                  
                delay ( 0xff );                                                                                                   //稍微延时一会
                RCC_HCLKConfig ( RCC_SYSCLK_Div1 );                                                           //设置AHB时钟为系统时钟频率      72MHz
                RCC_PCLK2Config ( RCC_HCLK_Div1 );                                                           //设置APB2的时钟,等于AHB时钟    72MHz
                RCC_PCLK1Config ( RCC_HCLK_Div2 );                                                           //设置APB1的时钟,等于AHB的一半  36MHz
                RCC_PLLConfig ( RCC_PLLSource_HSE_Div1, RCC_PLLMul_9 );                   //设置系统时钟PLL时钟的频率:8*9= 72MHz
                RCC_PLLCmd ( ENABLE );                                                                                   //使能PLL时钟
                while ( RCC_GetFlagStatus ( RCC_FLAG_PLLRDY ) == RESET );      //等待PLL时钟初始化成功
                RCC_SYSCLKConfig ( RCC_SYSCLKSource_PLLCLK );                                   //将系统时钟设置为PLL时钟源
                while ( RCC_GetSYSCLKSource () != 0x08 );                                           //等待PLL时钟成功的成为系统时钟源
                return 0;                                                                                                           //跳出循环,进行下面的步骤
        }       
        else
        {
                RCC_DeInit ();                                                 //不行的话,就重新初始化
                return 1;                                                                                                           //继续循环
        }
}
void Pin_Init ( void )
{
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;                                                        //PE口为数据口
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init ( GPIOE, &GPIO_InitStructure );

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init ( GPIOC, &GPIO_InitStructure );

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init ( GPIOD, &GPIO_InitStructure );
}
void LCD_Write_Com ( u16 com )
{
        GPIO_ResetBits ( GPIOD, GPIO_Pin_13 );          // RS= 0,表示地址
        GPIO_Write ( GPIOE, com );                           //GPIOE,作为数据口,16位并行模式
        GPIO_ResetBits ( GPIOD, GPIO_Pin_14 );         //WR = 0
        GPIO_SetBits ( GPIOD, GPIO_Pin_14 );            //WR = 1
}
void LCD_Write_Data ( u16 dat )
{
        GPIO_SetBits ( GPIOD, GPIO_Pin_13 );          // RS= 1,表示数据
        GPIO_Write ( GPIOE, dat );
        GPIO_ResetBits ( GPIOD, GPIO_Pin_14 );         //WR = 0
        GPIO_SetBits ( GPIOD, GPIO_Pin_14 );            //WR = 1
}
void LCD_Init ( void )
{
        //delay ( 0xffff );
        CS_0;                //打开片选使能
    LCD_Write_Com ( 0x0000 ); LCD_Write_Data ( 0x0001 );
        LCD_Write_Com ( 0x0001 ); LCD_Write_Data ( 0x333f );
        LCD_Write_Com ( 0x0002 ); LCD_Write_Data ( 0x0600 );

        LCD_Write_Com ( 0x000c ); LCD_Write_Data ( 0x0007 );
        LCD_Write_Com ( 0x000d ); LCD_Write_Data ( 0x0006 );
        LCD_Write_Com ( 0x000e ); LCD_Write_Data ( 0x3200 );
        LCD_Write_Com ( 0x001e ); LCD_Write_Data ( 0x00bb );
        LCD_Write_Com ( 0x0003 ); LCD_Write_Data ( 0x6a64 );

        LCD_Write_Com ( 0x0010 ); LCD_Write_Data ( 0x0000 );

        LCD_Write_Com ( 0x0011 ); LCD_Write_Data ( 0x4870 );
        LCD_Write_Com ( 0x0007 ); LCD_Write_Data ( 0x0033 );

        LCD_Write_Com ( 0x0025 ); LCD_Write_Data ( 0xe000 );
        LCD_Write_Com ( 0x000b ); LCD_Write_Data ( 0x5308 );

        LCD_Write_Com ( 0x000f ); LCD_Write_Data ( 0x0000 );
        LCD_Write_Com ( 0x0044 ); LCD_Write_Data ( 0xef00 );
        LCD_Write_Com ( 0x0045 ); LCD_Write_Data ( 0x0000 );
        LCD_Write_Com ( 0x0046 ); LCD_Write_Data ( 0x013f );
        LCD_Write_Com ( 0x004e ); LCD_Write_Data ( 0x0000 );
        LCD_Write_Com ( 0x004f ); LCD_Write_Data ( 0x0000 );

        LCD_Write_Com ( 0x0030 ); LCD_Write_Data ( 0x0000 );
        LCD_Write_Com ( 0x0031 ); LCD_Write_Data ( 0x0706 );
        LCD_Write_Com ( 0x0032 ); LCD_Write_Data ( 0x0206 );
        LCD_Write_Com ( 0x0033 ); LCD_Write_Data ( 0x0300 );
        LCD_Write_Com ( 0x0034 ); LCD_Write_Data ( 0x0002 );   
        LCD_Write_Com ( 0x0035 ); LCD_Write_Data ( 0x0000 );
        LCD_Write_Com ( 0x0036 ); LCD_Write_Data ( 0x0707 );
        LCD_Write_Com ( 0x0037 ); LCD_Write_Data ( 0x0200 );
        LCD_Write_Com ( 0x003a ); LCD_Write_Data ( 0x0908 );
        LCD_Write_Com ( 0x003b ); LCD_Write_Data ( 0x0f0d );

        LCD_Write_Com ( 0x0028 ); LCD_Write_Data ( 0x0006 );
        LCD_Write_Com ( 0x002f ); LCD_Write_Data ( 0x12eb );
        LCD_Write_Com ( 0x0026 ); LCD_Write_Data ( 0x7000 );
        LCD_Write_Com ( 0x0020 ); LCD_Write_Data ( 0xb0e3 );
        LCD_Write_Com ( 0x0027 ); LCD_Write_Data ( 0x0044 );
        LCD_Write_Com ( 0x002e ); LCD_Write_Data ( 0x7e45 );
    CS_1;                //关闭片选使能
}
void Address_set( u8 x1, u16 y1, u8 x2, u16 y2)
{
                u16 x = ( x2 << 8 ) | x1;
        LCD_Write_Com(0x004e); LCD_Write_Data (x1);                //设置X坐标位置
        LCD_Write_Com(0x004f); LCD_Write_Data (y1);                //设置Y坐标位置
        LCD_Write_Com(0x0044); LCD_Write_Data (x);                //开始X与结束x
        LCD_Write_Com(0x0045); LCD_Write_Data (y1);                //开始Y
        LCD_Write_Com(0x0046); LCD_Write_Data (y2);                //结束Y
        LCD_Write_Com(0x0022);
}
void Pant ( void )
{
        int i, j;
        CS_0;                //打开片选使能
        Address_set(0,0,239,319);
        for(i = 0; i < 320; i++)
        {
                for (j = 0; j < 240; j++)
                {
                        LCD_Write_Data ( 0xfe00 );   //红色
                }
        }
        CS_1;                //关闭片选使能
}
int main ( void )
{
        while ( CLK_Init () );
        RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE );
        Pin_Init ();
        LCD_Init ();
        Pant ();
        while (1);
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2019-4-17 22:42:28 | 显示全部楼层
以下希望可以帮到你:
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的!!!
//在其他型号的驱动芯片上没有测试!
void LCD_Init(void)
{
        RCC->APB2ENR|=1<<5;//先使能外设PORTD时钟
        RCC->APB2ENR|=1<<6;//先使能外设PORTE时钟

        //RCC->APB2ENR|=1<<0;    //开启辅助时钟
                                                                                         
        GPIOD->CRH&=0X0000FFFF;//CRH高16位清零  PD12-PD15都输出1
        GPIOD->CRH|=0X33330000; //CRH高16或上3333
                               //通用推挽输出最高速度50MHz
        GPIOD->ODR=0XF000;        //PD12-PD15都输出1
               
        GPIOE->CRH=0X33333333;//PE8-PE15通用推挽输出最高速度50MHz
        GPIOE->CRL=0X33333333; //PE0-PE7 通用推挽输出最高速度50MHz
        GPIOE->ODR=0XFFFF; //PE0-PE15全都输出1 //全部输出高

        delay_ms(50); // delay 50 ms
        LCD_WriteReg(0x0000,0x0001); //写寄存器
        delay_ms(50); // delay 50 ms
       
        DeviceCode = LCD_ReadReg(0x0000); //读取驱动IC的ID号码   
        if (DeviceCode == 0x8999)
        {
                 // SSD1298    芯片ID为 0x8999 //
                // power supply setting
                // set R07h at 0021h (GON=1,DTE=0,D[1:0]=01)
                LCD_WriteReg(0x07,0x0021);
                // set R00h at 0001h (OSCEN=1)
                LCD_WriteReg(0x00,0x0001);
                // set R07h at 0023h (GON=1,DTE=0,D[1:0]=11)
                LCD_WriteReg(0x07,0x0023);
                // set R10h at 0000h (Exit sleep mode)
                LCD_WriteReg(0x10,0x0000);
                // Wait 30ms
                delay_ms(3000);
                // set R07h at 0033h (GON=1,DTE=1,D[1:0]=11)
                LCD_WriteReg(0x07,0x0033);
                // Entry mode setting (R11h)
                // R11H Entry mode
                // vsmode DFM1 DFM0 TRANS OEDef WMode DMode1 DMode0 TY1 TY0 ID1 ID0 AM LG2 LG2 LG0
                //   0     1    1     0     0     0     0      0     0   1   1   1  *   0   0   0
                LCD_WriteReg(0x11,0x6070);
                // LCD driver AC setting (R02h)
                LCD_WriteReg(0x02,0x0600);
                // power control 1
                // DCT3 DCT2 DCT1 DCT0 BT2 BT1 BT0 0 DC3 DC2 DC1 DC0 AP2 AP1 AP0 0
                // 1     0    1    0    1   0   0  0  1   0   1   0   0   1   0  0
                // DCT[3:0] fosc/4 BT[2:0]  DC{3:0] fosc/4
                LCD_WriteReg(0x03,0x0804);//0xA8A4
                LCD_WriteReg(0x0C,0x0000);//
                LCD_WriteReg(0x0D,0x080C);//
                // power control 4
                // 0 0 VCOMG VDV4 VDV3 VDV2 VDV1 VDV0 0 0 0 0 0 0 0 0
                // 0 0   1    0    1    0    1    1   0 0 0 0 0 0 0 0
                LCD_WriteReg(0x0E,0x2900);
                LCD_WriteReg(0x1E,0x00B8);
               
//        LCD_WriteReg(0x01,0x2B3F);//驱动输出控制320*240  0x6B3F
//        LCD_WriteReg(0x0001,0x6B3F);   // delayms(5);  
          LCD_WriteReg(0x0001,0x3B3F);   // delayms(5);  
               
                LCD_WriteReg(0x10,0x0000);
               
    LCD_WriteReg(0x0011,0x6070);//定义数据格式 16位色 横屏 0x6058////竖屏0x6070
               
                LCD_WriteReg(0x05,0x0000);
                LCD_WriteReg(0x06,0x0000);
                LCD_WriteReg(0x16,0xEF1C);
                LCD_WriteReg(0x17,0x0003);
                LCD_WriteReg(0x07,0x0233);//0x0233
                LCD_WriteReg(0x0B,0x0000|(3<<6));
                                               
                LCD_WriteReg(0x0F,0x0000);//扫描开始地址
                LCD_WriteReg(0x41,0x0000);
                LCD_WriteReg(0x42,0x0000);
                LCD_WriteReg(0x48,0x0000);
                LCD_WriteReg(0x49,0x013F);
                LCD_WriteReg(0x4A,0x0000);
                LCD_WriteReg(0x4B,0x0000);
                LCD_WriteReg(0x44,0xEF00);
                LCD_WriteReg(0x45,0x0000);
                LCD_WriteReg(0x46,0x013F);
                LCD_WriteReg(0x30,0x0707);
                LCD_WriteReg(0x31,0x0204);
                LCD_WriteReg(0x32,0x0204);
                LCD_WriteReg(0x33,0x0502);
                LCD_WriteReg(0x34,0x0507);
                LCD_WriteReg(0x35,0x0204);
                LCD_WriteReg(0x36,0x0204);
                LCD_WriteReg(0x37,0x0502);
                LCD_WriteReg(0x3A,0x0302);
                LCD_WriteReg(0x3B,0x0302);
                LCD_WriteReg(0x23,0x0000);
                LCD_WriteReg(0x24,0x0000);
                LCD_WriteReg(0x25,0x8000);   // 65hz
                LCD_WriteReg(0x4f,0);        // 行首址0
                LCD_WriteReg(0x4e,0);        // 列首址0       

        }       

}
               

出0入0汤圆

 楼主| 发表于 2019-4-18 10:59:20 | 显示全部楼层
hsbkyh 发表于 2019-4-17 22:42
以下希望可以帮到你:
//初始化lcd
//该初始化函数可以初始化各种ILI93XX液晶,但是其他函数是基于ILI9320的 ...

虽然很感激。但这也是7年前的帖子了。。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-3-29 06:38

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表