51 SCM - electronic calendar (buzzer, matrix keyboard, lcd1602, timer / timer, serial / uart, basic calendar, alarm clock, calendar, modification time, and small game)

51 SCM - electronic calendar (buzzer, matrix keyboard, lcd1602, timers, serial ports, basic calendar, alarm clock, calendar, modification time, and small game)

MCU production for archiving electronic calendar 51, and proteus simulation circuit, the buzzer cover according to the present design, UART, Timer, matrix scan, LCD1602 display, basic calendar (year / month / day / hour / minute / second), alarm clock, calendar , modify the function of time and games, etc., basically covering the use of all 51 internal microcontroller resources.

The simulation results show

The basic calendar the results:
Basic calendar
set the alarm operating results:
Alarm Clock
the set schedule operating results:
Agenda
Modified the results:
Change the time
small game result:
Games

Circuit simulation

Simulation platform proteus7.10.
Circuit simulation

Code directory structure

| -Source # electronic calendar Source
| - | --- include.h # common definitions
| - | --- main.c # main function
| - | --- main.h
| - ± the -base # basic calendar
| - | ------- clock.c
| - | ------- clock.h
| - ± -drv # electronic calendar drive
| - | --- ± -buzzer # buzzer
| - | - - | ------- buzzer.c
| - | --- | ------- buzzer.h
| - | --- ± -keyboard # matrix keyboard
| - | --- | - keyboard.c ------
| - | --- | ------- keyboard.h
| - | --- ± -lcd1602 # LCD1602
| - | --- | ------ -lcd1602.c
| - | --- | ------- lcd1602.h
| - | --- ± -timer # timers
| - | --- | ------- timer.c
| - | --- | ------- timer.h
| - | --- | - UART serial #
| - | ----------- uart.c
| - | - uart.h ---------
| - | --- EXT # electronic calendar extension
| ------- ± -alarm
| ------- | ------- alarm.c # Alarm
| ------- | ------- alarm.h
| ------- | - ------ schedule.c # schedule
| ------- | ------- schedule.h
| ------- ± -game # Games
| ----- - | catch_rabbit.c -------
| ------- | ------- catch_rabbit.h
| ------- | -set # modified
| --- change_time.c ------------
| --------------- change_time.h

51 SCM - electronic calendar (project + simulation)

Including engineering and simulation circuit, clear project structure.
Download Link: //download.csdn.net/download/weixin_44413515/12178845

51 SCM - electronic calendar (all code)

All code in the same file, there is a small amount of additions and deletions consistent, functional, code structure is not clear.
Download Link: //download.csdn.net/download/weixin_44413515/12178806

51 SCM - electronic calendar (Proteus circuit emulation)

Download Link: //download.csdn.net/download/weixin_44413515/12178811

Electronic calendar sub-module Software

Visit the link:

  • Matrix keyboard: https: //blog.csdn.net/weixin_44413515/article/details/104528178
  • uart driver: https: //blog.csdn.net/weixin_44413515/article/details/104501797
  • lcd1602 drive: https: //blog.csdn.net/weixin_44413515/article/details/104439315
  • timer:https://blog.csdn.net/weixin_44413515/article/details/104428509
  • Buzzer drive: https: //blog.csdn.net/weixin_44413515/article/details/104618480
  • Basic functions: https: //blog.csdn.net/weixin_44413515/article/details/104638576
  • Alarm Clock: https: //blog.csdn.net/weixin_44413515/article/details/104682602
  • Schedule reminder: https: //blog.csdn.net/weixin_44413515/article/details/104705564
  • Modified: https: //blog.csdn.net/weixin_44413515/article/details/104742129

Electronic calendar function to enumerate

A list of calendar functions, such as: basic calendar (FUN_CLOCK), alarm clock (FUN_ALARM), schedule (FUN_SCHEDULE), modification time (FUN_CHANGE_TIME) and small game (FUN_CATCH_RABBIT). Abstract data type fun_t.

typedef enum {  // 功能判断
    FUN_CLOCK = 0,
    FUN_ALARM,
    FUN_SCHEDULE,
    FUN_CHANGE_TIME,
    FUN_CATCH_RABBIT,
    FUN_BUTT
} fun_t;

Function Switch

By switching function keys KEY_FUN completed, KEY_FUN key press is detected, switching to the next operating mode.

/*******************************************************************************
* 函 数 名         : response_key
* 函数功能         : 按键响应
* 输    入         : key:按键值
* 输    出         : void
* 说    名         : none
*******************************************************************************/
void response_key(key_t key)  // 按键响应
{
    switch (key) {
        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ADD:
        case KEY_SUB:
        case KEY_ENTER:
        case KEY_TRANS: break;
        case KEY_FUN: {  // 加1
            fun++;
            fun_change = 1;
            if (fun >= FUN_BUTT) {
                fun = FUN_CLOCK;
            }
            break;
        }
        case KEY_BACK: {
            fun_change = 1;
            fun = FUN_CLOCK;
            break;
        }
        default: break;
    }
}

Feature Selection

Fun by the current value, the currently selected choice the functions performed, and executed and displayed. The first call to a function will be initialized once, at the exit of a function call to initialize the interface may withdraw complete cleanup.

/*******************************************************************************
* 函 数 名         : fun_select
* 函数功能         : 功能选择
* 输    入         : fun:功能号
* 输    出         : void
* 说    名         : none
*******************************************************************************/
void fun_select(fun_t fun)  // 功能选择
{
    switch (fun) {
        case FUN_CLOCK: {
            if (fun_change) {
                fun_change = 0;
                timer_set_update_level(1);
                clock_init();
            }
            clock_display_update();
            break;
        }
        case FUN_ALARM: {
            if (fun_change) {
                fun_change = 0;
                alarm_init();
            }
            alarm_response_key(key);
            alarm_display();
            break;
        }
        case FUN_SCHEDULE: {
            if (fun_change) {
                fun_change = 0;
                schedule_init();
            }
            schedule_response_key(key);
            schedule_display();
            break;
        }
        case FUN_CHANGE_TIME: {
            if (fun_change) {
                fun_change = 0;
                change_time_init();
            }
            change_time_response_key(key);
            change_time_display();
            break;
        }
        case FUN_CATCH_RABBIT: {
            if (fun_change) {
                fun_change = 0;
                catch_rabbit_init();
            }
            catch_rabbit_response_key(key);
            break;
        }
        default: break;
    }
}

The main function

Responsible for initializing the various hardware modules, microcontroller 51 initializes the internal system, then the mapping cyclic scanning matrix keyboard and function keys to the key value, to do alarm, schedule reminders detection, complete the switching function.

/*
################################################################

                                万年历

################################################################
*/
void main(void)
{
    u8 state = 0;

    buzzer_enable_passive();
    lcd1602_init();
    timer_init();
    uart_init();

    while (1) {
        key = keyboard_map_to_key(keyboard_scan());

        fun_select(fun);

        state = alarm_check(time.hour, time.miunte);
        if (state && (key == KEY_TRANS) && (fun != FUN_ALARM) && (fun != FUN_SCHEDULE)) {
            alarm_close();
        }
        state = schedule_check(time.month, time.day, time.hour, time.miunte);
        if (state && (key == KEY_TRANS) && (fun != FUN_ALARM) && (fun != FUN_SCHEDULE)) {
            schedule_close();
        }

        response_key(key);

#if 0
        uart_send_time();
#endif
    }
}

Appendix - electronic calendar (main.h)

#ifndef __MAIN_H__
#define __MAIN_H__

#include "include.h"
#include "keyboard.h"

typedef enum {  // 功能判断
    FUN_CLOCK = 0,
    FUN_ALARM,
    FUN_SCHEDULE,
    FUN_CHANGE_TIME,
    FUN_CATCH_RABBIT,
    FUN_BUTT
} fun_t;

void response_key(key_t key);  // 按键响应
void fun_select(fun_t fun);  // 功能选择

#endif

Appendix - electronic calendar (main.c)

/* 晶振fosc = 12MHZ */
#include "main.h"
#include "lcd1602.h"
#include "keyboard.h"
#include "timer.h"
#include "buzzer.h"
#include "uart.h"
#include "clock.h"
#include "alarm.h"
#include "schedule.h"
#include "change_time.h"
#include "catch_rabbit.h"

key_t key = KEY_BUTT;  // 按键值
fun_t fun = FUN_CLOCK;  // 功能判断
u8 fun_change = 1;  // 功能改变,0无效,other有效

/*
################################################################

                                万年历

################################################################
*/
void main(void)
{
    u8 state = 0;

    buzzer_enable_passive();
    lcd1602_init();
    timer_init();
    uart_init();

    while (1) {
        key = keyboard_map_to_key(keyboard_scan());

        fun_select(fun);

        state = alarm_check(time.hour, time.miunte);
        if (state && (key == KEY_TRANS) && (fun != FUN_ALARM) && (fun != FUN_SCHEDULE)) {
            alarm_close();
        }
        state = schedule_check(time.month, time.day, time.hour, time.miunte);
        if (state && (key == KEY_TRANS) && (fun != FUN_ALARM) && (fun != FUN_SCHEDULE)) {
            schedule_close();
        }

        response_key(key);
#if 0
        uart_send_time();
#endif
    }
}

/*******************************************************************************
* 函 数 名         : response_key
* 函数功能         : 按键响应
* 输    入         : key:按键值
* 输    出         : void
* 说    名         : none
*******************************************************************************/
void response_key(key_t key)  // 按键响应
{
    switch (key) {
        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ADD:
        case KEY_SUB:
        case KEY_ENTER:
        case KEY_TRANS: break;
        case KEY_FUN: {  // 加1
            fun++;
            fun_change = 1;
            if (fun >= FUN_BUTT) {
                fun = FUN_CLOCK;
            }
            break;
        }
        case KEY_BACK: {
            fun_change = 1;
            fun = FUN_CLOCK;
            break;
        }
        default: break;
    }
}

/*******************************************************************************
* 函 数 名         : fun_select
* 函数功能         : 功能选择
* 输    入         : fun:功能号
* 输    出         : void
* 说    名         : none
*******************************************************************************/
void fun_select(fun_t fun)  // 功能选择
{
    switch (fun) {
        case FUN_CLOCK: {
            if (fun_change) {
                fun_change = 0;
                timer_set_update_level(1);
                clock_init();
            }
            clock_display_update();
            break;
        }
        case FUN_ALARM: {
            if (fun_change) {
                fun_change = 0;
                alarm_init();
            }
            alarm_response_key(key);
            alarm_display();
            break;
        }
        case FUN_SCHEDULE: {
            if (fun_change) {
                fun_change = 0;
                schedule_init();
            }
            schedule_response_key(key);
            schedule_display();
            break;
        }
        case FUN_CHANGE_TIME: {
            if (fun_change) {
                fun_change = 0;
                change_time_init();
            }
            change_time_response_key(key);
            change_time_display();
            break;
        }
        case FUN_CATCH_RABBIT: {
            if (fun_change) {
                fun_change = 0;
                catch_rabbit_init();
            }
            catch_rabbit_response_key(key);
            break;
        }
        default: break;
    }
}
Published 15 original articles · won praise 17 · views 1618

Guess you like

Origin blog.csdn.net/weixin_44413515/article/details/104742847