The most suitable for novice beginners single-chip computer 40 experiments free download

Source: Internet
Author: User

The most suitable for novice beginners single-chip computer 40 experiments free download

For beginners single-chip microcomputer 40 experiments, with source code, need information of Dabigatran: 813238832
You can also go to the Network Technology forum to download more about the microcontroller, MTK information and learning cases

Analog Switch Lights

1. Experimental tasks
As shown in 4.2.1, the monitoring switch K1 (on the P3.0 port), with a light-emitting diode L1 (connected to the microcontroller P1.0 port) display the switch state, if the switch closed, L1 bright, switch on, L1 off.

2. Schematic diagram of the circuit

Figure A

More information in the break Web download link: https://bbs.usoftchina.com/thread-200737-1-1.html

3. Hardware connection on the system board
(1). Connecting the P1.0 port in the "MCU system" area to the L1 port in the "Eight LED indicator module" area;
(2). Connecting the P3.0 port in the "MCU system" area to the K1 port in the "Quad Toggle Switch" area;

4. Programming content
(1). Detection process of switching state
Single-chip microcomputer for switching state detection relative to the microcontroller, is from the microcontroller P3.0 port input signal, and input signal only high and low level two, when the Switch K1 dial up, that is, the input high level, quite switch off, when the toggle switch K1 dial down, that is, the input low level, quite switch closed. Single-chip microcomputer can be used JB Bit,rel or JNB Bit,rel instructions to complete the switch state detection can be.
(2). Output control
3, when the P1.0 port output high, that is, p1.0=1, according to the unidirectional conductivity of the light-emitting diode, then the light-emitting diode L1 off, when the P1.0 port output low, that is p1.0=0, the light emitting diode L1 bright; we can use SETB The P1.0 instruction causes the P1.0 port to output high, using the CLR P1.0 directives to make the P1.0 port output low.

5. Program Block diagram

Figure II

6. Assembler source program ORG 00H
START:JB P3.0,lig
CLR P1.0
SJMP START
Lig:setb P1.0
SJMP START
END

7. C Language Source program
#include <at89x51. H>
Sbit k1=p3^0;
Sbit l1=p1^0;
void Main (void)
{
while (1)
{
if (k1==0)
{
l1=0; Light on
}
Else
{
L1=1; Light off
}
}
}

3. Multi-switch status indication

1. Experimental tasks
As shown in 4.3.1, the AT89S51 microcontroller p1.0-p1.3 four LEDs l1-l4,p1.4-p1.7 connected to four switch k1-k4, programmed to reflect the state of the switch to the light emitting diode. (the switch is closed, the corresponding light is on, the switch is off, the corresponding lamp is off).

2. Schematic diagram of the circuit

Might

3. Hardware connection on the system board
(1. Connecting the p1.0-p1.3 in the "MCU system" area to the L1-l4 port in the "Eight LED indicator module" area;
(2. Connecting the p1.4-p1.7 in the "MCU system" area to the K1-k4 port in the "Quad Toggle Switch" area;

4. Programming content
(1. Switching condition Detection
For switching state detection, relative to single-chip microcomputer, is the input relationship, we can take turns to detect each switch state, according to the status of each switch to let the corresponding light-emitting diode indication, can be used JB P1. X,rel or JNB P1. X,rel command to complete, you can also detect the four-way switch state, and then let it indicate that you can use the Mov a,p1 command to read the status of the P1 port all at once, and then take a high 4-bit state to indicate.
(2. Output control
According to the state of the switch, led L1-L4 to indicate that we can use SETB P1. X and CLR P1. x instruction to complete, you can also use the Mov P1,#1111xxxxb method once instructed.

5. Program Block diagram

Figure Four

6. Read P1 port data into ACC
ACC content shifted right 4 times
ACC content and f0h phase or
ACC content fed into P1 port
<! [endif]-->
Figure 4.3.2
6. Method One (assembler source program)
ORG 00H
Start:mov A,P1
ANL A, #0F0H
RR A
RR A
RR A
RR A
ORl A, #0F0H
MOV P1,a
SJMP START
END

7. Method One (C language source program)
#include <at89x51. H>
unsigned char temp;
void Main (void)
{
while (1)
{
temp=p1>>4;
Temp=temp | 0xf0
P1=temp;
}
}

8. Method Two (assembler source program)
ORG 00H
START:JB P1.4,next1
CLR P1.0
SJMP NEX1
Next1:setb P1.0
NEX1:JB p1.5,next2
CLR P1.1
SJMP NEX2
Next2:setb P1.1
NEX2:JB P1.6,NEXT3
CLR P1.2
SJMP NEX3
Next3:setb P1.2
NEX3:JB P1.7,NEXT4
CLR P1.3
SJMP NEX4
Next4:setb P1.3
NEX4:SJMP START
END

9. Method Two (C language source program)
#include <at89x51. H>
void Main (void)
{
while (1)
{
if (p1_4==0)
{
p1_0=0;
}
Else
{
P1_0=1;
}
if (p1_5==0)
{
p1_1=0;
}
Else
{
P1_1=1;
}
if (p1_6==0)
{
p1_2=0;
}
Else
{
P1_2=1;
}
if (p1_7==0)
{
p1_3=0;
}
Else
{
P1_3=1;
}
}
}

The most suitable for novice beginners single-chip computer 40 experiments free download

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.