找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2446|回复: 1
收起左侧

STM32驱动带字库12864的大字体时钟源程序

[复制链接]
ID:461428 发表于 2020-3-23 19:09 | 显示全部楼层 |阅读模式
串口调整时间。自动背光。24节气,温度显示。星期以及农历显示。特殊日期显示等。因本人才入门,故此程序写的实在不咋滴。望批评指教 。谢谢

制作出来的实物图如下:

分时显示信息

分时显示信息


分时显示诗词

分时显示诗词

分时显示农历

分时显示农历

void LCD12864_InitPort(void)//12864使用的端口配置
{
        GPIO_InitTypeDef  GPIO_InitStructure;        //定义结构体               
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);    //把调试设置普通IO口
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出   
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init( GPIOB , &GPIO_InitStructure);          //初始化IO口配置
}

void KEY_K()//按键使用的端口配置
{
                GPIO_InitTypeDef  GPIO_InitStructure;        //定义结构体                        
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);  //
        //GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);    //把调试设置普通IO口
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_10|GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
        GPIO_Init(GPIOB , &GPIO_InitStructure);

}

//LCD12864写一个字节函数
void xiebye(u8 bye)
{
        u8 a;
        for(a=0;a<8;a++)
        {
                sck=1;
                if(bye&0x80)sda=1;
                        else sda=0;
                 bye=bye<<1;
                sck=0;
        delay_us(3);
        }
}
//LCD12864写命令
void xiecom(u8 com)
{
                cs=1;
                xiebye(0xf8);
                xiebye(0xf0&com);
                xiebye(0xf0&com<<4);
                cs=0;
}
//写数据
void xiedat(u8 dat)
{
        cs=1;
                xiebye(0xfa);
                xiebye(0xf0&dat);
                xiebye(0xf0&dat<<4);
                cs=0;
}
void init12864()
{
    delay_us(100);  xiecom(0x30);
        delay_us(20);  xiecom(0x02);
        delay_us(20);  xiecom(0x0c);
        delay_us(20);  xiecom(0x06);
        delay_us(20);  xiecom(0x80);
        delay_us(20);  xiecom(0x01);
}

//任意位置写汉字
void xiezi(u8 x,u8 y,u8 *z)
{
        u8 poos;
        if(x==1)poos=0x80+y;
        if(x==2)poos=0x90+y;
        if(x==3)poos=0x88+y;
        if(x==4)poos=0x98+y;
        xiecom(poos);
        while(*z!='\0')
        {
          xiedat(*z);
                z++;
        
        }
}
void pos(u8 x,u8 y) //屏坐标位置设定
{
        u8 poos;
   if (x==1)
     {x=0x80;}
   else if (x==2)
     {x=0x90;}
   else if (x==3)
     {x=0x88;}
   else if (x==4)
     {x=0x98;}
        poos=x+y;
        xiecom(poos);
}

void xieziz(u8 *s)//写字符串
{
        while(*s!='\0')
        {
                xiedat(*s);
        s++;
                delayus(0);
        }
}

////////////////////////////////////////////////////////////////////////////////////
void xiez(u8 x,u8 y,u8 *z)
{
        u8 poos;
        if(x==1)poos=0x80+y;
        if(x==2)poos=0x90+y;
        if(x==3)poos=0x88+y;
        if(x==4)poos=0x98+y;
        xiecom(poos);
        while(*z!='\0')
        {
          xiedat(*z);
                z++;
                delay_ms(60);
        }
}
回复

使用道具 举报

ID:483456 发表于 2021-3-7 13:47 | 显示全部楼层
楼主能否发个源码,谢谢
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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