標題: STM32驅動帶字庫12864的大字體時鐘源程序 [打印本頁]

作者: kissme    時間: 2020-3-23 19:09
標題: STM32驅動帶字庫12864的大字體時鐘源程序
串口調整時間。自動背光。24節(jié)氣,溫度顯示。星期以及農歷顯示。特殊日期顯示等。因本人才入門,故此程序寫的實在不咋滴。望批評指教 。謝謝

制作出來的實物圖如下:



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);
        }
}

作者: yxt123    時間: 2021-3-7 13:47
樓主能否發(fā)個源碼,謝謝




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1