找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 736|回复: 0
打印 上一主题 下一主题
收起左侧

基于STM32的(IIC OLED 显示)+矩阵按键串口打印程序

[复制链接]
跳转到指定楼层
楼主
ID:316613 发表于 2023-2-16 15:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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;//闹钟时 闹钟分


//unsigned int time=5,branch=8;
//unsigned int second=5,second2=5;//时分秒

unsigned int shi=11,fen=21,miao=50;//时分秒
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)    //读取要写入芯片中的字节数。


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时钟

    TIM_TimeBaseStructure.TIM_Period = 9999;                        //设置在下一个更新事件装入活动的自动重装载寄存器周期的值(计数到10为1ms)  9 1MS计数   99 10ms基计数
    TIM_TimeBaseStructure.TIM_Prescaler = 7199;                    //设置用来作为TIMx时钟频率除数的预分频值(10KHz的计数频率)
    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;        //设置时钟分割:TDTS = TIM_CKD_DIV1
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;    //TIM向上计数模式
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);                //根据TIM_TimeBaseInitStruct中指定的参数初始化TIMx的时间基数单位
   
    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;                //设置中断向量号
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;    //设置抢先优先级0
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;            //设置响应优先级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)                                                   //定时器2中断服务函数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);    //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
     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();                      // 顶层图标显示
        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);                 //蓝
    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);    //右下角页数
    OLED_P6x8Str(6.5*16,7,"/");
    OLED_P6x8Str(7*16,7,"10");
   
*/
        
    }
}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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