找回密码
 立即注册
查看: 536|回复: 1

LCD1602动态双行显示(C语言)

[复制链接]
  • 打卡等级:偶尔看看III
  • 打卡总天数:56
  • 最近打卡:2025-04-15 09:09:55

12

主题

28

回帖

246

积分

中级会员

积分
246
发表于 2023-11-11 09:02:23 来自手机 | 显示全部楼层 |阅读模式
IMG_6746.jpeg
主控芯片:STC32G12K128
设备型号:LCD1602
主控芯片及实验箱购买链接:
KCER001.taobao.com
强烈推荐P3的仿真器
////////////////
#include "stc32g.h"
#define uint unsigned int
#define uchar unsigned char

sbit rs=P0^0;
sbit rw=P0^1;
sbit e=P0^2;

uchar num;
uint i;

uchar code tab1[]="www.stcaimcu.com";
uchar code tab2[]="KCER001.taobao.";

void csh_io(){
    P0M1 = 0x00;   P0M0 = 0x00;   //设置为准双向口
    P1M1 = 0x00;   P1M0 = 0x00;   //设置为准双向口
    P2M1 = 0x00;   P2M0 = 0x00;   //设置为准双向口
    P3M1 = 0x00;   P3M0 = 0x00;   //设置为准双向口
    P4M1 = 0x00;   P4M0 = 0x00;   //设置为准双向口
    P5M1 = 0x00;   P5M0 = 0x00;   //设置为准双向口
    P6M1 = 0x00;   P6M0 = 0x00;   //设置为准双向口
    P7M1 = 0x00;   P7M0 = 0x00;   //设置为准双向口   
}

void delay(uint ms){
   
    for(ms=ms;ms>0;ms--)
    for(i=150;i>0;i--);
}

void delayus(uint us){
    while(us--);
}

void wat_data(uchar dat){

    rs=1;
    rw=0;
    e=0;
    P2=dat;
    e=1;
    delay(5);
    e=0;
    delayus(50);
}

void wat_ml(uchar tad){
    rs=0;
    rw=0;
    e=0;
    P2=tad;
    e=1;
    delay(5);
    e=0;
    delayus(50);
}

void lcd_csh(){
    wat_ml(0x38);
    wat_ml(0x01);
    wat_ml(0x02);
    wat_ml(0x06);
    wat_ml(0x0c);
}   

void main(){
    csh_io();
    lcd_csh();   
    for(num=0;num<16;num++){
        wat_data(tab1[num]);
        delay(300);
    }
    wat_ml(0x80+0x40);
    for(num=0;num<15;num++){
        wat_data(tab2[num]);
        delay(300);
    }
    while(1);   
}
LED点亮世界🇨🇳
回复

使用道具 举报 送花

  • 打卡等级:以坛为家II
  • 打卡总天数:489
  • 最近打卡:2025-05-02 10:56:10

6

主题

49

回帖

769

积分

高级会员

积分
769
发表于 2023-11-11 10:10:11 来自手机 | 显示全部楼层
谢谢楼主 !
回复

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-2 22:10 , Processed in 0.227302 second(s), 57 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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