标题: STM32驱动带字库12864的大字体时钟源程序 [打印本页]

作者: kissme    时间: 2020-3-23 19:09
标题: STM32驱动带字库12864的大字体时钟源程序
串口调整时间。自动背光。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);
        }
}

作者: yxt123    时间: 2021-3-7 13:47
楼主能否发个源码,谢谢




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1