You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PIC24EP512GU810驱动Hacktronix HDM16216L-7 LCD无显示技术求助

技术求助:PIC24EP512GU810驱动Hacktronix HDM16216L-7 LCD无显示

我正在使用PIC24EP512GU810单片机驱动Hacktronix HDM16216L-7型LCD显示数据。此前相同引脚配置曾成功显示字符,但目前LCD完全无显示。已尝试以下操作:

  • 调整延迟时间
  • 修改LCD初始化设置
  • 注释定时器代码以避免干扰LCD写入
  • 确认字符数组已正常传输、引脚电平设置正确
  • 验证LCD硬件本身无故障(可在其他板卡正常工作)

附上当前代码,寻求技术排查建议:

const unsigned int tm10ms = 2;
const unsigned int tm20ms = 4;
const unsigned int tm25ms = 5;
const unsigned int tm50ms = 10;
const unsigned int tm100ms = 20;
const unsigned int tm200ms = 40;
const unsigned int tm500ms = 100;
const unsigned int tm1000ms = 200;
const unsigned int tm2000ms = 400;
const unsigned int tm5000ms = 1000;
const unsigned int tm1min = 12000;
const unsigned int tm5min = 60000;
const unsigned long tm10min = 120000;
unsigned int count5ms = 1;
unsigned int count = 0;
unsigned int ii = 0;
void SetLCDData(unsigned char chardata);
void LcdInit();
void LcdCmd(unsigned char cmd);
void LcdWrite(unsigned char *cmd);
unsigned char charData;
int countvar = 0;

void InitTimer1(){        //10ms
     T1CON         = 0x8020;
     T1IE_bit         = 1;
     T1IF_bit         = 0;
     IPC0         = IPC0 | 0x1000;
     PR1         = 10937;
}

void Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT
{
  T1IF_bit     = 0;
  count5ms = 1;
}

void LcdInit()
{
    delay_ms(50);
    AN_AvgValues[idxSigBusFLT] = 0;       //corresponds to the R/W bit of the LCD
    LcdCmd(0x38);  //Set LCD Functionality
    LcdCmd(0x0e);  //LCD ON 1110      cursor on
    LcdCmd(0x01);  //clear the Display    0001
    LcdCmd(0x06);  //Entry Mode Set  0111  increment cursor no display shift
    LcdCmd(0x80);  //set the DD Ram address aka the location on the lcd which we will Display a character
}

void LcdCmd(unsigned char cmd)
{
     LCD_RS = 0;
     SetLCDData(cmd);
     delay_ms(1);
}

void LcdWrite(unsigned char *cmd)
{
     LCD_RS = 1;
     ii = 0;
     while (cmd[ii] != '~')
     {
        SetLCDData(cmd[ii]);
        delay_ms(100);
        LD_FAULT=~LD_FAULT;
        ii++;
     }
}

void SetLCDData(unsigned char charData)
{
      AN_AvgValues[idxSigBusFLT] = 0; //represents the R/W signal always 0
      LCD_D0 = charData.B0;
      LCD_D1 = charData.B1;
      LCD_D2 = charData.B2;
      LCD_D3 = charData.B3;
      LCD_D4 = charData.B4;
      LCD_D5 = charData.B5;
      LCD_D6 = charData.B6;
      LCD_D7 = charData.B7;
      LCD_EN = 1;
      delay_ms(1);
      LCD_EN = 0;
      delay_ms(50);
}


void main() {
     //PLL Config for 140MHz Fosc
     //Fosc = Fin*(M/(N1*N2)) --> 140MHz = 8*(70/4)
        PLLFBD = 68;             // PLL multiplier M=70
        CLKDIV = 0x0000;         // PLL prescaler N1=2, PLL postscaler N2=2
     
    //SET Analog bits and TRIS bits

    LcdInit();    // Initialize The LCD
    delay_ms(50);

    LcdWrite("test~");
    LcdCmd(0xc0);
    LcdWrite("BadApple~");
    //InitTimer1(); // Initialize Timer 1 for Period Interrupts
    while(1)
    {
       /*if (count5ms == 1)
       {
           count5ms = 0;
           count++;
           if (count%tm1000ms == 0)
           {
                LcdWrite("Bad Apple~");
           }
       } */
    }
}

排查建议

  • 确认引脚方向配置:代码中仅注释了SET Analog bits and TRIS bits但未实现,需确保LCD的RS、EN、D0-D7引脚的TRIS寄存器已设置为输出模式(PIC24引脚默认是输入,必须手动配置)。
  • 检查R/W引脚的硬件映射:代码中用AN_AvgValues[idxSigBusFLT] = 0表示拉低R/W,但需确认该变量对应的硬件引脚确实连接到LCD的R/W脚,且该引脚已配置为输出并保持低电平(当前代码未直接操作引脚,可能存在映射错误)。
  • 严格匹配初始化时序:参考LCD手册,上电后需等待至少15ms,再发送0x38,间隔4.1ms后再次发送0x38,再间隔100us发送第三次0x38,之后才能发送其他初始化指令。当前代码仅延迟50ms就直接发送0x38,可能时序不满足要求。
  • 调整EN信号脉冲宽度:SetLCDData中EN拉高后延迟1ms再拉低,可尝试缩短至10us左右(手册要求最小450ns),过长高电平可能导致识别错误;拉低后的50ms延迟可根据指令类型缩短(清屏指令需1.64ms,其他指令需40us)。
  • 验证PLL时钟配置:确认delay_ms函数基于正确的系统时钟计算延迟,若PLL配置错误,延迟时间会偏差,导致LCD时序混乱。
  • 逐指令波形调试:用电平测试仪或示波器观察初始化每一步的RS、EN、D0-D7波形,确认指令是否正确发送,比如先单独发送清屏指令,看LCD是否有反应。

内容的提问来源于stack exchange,提问作者Brendan Bates

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 04:02:32