找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3261|回復: 1
打印 上一主題 下一主題
收起左側

STM32驅動帶字庫12864的大字體時鐘源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:461428 發(fā)表于 2020-3-23 19:09 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
串口調整時間。自動背光。24節(jié)氣,溫度顯示。星期以及農(nóng)歷顯示。特殊日期顯示等。因本人才入門,故此程序寫的實在不咋滴。望批評指教 。謝謝

制作出來的實物圖如下:



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寫一個字節(jié)函數(shù)
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;
}
//寫數(shù)據(jù)
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);
        }
}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:483456 發(fā)表于 2021-3-7 13:47 | 只看該作者
樓主能否發(fā)個源碼,謝謝
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表