Control IO port operation by buttons

Publisher:CuriousObserverLatest update time:2015-06-15 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Today, we have a certain understanding of the microcontroller keys. Microcontrollers are divided into stand-alone keyboards and matrix keyboards. The stand-alone type occupies more IO port resources and is suitable for control operations with fewer keys. Its advantage is that the design and programming are clear at a glance and relatively simple. The matrix type occupies fewer IO ports and is suitable for operations that have high requirements for keys and where IO port resources are relatively precious. The two have their own advantages and disadvantages. In future applications, they must be designed according to needs, especially the matrix type must use the high and low level detection of row and column lines and the principle of processing data information must be remembered.
 
Below I will write a simple program that I learned today to control the operation of the IO port LED light through buttons. Haha, it can deepen my understanding of button operation (ELSE statement).
 
#include
#define uint unsigned int
#define uchar unsigned char
sbit DIPswitch1=P3^0;
sbit DIPswitch2=P3^1;
sbit redLED1=P1^0;
sbit blueLED1=P1^1;
sbit greenLED1=P1^2;
sbit yellowLED1=P1^3;
sbit redLED2=P1^4;
sbit blueLED2=P1^5;
sbit greenLED2=P1^6;
sbit yellowLED2=P1^7;
void delay(void)
{ uint i;
 for(i=0;i<35530;i++);
}
void main(void)
{
  P1=0XFF;
  P3=0XFF; //Set
 while(1)
 {
  if(DIPswitch1==0)
  {
  redLED1=~redLED1;
  yellowLED2=~yellowLED2; //Judge whether button 1 is at a low level. If so, implement bitwise inversion of pins 1 and 7 of port P0
  delay();}//delay operation
  else if(DIPswitch2==0)
  {
  P1=~P1; //When button 2 is low, all bits of port P0 are inverted and flash
  }
  else
  {
  P1=0X00; //If both buttons 1 and VS2 are high, all lights will be on
  }
  
 }
}
 
The working principle is that when button 1 is at a low level, pins 1 and 7 of P1 port are bitwise inverted to realize the flashing of LED lights. When button 2 is at a low level, all lights of P1 port realize the bitwise inversion function and all lights flash. When buttons 1 and 2 are both at a high level, P1 port is at a low level and all lights are on.
 
This hardware circuit is that P3^0 and P3^1 control buttons 1 and 2; P1 port controls eight LED lights.
 
Haha, I am still learning the dynamic and static control of digital tubes. Now I should be able to master the basic static control, and I will try to finish learning the dynamic control in the next two days. Come on.
Due to time constraints, I will not write about the working system of the microcontroller here.
Reference address:Control IO port operation by buttons

Previous article:Only two I/O pins of the microcontroller are needed to connect the digital keyboard circuit
Next article:NRF9E51 reads the IC card number and transmits the read data

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号