Production of 51 single chip music calendar

Publisher:温馨家园Latest update time:2020-02-11 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. The power supply voltage is 4.8V-5.2V, and can be powered directly by computer USB.
2. Program modification instructions
1. If you can't compile, it means that the KEIL library file you are using is incomplete. Please change to a complete version of KEIL, or buy it in my store. This program is fully compiled and there is no warning.
2. This program takes up a lot of space due to the lunar calendar, solar terms and other data. After compilation, it has more than 19K. Please use a 51 microcontroller with a program memory of more than 20K, such as STC89C55, STC89C58, STC89C516, AT89C55, AT89S54, SST89C58, etc.
3. If your Chinese characters are not displayed completely or are garbled, such as "三" cannot be displayed, it is because your KEIL has not been patched, not a program problem. As for what patch to use, you can search online or ask me for it.
4. When modifying the bit definition, you need to modify sbit BeepIO = P3^7; sbit KEY_1 = P2^7; in the Soundplay.h file together;
5. Please use a passive buzzer or a small speaker as the buzzer will sound better.
III. Birthday, solar terms and festival reminders
1. The various reminders of this perpetual calendar will be displayed alternately on the fourth line of the main interface, with birthdays and solar terms being displayed first.

The schematic diagram and PCB diagram of the music perpetual calendar drawn by Altium Designer are as follows: (Project files can be downloaded in the 51hei attachment)

Component list of single-chip perpetual calendar:
Name Quantity Description
STC89C54 (STC89C516) single-chip microcomputer 1 51 single-chip microcomputers with memory ≥20K can be used
DS1302 1    
DS18B20 1    
40DIP socket 1    
8DIP socket 1    
3DIP socket 1    
20-    
core socket 1 20-core pin 1     10K resistor 1 Passive buzzer    
can be installed 1 CR2032 battery 1     Battery holder     1 Power socket 1     Button 4     switches 1     32768HZ crystal oscillator 1     11.0592MHZ crystal oscillator 1     S8050 transistor 1     30P capacitor 2     103 capacitor 1 10uF electrolytic     can be installed 1 4.7K resistor 1     10K resistor 2     220uF electrolytic 1 PCB     can be installed 1 12864 LCD 1 ST7920 drives the font library LCD microcontroller music calendar source program as follows:


















/********************************************************************************/

//12864 LCD perpetual calendar clock 2010 latest V5.2 version

//Design: Yang Limin

//Beginning of the program

//Updated: September 3, 2010

//Main features: multi-function menu, multi-style main interface, birthday, festival, solar term, lunar calendar time multi-function reminder, alarm clock, music, temperature, screen self-check

//5.1 added the adjustment of time highlight and alarm setting highlight display

//5.2 adjusted the priority display of birthdays and solar terms

/********************************************************************************/

//head File

#include

#include

#include

#include "SoundPlay.h" //Music file

#define uchar unsigned char 

#define uint unsigned int

/********************************************************************************/

//Speaker definition

sbit beep = P3^7; // speaker

/********************************************************************************/

// Temperature sensor definition

sbit DQ = P2 ^ 0; //ds18B20

uint tvalue; //temperature value

uchar tflag, flagdat, t, hh1; // temperature positive and negative flag

/********************************************************************************/

//Keyboard pin definition

//sbit KEY_1 = P2^7; //Upper left, defined in the music file SoundPlay.h

sbit KEY_2 = P2^6; //lower left

sbit KEY_3 = P2^5; //upper right

sbit KEY_4 = P2^4; //lower right

/********************************************************************************/

//Define DS1302 clock interface

sbit clock_clk = P2 ^ 1; //ds1302_clk (clock line)

sbit clock_dat = P2 ^ 2; //ds1302_dat (data line)

sbit clock_Rst = P2 ^ 3; //ds1302_Rst (reset line)

//Define each bit in accumulator A

sbit a0 = ACC ^ 0;

sbit a1 = ACC ^ 1;

sbit a2 = ACC ^ 2;

sbit a3 = ACC ^ 3;

sbit a4 = ACC ^ 4;

sbit a5 = ACC ^ 5;

sbit a6 = ACC ^ 6;

sbit a7 = ACC ^ 7;

/********************************************************************************/

//Define global variables

unsigned char yy,mo,dd,xq,hh,year,year1; //Define time mapping global variables (special registers)

unsigned char shi,ge,sec_temp,min_temp,hour_temp,secl,selx,e=0,hh1,mm1,k,mm,ss,n;

char n1,n2;

bit w = 0; //Time adjustment flag

static unsigned char menu = 0; //Define static hour update data variable

static unsigned char keys = 0; //Define static hour update data variables

static unsigned char timecount = 0; //define static software counter variable

/********************************************************************************/

//-----------------------------------------------

//TS12864 parallel port related settings//

#define BUSY_FLAG P0_7 //LCD module busy flag

#define MPU_RS_CH P1_5 //Register selection input

#define MPU_RW_CH P1_6 //Read and write control

#define MPU_ENABLE P1_7 //Enable control

#define LCD_DATA P0 //LCD data port

//-----------------------------------------------

#define LOW 0 //Low level

#define HIGH 1 //High level

#define OFF 0 //Logic off

#define ON 1 //Logic on

//-----------------------------------------------

//LCD module instruction set definition

#define cClearDisplay 0x01 //Clear display instruction

#define cEntryModeSet 0x06 //Set the input mode

#define cDisplayOnCtrl 0x0c //Set display control

#define cFunctionSetB 0x30 //Function setting (basic instructions)

#define cFunctionSetE 0x34 //Function setting (extended instruction)

#define cFuncDrawOn 0x36 //Set drawing function

//-----------------------------------------------

uchar xdata lcdPosX, lcdPosY; //X,Y coordinates

uchar xdata halfScr, halfLineCnt, basicBlock; //half screen, half screen lines, N*8 blocks

//-----------------------------------------------

//Subroutine declaration and usage

bit scanKey1 (void);

//Button 1 detection

void procKey (void);

//Key processing subroutine

void lcdInit (void);

// Initialize LCD subroutine

void lcdClear (void);

//Clear LCD text screen subroutine

void lcdWriteCommand (uchar Command); 

//Write control commands to LCD subroutine

//Input parameters: LCD control instructions

void lcdWriteData (uchar Data); 

//Write display data to LCD subroutine

//Input parameters: display data

void checkLcdBusy (void); 

//Detect LCD busy subroutine

void displayPhoto (uchar *bmp, uchar bmpCls); 

//Full screen display graphics subroutine

//Input parameters: *bmp=graphic data 

//bmpCls=clear graphics screen option (OFF means clearing the screen, i.e. displaying graphics, ON means clearing the screen)

void convertChar (uchar CX, CY, width); 

//Character highlighting

//Input parameter: CX=line to highlight characters (0-3)

//CY=column to highlight characters (0-7)

//width=length of the highlighted characters (1-16)

void wrPosition (void); 

//Coordinate writing subroutine

void dispString (uchar X, Y, speed, uchar *msg); 

//Display string subroutine

//Input parameters: X=row (0-3), Y=column (0-7), speed=display speed (milliseconds), msg=character data

void beepBl (void);

//Buzzer sounds once subroutine

void delayMs (uchar ms); 

//Delay (milliseconds) subroutine

//Input parameter: milliseconds

void delaySec (uchar sec); 

//Delay (seconds) subroutine

//Input parameter: seconds

void init_dz();

void clear_img();

//===============================================

//12864 LCD driver

//===============================================

void lcdInit (void)

{

        lcdWriteCommand(cFunctionSetE);

        lcdWriteCommand(cFunctionSetB);

        lcdClear();

        lcdWriteCommand(cEntryModeSet);

        lcdWriteCommand(cDisplayOnCtrl);

        if(k==1){clear_img();lcdClear();

        }

        if(k==0){lcdClear(); clear_img();init_dz();

        }

}

//===============================================

void lcdClear (void) 

{

        lcdWriteCommand(cClearDisplay);

}

//===============================================

void lcdWriteCommand (uchar Command) 

{

        checkLcdBusy();

        MPU_RS_CH = LOW;

        MPU_RW_CH = LOW;

        LCD_DATA = Command;

        MPU_ENABLE = HIGH;

        delayMs(1);

        MPU_ENABLE = LOW;

}


//===============================================

void lcdWriteData (uchar Data) 

{

        checkLcdBusy();

        MPU_RS_CH = HIGH;

        MPU_RW_CH = LOW;

        LCD_DATA = Data;

        MPU_ENABLE = HIGH;

        delayMs(1);

        MPU_ENABLE = LOW;

}

//===============================================

void checkLcdBusy (void) 

{

        LCD_DATA = 0xff;

        MPU_RS_CH = LOW;

        MPU_RW_CH = HIGH;

        MPU_ENABLE = HIGH;

        while (BUSY_FLAG);

        MPU_ENABLE = LOW;

}

//===============================================

void displayPhoto (uchar *bmp, uchar bmpCls) 

{

        lcdPosX = 0x80;

        halfScr = 2;

        

        for (;halfScr != 0; halfScr--)

        {

                lcdPosY = 0x80;

                halfLineCnt = 32;

                

                for (; halfLineCnt != 0; halfLineCnt--)

                {

                        basicBlock = 16;

                        wrPosition();

                        

                        for (; basicBlock != 0; basicBlock--)

                        {

                                if (bmpCls == OFF)

                                {

                                        lcdWriteData (*bmp++);

                                }

                                else if (bmpCls == ON)

                                {

                                        lcdWriteData (0x00);

                                }

                        }

                        lcdPosY++;

                }

                lcdPosX = 0x88;

        }

        lcdWriteCommand(cFuncDrawOn);

        lcdWriteCommand(cFunctionSetB);

}

//===============================================

void convertChar (uchar CX, CY, width) 

{

        displayPhoto(OFF,ON);

        lcdPosY = 0x80;


        if (CX == 0)

        {

                CX = 0x80;

                halfLineCnt = 16;

        }

        else if (CX == 1)

        {

                CX = 0x80;

[1] [2] [3] [4] [5] [6] [7] [8] [9]
Reference address:Production of 51 single chip music calendar

Previous article:51 MCU + K9F2080U0A to make MP3 circuit diagram and source program
Next article:Design of single chip alcohol concentration tester

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号