当前位置:网站首页>Blue Bridge Cup single chip microcomputer (I) -- turn off peripherals and turn off led

Blue Bridge Cup single chip microcomputer (I) -- turn off peripherals and turn off led

2022-06-23 11:50:00 There is heavy snow in the South

Recently, I began to prepare for the Blue Bridge Cup SCM competition in September , I bought a development board and began to learn . I have studied before 51 Single chip microcomputer , Compared with CT107D MCU competition board V20,51 The operation of single chip microcomputer is indeed much simpler , But the principle is the same , Nothing has changed , Previous studies 51 I didn't take notes when I was , Now I want to look for my previous study notes , So now after learning, I will post my notes on my blog , By the way, add some of your own learning experience , It's convenient for you to find it later , If there is a mistake , Welcome to correct .
When you create a project , The chip I chose was STC15F2K60S2, Of course, you can choose AT89C51 or AT89C52, When our development board is powered on , Buzzer and LED It's all on by default , The buzzer sounds uncomfortable and noisy after listening to it for a long time , And the game often requires that the peripherals be turned off first , That is, turn off the buzzer and LED. Because of MCU IAP15F2K61S2 There are not many interfaces , And the single-chip operation also needs to use many functions , So here in the circuit we use 74HC573 The effect of latch on SCM P0 Mouth for buffering , When we need to use the corresponding functions , Open the corresponding latch , Input and output .
 Insert picture description here When enabling end Y4C For high voltage ,Q Output with D Input and change , Enable end Y4C Low power level , The output will be locked at the established data level .
Enable end Y4C The level of , Is through an input or not gate and 74HC138 Jointly controlled by the decoder . Here's the picture :
745 Insert picture description here
74HC02 Is an input or not gate , The principle is :
 Insert picture description here
Y4C The output is zero Y4,WR Take the value after first or then reverse ,WR The connection is GND, Is a low level ,Y4C To get a high level , Activate 74HC53 Latch ,Y4 It must be low level ,Y4 Again through 74HC138 The decoder implements , as follows :
 Insert picture description here
138 The decoder passes P27~P25 The level of the three input ports is controlled Y0 ~Y7 Output , When Y0 ~Y7 Either output is low , Is valid output .
such as ,Y4 Namely P27~ P25 by 100 Valid output of , Binary algorithm ,100 by 4, Again , If you want to make Y5 It works ,P27~ P25 The input of should be 101, By analogy . Please read the chip principle by yourself 74HC138 Chip data .
therefore , The circuit controls 138 Of the decoder P27~P25 To control the switch of each latch .
In the circuit schematic diagram , The buzzer is activated by Y5C This port is controlled by a latch , therefore , To operate the buzzer , The latch must be opened first Y5C,
 Insert picture description here

P2 = P2 & 0x1f | 0xa0; // First the P27~P25 Zero clearing , Then open the latch Y5C,

In the connecting circuit ,74HC573 The output of the Q I got one ULN2003,ULN2003 The function here is to negate , It is when we input high level , After this, the output is low level .
The buzzer is connected VCC, That's high level 1, All that needs to be transferred here is the low level 0, The buzzer will work , Will ring . We need to turn off the buzzer first , because ULN2003 The reaction of , When we don't need these peripherals , Just put this P0 Set the mouth to zero .

P2 = P2 & 0x1f | 0xa0; P0 = 0x00; // 1010 0000  Open the latch Y5C,  Turn off the buzzer 

Of course , When you need to turn on the buzzer , Reset the corresponding pin port 1 that will do . such as , Now you need to turn on the buzzer :

P2 = P2 & 0x1f | 0xa0; P0 = 0x40; // 1010 0000  Open the latch Y5C,  Turn off the buzzer 

As shown in the schematic diagram above ,P07~P00 It is controlled by hexadecimal code ,0000 0000, To turn on the buzzer , Is to P06 Set to high level , namely :0100 0000, therefore ,P0 The port is 0x40.

below , After turning off the buzzer , We need to shut down LED The lamp , close LED The principle of the lamp is the same as that of turning off the buzzer , Just open the corresponding latch , Carry out corresponding operations .
 Insert picture description here
adopt 138 The decoder and 74HC02 Enable end Y4C High level 1,LED Followed by VCC, So from P0 Port input low level 0,LED Light on , If high 1,LED The light goes out .

P2 = P2 & 0x1f | 0x80; P0 = 0xff; // 1000 0000  Open the latch Y4C,  close LED

control LED Eight pin ports of P07~P00, When all are extinguished :1111 1111 When you need to light a LED, Just set the corresponding pin port to zero ( Set to low level ) that will do . For example, it should be bright LED1, Namely :1111 1110 namely P0=0xfe.
my LED It will light up slightly at the beginning of closing , This phenomenon does not appear after other functions are added .
There may be many places in the text where the words are not particularly professional , There is a mistake .

原网站

版权声明
本文为[There is heavy snow in the South]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231137435260.html