Design of Oscilloscope Monitoring Program for C8051F

Publisher:Jinyu2022Latest update time:2011-01-23 Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Abstract: The design uses the high-performance single-chip microcomputer C8051F020 as the control chip to monitor the status of 40 buttons, 3 coding switches and 4 potentiometers on the oscilloscope panel. The working principles of the keyboard, coding switch and potentiometer, as well as the hardware circuit connected to the single-chip microcomputer and the implementation of software programming are introduced respectively. The key part adopts the keyboard program design method of one key with multiple meanings, and the key code matching subroutine flow chart is given.
Keywords: keyboard; coding switch; analog-to-digital conversion; monitoring program

The monitoring program is responsible for the allocation and scheduling of all hardware and software resources in the system. It provides a user interface to enable users to obtain a friendly working environment and is an important part of the system design.

1 Overview of C8051F020 single-chip microcomputer
The C8051F020 single-chip microcomputer is a highly integrated system-on-chip. The chip integrates 2 multi-channel ADC subsystems (each subsystem includes 1 programmable gain amplifier and 1 analog multiplexer), 2 voltage output DACs, 2 voltage comparators, voltage reference, SMBus/I2C bus interface, UART, SPI bus interface, 5 general 16-bit timers, 1 programmable counter/timer array (PCA) with 5 capture/compare modules, internal oscillator, 8 8-bit general digital I/0 ports and 64 KBFlash program memory, as well as 8051 compatible high-speed microcontroller core. 2 Working principle of one-key polyphonic keyboard A complete intelligent instrument often has many functions, and many set ranges and parameters. If one key is still used for one function, it is bound to have a large keyboard, the panel will be enlarged accordingly, which is not beautiful and the cost will increase. Therefore, in this type of instrument, the keyboard is designed to have one key with multiple meanings, and one key has multiple functions. In

the case of one key with multiple meanings, a command is not composed of a single key press, but a key sequence. In other words, the interpretation of the meaning of a key depends not only on the current key press, but also on what keys were pressed before. Therefore, for a key polysemy monitoring program, we must first determine whether a key sequence (not a single key press) has constituted a legal command. If it has constituted a legal command, the command is executed, otherwise wait for a new key input. The key polysemy keyboard management program mainly solves the two problems of keyboard key sequence recognition and how to find the corresponding operation program according to the keyboard key sequence. The above problems can be solved by the "one map and three tables" method. That is, a key map is established, which is completed by analyzing the program state table, analyzing the program entry table and the action routine subroutine table. The analysis program state table is divided into 4 columns, namely the current state PSTi, key code, next state, and action routine subroutine number. 3 Working principle of the encoding switch The encoding switch has 3 pins and 5 pins, of which 2 pins are press functions, and the other 3 pins control the left and right rotation functions of the encoding switch. Connected to pins 1 and 2 are two metal static plates of different lengths, and connected to pin 3 is a metal moving plate with 12 or 24 teeth in one circle. When the pulse potentiometer rotates, there are four states: pin 3 is connected to pin 1, pin 3 is connected to pin 2 and pin 1, pin 3 is connected to pin 2, and pin 3 is disconnected from pin 2 and pin 1. In actual use, pin 3 is usually grounded as the data input terminal. Pins 1 and 2 are connected to the I/O port of the microcontroller as data output terminals. Three encoding switches are used in this design, one of which connects pin 1 to P4.0 of the microcontroller and pin 2 to P4.1 of the microcontroller. When the pulse potentiometer rotates left or right, P4.0 and P4.1 will periodically generate the waveform shown in Figure 1. If a 12-point pulse potentiometer rotates one circle, 12 groups of such waveforms will be generated, and a 24-point pulse potentiometer will generate 24 groups of such waveforms. One group of waveforms (or one cycle) contains 4 working states. Therefore, as long as the waveforms of P4.0 and P4.1 are detected, it is possible to identify whether the pulse potentiometer is rotating, and whether it is rotating left or right. 4 C8051F020 MCU ADC0 The ADC0 subsystem of C8051F020 includes: a 9-channel configurable analog multiplexer (AMUX0), a programmable gain amplifier (PGA0) and a 100 ksps 12-bit resolution successive approximation register ADC. The ADC integrates a track-and-hold circuit and a programmable window detector. AMUX0, PGA0, data conversion mode and window detector can be configured by software through special function registers. The ADC subsystem is only allowed to work when the ADOEN bit in the ADC0 control register (ADCOCN) is set to 1. When the ADOEN bit is 0, the ADC subsystem is in low-power shutdown mode. Each pair of ADC0 ports can be programmed to be single-ended input or differential input. The port pairing for differential input is (0, 1), (2, 3), (4, 5), (6, 7), which is determined by the lower 4 bits of the channel selection register AMUXOSL and the lower 4 bits of the channel configuration register AMUXOCF. In AMXOCF, bits 3 to 0 correspond to two pin channels each. Bit value = 0 indicates an independent single-ended input (the reset value is single-ended input); bit value = 1 indicates a differential input pair. The ADC rate in the C8051F series microcontrollers is programmable, but at least 16 system clocks are required. Generally, a tracking/holding capture time of 3 system clocks (>1.5μs) is automatically added before conversion. The method to set the ADC rate in F020 is to configure bits 7 to 3 of the ADCOCF register, and its reset value is 11111 (bits 7 to 3 = SYSCLK/CLK(SAR)-1). Generally, the ADC must be in tracking mode before starting. If bit 6 of the control register ADCOCN is "0", it is always in tracking mode (at this time, starting the four starting modes can be 3 system clocks faster than the tracking start); if it is "1", there are 4 tracking start modes to choose from, that is, assign values ​​to bits 3 to 2 in ADCOCN: 00 is tracking when writing 1 to ADBUSY (software command), 01 is timer 3 overflow tracking, 10 is CNVSTR rising edge tracking (external signal), and 11 is timer 2 overflow tracking. 5 System hardware circuit design The keyboard part uses a 6×6 matrix keyboard, P7.0~P7.5 are row lines, and P3.0~P3.5 are column lines. The intersection of P3.0 and P7.0 is a key, and the P7 port is connected to a 10 kΩ pull-up resistor to 3.3 V. The 1 and 2 pins of the three encoding switches are directly connected to the I/0 pins of the microcontroller. Here, P4.0~P4.5 are selected, and the 3 pins are grounded, and the 4 and 5 pins are used as keys. Take the coding switch connected to P4.O and P4.1 as an example, the circuit diagram is shown in Figure 2. The analog-to-digital conversion part uses an internal voltage reference, so just connect the VREF pin to the VREF0 pin. A potentiometer is used to adjust the analog input, single-ended input, the potentiometer resistance is 10 kΩ, the reference voltage is typically 2.43 V, and the power supply voltage is 3.3 V. In order to maximize the reference voltage, a resistor with a resistance of about 3.58 kΩ is required to be connected in series with the potentiometer to the analog port. The hardware circuit is shown in Figure 3. The 4th and 5th pins of the potentiometer are also used as keys. 6 System Software Design 6.1 One-key polysemy keyboard program design In keyboard analysis, a working status register is used to save the current state of the keyboard. When the keyboard scans a key, the address of the analysis program state table is found from the analysis program entry table according to the value of the current state, and the analysis program state table is entered from the address. Find the matching value, send the next state to the current state unit, take out the action number, calculate the action subroutine entry address according to the action number, and then execute the corresponding subroutine. Figure 4 is a flowchart of the key code matching subroutine. 6.2 Coding switch program design







a.JPG









b.JPG
c.JPG







As can be seen from Figure 1, pins 1 and 2 are both high at the same time. If pin 2 reaches a high level before pin 1, it indicates left rotation. If pin 1 reaches a high level before pin 2, it indicates right rotation. When programming, you can judge the status of pins 1 and 2 based on this feature. Take pin 1 connected to P4.0 and pin 2 connected to P4.1 as an example:
d.JPG
6.3 Analog-to-digital conversion software design
Start the A/D conversion by setting the A/D conversion start mode selection bit of ADCOCN bits 3~2 (ADOCM1~O) of the ADCO control register: when bits 3~2 are 00, write 1 to ADOBUSY (ADCOCN bit 4) to start the A/D conversion; when bits 3~2 are 01, timer 3 overflows to start the A/D conversion; when bits 3~2 are 10, CNVSTR rising edge starts the A/D conversion; when bits 3~2 are 11, timer 2 overflows to start the A/D conversion. This design uses the first start mode. Since the workload of the microcontroller is not large, the query method is used in software design. The single-chip microcomputer constantly queries the status of the keyboard, encoding switch and potentiometer. If there is a change, the single-chip microcomputer will pass the action information to the ARM main MCU and wait for the main MCU to process. Since the analog-to-digital conversion speed of the single-chip microcomputer is very fast, a delay is added to the program in order to observe the change in the analog-to-digital conversion. In addition, filtering was not considered during the hardware design, so the filtering was implemented by software. General filtering methods include limited amplitude filtering, mid-position filtering, arithmetic mean filtering, etc. A new filtering method is now proposed. Since a 12-bit A/D is used, but only 8 bits are needed to achieve the desired accuracy, the method of removing the lower 4 bits can be used to achieve the purpose of filtering. Due to limited space, only part of the program is given below, taking AIN0 as an example:
e.JPG

f.JPG

Conclusion
The one-button multi-meaning key management program introduced in this article can be used for multi-button intelligent instruments. The programming method of the coding switch is simple and easy to understand. In the A/D conversion part, the proposed software filtering method of removing the lower 4 bits is reliable and feasible, and is very suitable for occasions where the accuracy requirement is not high. These three parts constitute a complete monitoring program. When the microcontroller monitors a change in a certain part, it transmits its action information to the ARM main CPU, and the main CPU performs corresponding processing.


Keywords:MCU Reference address:Design of Oscilloscope Monitoring Program for C8051F

Previous article:Design of vehicle-mounted digital video compression recording system based on LPC2210 and SZ1510
Next article:Design of TFT LCD display based on 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-17 00:56

Detailed explanation of the working principle of P0 port of 51 single chip microcomputer
Three-state gate: Three-state gate buffer: 51 MCU P0 port input buffer Output drive of P0 port: push-pull structure composed of two MOS tubes When P0 port is used as IO line input state: ① read pin; ② read latch; P0 port is used as address/data multiplexing port When the P0 port is used as an IO line output,
[Microcontroller]
Detailed explanation of the working principle of P0 port of 51 single chip microcomputer
Microcontroller Basics: Differences among data, idata, xdata, pdata, and code in Keil
Many MCU beginners and even some experienced engineers have never understood what data, idata, xdata, pdata, and code are. Recently, I saw an article about the problems of data, idata, xdata, pdata, and code in Keil, and I would like to share it with you. In terms of data storage type, the 8051 series has on-chip an
[Microcontroller]
STC12C5604AD voltage alarm detection module schematic diagram and MCU source program
Voltage detection module Circuit diagram: 【A brief description】 Dimensions: Length 88mmX Width 45mmX Height 15mm 2. Main chip: STC12C5604AD 3. Working voltage: DC 12V Features: 1. Detection analog voltage range 0~10V (range can be expanded according to customer needs) 2. Digital tube display range 0~9.999 3. Four-
[Microcontroller]
STC12C5604AD voltage alarm detection module schematic diagram and MCU source program
Write a single-chip counter program to count pulses
Write a program with the following functional requirements: when the level of the P1.0 pin changes positively, count the input pulses of P1.1; when the level of the P1.2 pin changes negatively, stop counting and write the count value into R0 and R1 (the high bit is stored in R1 and the low bit is stored in R0). Answer
[Microcontroller]
51 MCU implements multiple software timers based on one timer
A software timer is a timer simulated by a program. One hardware timer can simulate thousands of software timers, so that when the program needs to use more timers, it will not be limited by the lack of hardware resources. This is an advantage of software timers, that is, the number is unlimited. However, since the so
[Microcontroller]
51 MCU implements multiple software timers based on one timer
Precautions for welding of MCU learning board
Pay attention to the following points during the welding process: 1. Pay attention to the positive and negative polarity of electrolytic capacitors, light-emitting diodes, and buzzers. The long pins of the three are connected to the positive pole and the short pins are connected to the negative pole. If they are conne
[Microcontroller]
How to use the AT89S51 watchdog function
  In the initialization of the program, first write 01EH and then write 0E1H to the watchdog register (WDTRST address is 0A6H). This activates the watchdog.     ORG 0000H      LJMP begin Begin:     MOV 0A6H,#01EH ;Send 1E first     MOV 0A6H,#0E1H ;Send E1 later     ;Activate the watchdog in program initialization
[Microcontroller]
Design of coding, decoding and display experimental circuit based on 51 single chip microcomputer
0 Introduction In daily digital logic circuit experiments, the coding, decoding and display experimental circuit is a comprehensive application of the three circuits of coding, decoding and display. It plays an important role in the digital logic experimental circuit. During the experiment, the display result of
[Microcontroller]
Design of coding, decoding and display experimental circuit based on 51 single chip microcomputer
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号