Design of wireless answering device using 51 microcontroller

Publisher:Meiren520Latest update time:2023-10-10 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

* Customize Macro

//The encoding is reverse encoding

#define CLEAR 0x7f //Define the complement of clear

#define LED_BEGIN 0x01 // Define the display of the digital tube at the beginning

#define LED_FOUL 0x38 // Display the letter "F" after a foul, digital tube encoding

#define LED_C 0x31 // The encoding of the letter "C"

#define LED_L 0x71 // The encoding of the letter "L", two are used to display "CL" after the host cancels --cancel

#define GET 1 // This is mixed as a parameter of a function, which means successful answer.

#define FOUL 0 // Mixed with the above parameters, foul --- the usage of these two will be reflected later

#define READY 0x7e

Design of wireless answering device using 51 microcontroller

//The following is the command sent to the host computer, corresponding to cmdID

#define _STRING_READY_ 9//Adjust the answer countdown and prepare to start the answer

#define _STRING_START_ 8//The countdown ends and the answering begins

#define _STRING_CANCEL_ 7//Cancel answering

#define _CHANGE_TIME_ 6//Read seconds each time

//Send commands 1--4 to represent the serial number of the answering terminal

//Because a 12M crystal oscillator is used on the board, and an 11.0529M crystal oscillator is used during simulation. In order to facilitate compilation at different times, this is combined with the subsequent conditional compilation to make it easier for the program to modify parameters.

//#define CLOCK_FREQUENCY_12M 1

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

* Custom data type

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

typedef unsigned char Byte; // One byte

typedef unsigned int Word; // One word, two bytes

typedef bit Bool; // Imitate Boolean variables

//typedef sbit Port; // I wanted to use a custom port type variable, which is more convenient, but I don’t know why it can’t be compiled.

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

* Define MAX7219 register

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

#define REG_NO_OP 0x00 //Define no operation register

#define DIG_1 0x01 //Define digital tube 1 register

#define DIG_2 0x02 //Define digital tube 2 register

#define DIG_3 0x03 //Define digital tube 3 register

#define DIG_4 0x04 //Define digital tube 4 register

#define DIG_5 0x05 //Define digital tube 5 register

#define DIG_6 0x06 //Define digital tube 6 register

#define DIG_7 0x07 //Define digital tube 7 register

#define DIG_8 0x08 //Define digital tube 8 register

#define REG_DECODE 0x09 //Define decoding control register

#define REG_INTENSITY 0x0a //Define display brightness register

#define REG_SCAN_LIMIT 0x0b //Define scan limit register

#define REG_SHUTDOWN 0x0c // Define "shutdown" mode register

#define REG_DISPLAY_TEST 0x0f // Define "display test" mode register

#define INTENSITY_MIN 0x00 //Define the minimum display brightness

#define INTENSITY_MAX 0x0f //Define the maximum display brightness

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

* Define hardware pin connections

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

sbit DATA=P2^0; //Data port of MAX7219

sbit LOAD=P2^1; //Latch port of MAX7219

sbit CLK=P2^2; //clock port of MAX7219

sbit HOST_START=P0^0; //Host button, the button used to restart start

sbit HOST_CANCEL=P0^1; //Clear button used by the host to cancel answering questions

sbit SWITCH1_3=P1^4; // DIP switch to adjust the countdown time. The number before the underline represents the serial number of the switch, and the number after the underline represents the value of the switch.

sbit SWITCH2_2=P1^5; // Same as above

sbit SWITCH3_2=P1^6; // Same as above

sbit SWITCH4_1=P1^7; // Same as above

sbit BEEP=P0^7; //Define buzzer port

#ifdef USE_SOUND //You can choose whether to use the sound during simulation through define

sbit LS138_C=P2^4; //Define the decoder input

sbit LS138_B=P2^5; //Same as above

sbit LS138_A=P2^6; //Same as above

sbit LS138_E1=P2^7; //Define the decoder enable end

#endif

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

* Define global variables

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

Byte data intrCounter; // Number of timer interruptions

Byte data beginNum; // Start countdown time

Byte data counterBack; // Put the number of interruptions in it for later use

Byte data showNum; // The time the digital tube is displaying

Bool data isStart; // Whether to start answering questions

Bool data isFoul; // Whether there is a foul

Bool data isPressed; // Whether there is a key to answer the question is pressed

Byte data number_temp; // A variable used to record the last status of P1 port

Bool data needResetTimes;//Record whether the number of overflows of Timer0 needs to be reset

code unsigned char C51BOX2[3] _at_ 0x43; //Prevent the program from running away when using C51Box

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

* Common cathode seven-segment digital tube display corresponding segment lookup table (numbers 0-9 correspond to code_table [0]-[9] respectively)

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

Byte code code_table_zheng[10]=

{0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b};

Byte code code_table[10]=

{0x01,0x4f,0x12,0x06,0x4c,0x24,0x20,0x0f,0x00,0x04};

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

* Function declaration

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

void MAX7219_SendByte (Byte dataout);

void MAX7219_Write (Byte reg_number, Byte dataout);

void MAX7219_DisplayChar(Byte digit, Byte character);

void MAX7219_Clear (void);

void MAX7219_SetBrightness (Byte brightness);

void MAX7219_DisplayTestStart (void);

void MAX7219_DisplayTestStop (void);

void MAX7219_ShutdownStart (void);

void MAX7219_ShutdownStop (void);

void MAX7219_Init (void);

void Delay10ms(void);

Bool GetHostStartKey (void);

Bool GetHostCancelKey (void);

void GetCounter(void);

Byte GetPressed(Byte KeyState);

Byte GetPressedWireless(Byte KeyState);

void IT0_Init(void);

void Timer0_Overflow();

void PressedHandle(Byte keyPressed);

void GetOrFoulHandle(Bool state);

void CancelHandle();

void SPEAKER_count (void); //Declare the countdown sound function

void SPEAKER_start(void); //Declare the start answering sound function

void SPEAKER_get(void); //Declare the sound function

void SPEAKER_foul(void); // Declare the foul sound function

void initialSerial();

void sendNumber(int number);//The serial port sends a number, what is sent here is the CommandID

void sendString(unsigned char *string);//Send string through serial port

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

* MAX7219_SendByte()

*

* Description: Transfer one byte of data to MAX7219

* Arguments : dataout = data to send

* Returns : none

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

void MAX7219_SendByte (Byte dataout)

{

Change in;

for (i=8;i》0;i--)

{

Byte mask=1《《(i-1);//mask is a mask, used to take bits

CLK=0;//The bit input of MAX7219 is before the rising edge of the clock, so it must become low level before each bit is sent.

if (dataout&mask)

DATA=1;

else

DATA=0;

CLK=1;//After all eight bits are transferred, they become high level and latched

}

}

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

* MAX7219_Write()

*

* Description: Write commands to MAX7219

* Arguments : reg_number = register to write to

* dataout = data to write to MAX7219

* Returns : none

Unfinished~

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

void MAX7219_Write (Byte reg_number, Byte dataout)

{

LOAD=0;//It is also before the rising edge of the latch. It must become low level before sending these two bytes.

MAX7219_SendByte(reg_number); //Send register address

MAX7219_SendByte(dataout);//Send data

LOAD=1;//turn to high level, latch

}

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

* MAX7219_DisplayChar()

*

* Description: Make a certain digit display a number

* Arguments : digit = digit number (0-7)

* character = character to display (0-9, A-Z)

* Returns : none

void MAX7219_DisplayChar(Byte digit, Byte character)

{

MAX7219_Write(digit, character);

}

* MAX7219_Clear()

* Description: Clear the display of all bits

* Arguments : none

* Returns : none


Reference address:Design of wireless answering device using 51 microcontroller

Previous article:Design of step angle subdivision system for stepper motor based on AT89CC51 microcontroller and TA8435 chip
Next article:51 Basic concepts of microcontroller serial communication

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号