Preface -----

Because I want to participate in the electric competition, I came into contact with the STC89C52RC (A51) single-chip microcomputer 

 

 

STC89C52RC pin function  

1 power supply:
①VCC - chip power supply, connected to +5V; 
②VSS - ground terminal; 

2. Clock:  
XTAL1, XTAL2 - crystal oscillator circuit inverting input and output.  

3. Control line:  
There are 4 control lines: 
         ALE/PROG: address latch permission/on-chip EPROM programming pulse  
         ① ALE function: used to latch the lower 8-bit address sent by P0 port  
         ② PROG function: on-chip EPROM Chip, during EPROM programming, this pin inputs programming pulses. 
        PSEN: External ROM read strobe signal
        RST/VPD: reset/standby power supply. 
                 ① RST (Reset) function: Reset signal input terminal. 
                 ② VPD function: In the case of Vcc power failure, connect to the backup power supply. 
        EA/Vpp: internal and external ROM selection/on-chip EPROM programming power supply. 
             ① EA function: internal and external ROM selection terminal. 
             ② Vpp function: For chips with EPROM on-chip, the programming power supply Vpp is applied during EPROM programming. 

4. I/O port lines: P0, P1, P2, and P3 are four 8-bit ports.  
    Port P0 is a three-state bidirectional port, commonly known as a data bus port, because only this port can be directly used for read/write operations on external memory. Port 0 is also used to output the lower 8-bit map 1 address of the external memory. Since it is a time-sharing output, a latch should be added externally to latch the address data, the address is latched, and the signal uses ALE.  
     P1 port is an I/O port specially for users, and it is a quasi-two-way port.  
     The P2 port is used as the high 8-bit address line when the slave system is extended. When the external memory is not expanded, the P2 port can also be used as a user I/O port line, and the P2 port is also a quasi-bidirectional port.  
     Port P3 is a dual-function port, and each bit of this port can be independently defined as the first I/O function or the second I/O function. When used as the first function, the operation is the same as that of P1 port.

1. Marquee

 

 Use the program to control the output level of P20-P27 (0,1) to realize the cycle lighting of the LED module D1-D8 light-emitting diodes, and complete the marquee effect.

/*定义LED引脚*/
 #define LED P2

/*延迟函数*/
void Delay(unsigned int a)
{
	while(a--);
}

//流水灯
void Running()
{
	 u8 i;
	 LED = 0xfe;
	 Delay(50000);//大约延时450ms	
	 while(1)
	 {
		 for(i = 0;i<7;i++)
		 {
			 LED = _crol_(LED,1);	//左移一位  0xfe(11111110)--->0xfd(11111101)
			 Delay(50000);
		 }
		 for(i = 0;i<7;i++)
		 {
			 LED = _cror_(LED,1);	//右移一位  0x7f(01111111)--->0xbf(10111111)
			 Delay(50000);
		 }
	 }
}

Define the LED as pin P2, P2 is assigned a value of 0xfe, binary is 11111110, a total of eight bits are respectively for P27-P20, when the P20 pin is 0-low voltage, the light is on, and 1-high voltage is off. Cycle left, right and wait for 450ms to turn on the next one

2. Independent button to control the buzzer

 

 In the experimental version, there are 4 independent buttons k1-k4, respectively for the P30-33 pins of the STC80C51, when the button is pressed, the corresponding pin is grounded, that is, assigned a value of 0. Determine which of P30-P33 is 0 through the program, corresponding to the key press.

The BEEF of the buzzer is connected to the OUT5 pin of the wireless four-phase stepper motor ULN2003D, and the signal of this pin is affected by the P25 pin corresponding to IN5.

 /*定义蜂鸣器*/
 sbit BEEP = P2^5;

void C_buzzer()
{
		 while(1)
	 {
		 if(P31==0)//按下关闭
		 {
			 BEEP=1;
			 while(1)
			 {
				 if(P31==0)//当再次按下时,再次启动
				 {
					 break;
				 }
			 }
		 }
		 else
		 {
			 BEEP = ~BEEP;
			 Delay(50000);
		 }
	 }
}

Guess you like

Origin blog.csdn.net/m0_61598337/article/details/131465603