找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1417|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于STM32的(IIC OLED 顯示)+矩陣按鍵串口打印程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:316613 發(fā)表于 2023-2-16 15:23 | 只看該作者 回帖獎勵 |正序?yàn)g覽 |閱讀模式
#include "stm32f10x.h"
#include "oled.h"
#include "sys.h"
#include "lnterface.h"
#include "bmp.h"
#include "24cxx.h"
#include "led.h"
#include "key.h"
#include "usmart.h"     
#include "key4_4.h"
#include "usart.h"   

unsigned int year=2019,month=8,day=8;//年月日

unsigned int nzs=12,nzf=22;//鬧鐘時(shí) 鬧鐘分


//unsigned int time=5,branch=8;
//unsigned int second=5,second2=5;//時(shí)分秒

unsigned int shi=11,fen=21,miao=50;//時(shí)分秒
unsigned int num=0;
unsigned int S;



u8 key=0;
unsigned int Choice=2;
int Bluetooth_Sign=1,WIFI_Sign=33,Flashlight_Sign=1,Electricity_Sign=4;
int Status_Bar_Sgin=0,Content_Column_Sgin=0;
int Key_Selectio=0;
int conu=0;
int Page_Sgin=0;
int count=0;
int Return_Sgin=0;
int Sgin=1;




int text_Buffer[]={00000000};
#define size sizeof(text_Buffer)    //讀取要寫入芯片中的字節(jié)數(shù)。


void FMQ(void)
{
    fmq=1;//叫
    delay_ms(50);
    fmq=0;//停
    delay_ms(50);
}

void Timer2_Init_Config(void)
{
    NVIC_InitTypeDef  NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);        //使能Timer2時(shí)鐘

    TIM_TimeBaseStructure.TIM_Period = 9999;                        //設(shè)置在下一個(gè)更新事件裝入活動的自動重裝載寄存器周期的值(計(jì)數(shù)到10為1ms)  9 1MS計(jì)數(shù)   99 10ms基計(jì)數(shù)
    TIM_TimeBaseStructure.TIM_Prescaler = 7199;                    //設(shè)置用來作為TIMx時(shí)鐘頻率除數(shù)的預(yù)分頻值(10KHz的計(jì)數(shù)頻率)
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;        //設(shè)置時(shí)鐘分割:TDTS = TIM_CKD_DIV1
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;    //TIM向上計(jì)數(shù)模式
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);                //根據(jù)TIM_TimeBaseInitStruct中指定的參數(shù)初始化TIMx的時(shí)間基數(shù)單位
   
    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;                //設(shè)置中斷向量號
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;    //設(shè)置搶先優(yōu)先級0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;            //設(shè)置響應(yīng)優(yōu)先級0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                //使能NVIC
    NVIC_Init(&NVIC_InitStructure);
     
    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE );                 //使能TIM2指定的中斷
    TIM_Cmd(TIM2, ENABLE);                              
}

void TIM2_IRQHandler(void)                                                   //定時(shí)器2中斷服務(wù)函數(shù)1S一次
{
    if(TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
    {
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);   
   
        miao++;
        if(miao==60)
        {
            miao=0;
            fen++;
            if(fen==60)
            {
                fen=0;
                shi++;
                if(shi==24)
                {
                    shi=0;
                }
            }
        }
        if(shi==nzs&&fen==nzf)
        {
            FMQ();
        }        
    }   
}

int main(void)
{     
     unsigned int datatemp[size];   
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);    //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級
     delay_init();
     uart_init(115200);      
     IIC_Init();
     OLED_Init();
     LED_Init();
     KEY_Init();
     Timer2_Init_Config();
     Key_Init();

    while(1)
    {
        
   
Key_Test();

    //AT24CXX_WriteLenByte(0,miao,size);

        
    //S=AT24CXX_ReadLenByte(0,size);
    //printf("%d",S);


    WhenTheDisplay2();





    //lnterface();  //菜單顯示   
    //WhenTheDisplay();
    /*
        OLED_P16x32Ch(1*16,2,1);        //屏幕中間顯示12:28
        OLED_P16x32Ch(2*16,2,2);
        OLED_P16x32Ch(3*16,2,10);  
        OLED_P16x32Ch(4*16,2,2);
        OLED_P16x32Ch(5*16,2,8);
        
    */
        
        //OLED_P32x32Ch(1*32,2,0);    //您   
        //OLED_P32x32Ch(2*32,2,1);    //好
        //OLED_P128x48Ch(0,2,0);//嗨占滿屏幕
        
    /*    Status_Bar();                      // 頂層圖標(biāo)顯示
        OLED_P8x16Str(1*16,2,"Tomorrow");//第一行
        OLED_P8x16Str(1*16,4,"123");     //第二行
        OLED_P8x16Str(1*16,6,"123");      //第三行
    */


/*
    OLED_P16x16Ch(0*16,Choice,44);            //選擇箭頭
    OLED_P16x16Ch(1*16,2,65);                 //藍(lán)
    OLED_P16x16Ch(2*16,2,66);                 //牙
   
    OLED_P8x16Str(1*16,4,"WIFI");             //WIFI
   
    OLED_P16x16Ch(1*16,6,67);                   //溫
    OLED_P16x16Ch(2*16,6,68);                   //度
   
        
    OLED_ShowNum(6*16,6,Choice/2,1,12);    //右下角頁數(shù)
    OLED_P6x8Str(6.5*16,7,"/");
    OLED_P6x8Str(7*16,7,"10");
   
*/
        
    }
}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

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

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

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

快速回復(fù) 返回頂部 返回列表