Single chip microcomputer (AT89C51) peripheral I/O input and output experiment

Publisher:快乐奇迹Latest update time:2022-05-30 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Question Analysis

The main purpose is to connect 8 switches to the extended input port and 8 LEDs to the extended output port. How to control the display of 8 LEDs corresponding to 8 switches?


Other external chips are needed in the experiment


method one

Use 74LS373 and 74LS245 as external chips to complete the experiment


Experimental Circuit Diagram

Experiment Code

#include 

#include //define absolute address access

#define  uchar  unsigned  char

void delay(unsigned int n)

{

unsigned int i,j;

for(i=0;i   for(j=249;j>0;j--)

  ;

}

 

flying i;

void main(void)

{

    while(1)

{

i=XBYTE[0x7fff]; //Enter the switch information of the input port into i

delay(1); //delay program

XBYTE[0x7fff]= i; //Transfer the input switch information to the output address

}

}


The experimental code is not difficult to understand. It is to assign the button information of the input port (address 0x7fff) to i, and then transfer the data of the input port to the output port. The input port is connected to the button, and the output port is connected to the LED light. It is the same as the circuit diagram above.


Experimental Results

The LED light turns on and off corresponding to each button pressed.


Method Two

Use 8255 and 74LS373 as external chips to complete the experiment


Experimental Circuit Diagram

Experiment Code

#include 

#include     

#define  uchar  unsigned  char

flying i;


void delay(unsigned int n)

{

unsigned int i,j;

for(i=0;i   for(j=249;j>0;j--)

  ;

}

 

 

void  main (void) 

   while(1)

  {

   i= 0x90; //optional

  XBYTE[0xff7fc]= i; //optional

 

  i=XBYTE[0xff7c]; //Same as the above program

  delay(1); //Same as above program

  XBYTE[0xff7d]= i; //Same as the above program

  }

}


Experimental Results

The LED light turns on and off corresponding to each button pressed.


Summarize

The results of the I/O input and output experiment of the microcontroller (AT89C51) peripherals are relatively simple and clear, but it is mainly necessary to understand the experimental principles.

Keywords:MCU Reference address:Single chip microcomputer (AT89C51) peripheral I/O input and output experiment

Previous article:The single chip microcomputer (AT89C51) button controls the LED light to realize the running light and flashing running light
Next article:Serial communication experiment of single chip microcomputer (AT89C51)

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号