Button-LED

Publisher:草木知秋Latest update time:2019-09-16 Source: eefocusKeywords:Button  LED  s3c24xx Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Use the IO port query method to realize the key control of the LED's light on and off

#include "s3c24xx.h"

 

#define LED_ON 0

#define LED_OFF 1

 

#define KEY1_POS (0) //The position of key 1 on the IO port. Here it is GPF0 port, so the value is 0

 

#define KEY2_POS (2) //The position of key 2 in the IO port, here is GPF2 port, the value is

#define KEY3_POS (3)//GPG3   EINT11

 

#define LED1_POS (1<<4) //The position of LED1 in the IO port, here is GPF4 port, so the value is 4

#define LED2_POS (1<<5) //LED2 is located at the IO port, here is GPF5 port, the value is

#define LED3_POS (1<<6)     //GPF6

 

 

 

//Software related, not related to hardware buffe

#define OFS_KEY1 (0) //The state of key 1 is saved in the variable, here it is saved in the 0th position of the variable

#define OFS_KEY2 (1)// 

#define OFS_KEY3 (2)

 

#define GPF4_out (1<<(4*2)) //Set the 8th and 9th bits of GPFCON, that is, set the GPF4 bit output

#define GPF5_out (1<<(5*2)) //Set the 10th and 11th bits of GPFCON, that is, set the GPF5 bit output

#define GPF6_out (1<<(6*2)) //Set the 12th and 13th bits of GPFCON, that is, set the GPF6 bit output

#define GPF7_out (1<<(7*2))

 

#define hrdReadKey1 ((GPFDAT>>KEY1_POS)&0X01) //Read the status of key 1 

#define hrdReadKey2 ((GPFDAT>>KEY2_POS)&0X01) //Read the status of key 2 

#define hrdReadKey3 ((GPGDAT>>KEY3_POS)&0X01) //Read the status of key 2

 

 

#define hrdLed1On (GPFDAT &= (~LED1_POS)) // Make GPF4 output 0

#define hrdLed1Off (GPFDAT |= (LED1_POS)) // Make GPF4 output 1

#define hrdLed2On (GPFDAT &= (~LED2_POS)) // Make GPF5 output 0

#define hrdLed2Off (GPFDAT |= (LED2_POS)) // Make GPF5 output 1

#define hrdLed3On (GPGDAT &= (~LED3_POS)) // Make GPG6 output 0

#define hrdLed3Off (GPGDAT |= (LED3_POS)) // Make GPG6 output 1

 

 

 

typedef union

{

unsigned long byte;

struct

{

unsigned long key1 :1;

unsigned long key2 :1;

unsigned long key3 :1;

unsigned long notused :5;

}bits;

}mmiFlag_t;

 

mmiFlag_t mmiFlag;

 

#define mmiFlag_Key1 mmiFlag.bits.key1 //Judge whether it is the first time to process after the key is pressed

 

#define mmiFlag_Key2 mmiFlag.bits.key2 //Judge whether it is the first time to process after the key is pressed

#define mmiFlag_Key3 mmiFlag.bits.key3 //Judge whether it is the first time to process after the key is pressed

 

typedef union

{

unsigned long byte;

struct

{

unsigned long led1 :1;

unsigned long led2 :1;

unsigned long led3 :1;

unsigned long notused :5;

}bits;

}ledStatus_t;

ledStatus_t ledStatus;

#define led1Status    ledStatus.bits.led1

#define led2Status    ledStatus.bits.led2

#define led3Status ledStatus.bits.led3

 

 

 

 

volatile unsigned long dgtInBuf=1; //Save the switch input status

volatile unsigned long dgtInPre; //Pre-store switch input status

volatile unsigned long dgtCount; //delay count of switch input

 

 

 

 

 

 

 

// Initialize IO port

void ioInitialize_IO(void)

{

GPFCON |= GPF4_out; // Set GPF4, GPF5, GPF6 as output ports, bit [9:8] = 0b01

GPFCON &=(~GPF5_out);

GPFCON |= GPF5_out;

GPFCON |= GPF6_out;  

  GPFDAT = 0x00000000; //GPF4 outputs 0, LED1 lights up

}

 

 

 

 

 

//Refresh the IO port, read or write the IO port operation here

void ioRefresh_IO(void)

{

unsigned long buf=0;

if(hrdReadKey1==0) //Read the input status of key 1

buf |= (1< else if(hrdReadKey2==0)

buf |=  (1< else if(hrdReadKey3==0)

buf |=  (1< dgtInBuf = buf; //Save the read key status to dgtInBuf

}

/*Delay*/

void wait(unsigned long dly)

{

for(;dly>0;dly--);

}

/*

    *******************************Key processing function*********************************************

    This is achieved by querying the IO port, not interrupting it.

*/

void mmiProcess_Key1(void)

{

//mmiFlag_Key1 determines whether the key is pressed for the first time, and does not determine whether it is pressed next time until it is released

if((dgtInBuf&(1< {

mmiFlag_Key1 = 1; //The flag is set to 1 to prevent the key from being released and entering this judgment body again

if(led1Status==0) ​​//LED light status flip

{

led1Status = 1;

hrdLed1Off;

}

else

{

led1Status = 0;

hrdLed1On;

}

}

else if((dgtInBuf&(1< {

mmiFlag_Key1 = 0; //Set the flag to 0 and wait for the next key press

}

}

 

void mmiProcess_Key2(void)

{

//mmiFlag_Key2 determines whether the key is pressed for the first time, and does not determine whether it is pressed next time until it is released

if((dgtInBuf&(1< {

mmiFlag_Key2 = 1; //The flag is set to 1 to prevent the key from being released and entering this judgment body again

if(led2Status==0) ​​//LED light status flip

{

led2Status = 1;

hrdLed2Off;

}

else

{

led2Status = 0;

hrdLed2On;

}

}

else if((dgtInBuf&(1< {

mmiFlag_Key2 = 0; //Set the flag to 0 and wait for the next key press

}

}

 

 

void mmiProcess_Key3(void)

{

//mmiFlag_Key3 determines whether the key is pressed for the first time, and does not determine whether it is pressed next time until it is released

if((dgtInBuf&(1< {

mmiFlag_Key3 = 1; //The flag is set to 1 to prevent the key from being released and entering this judgment body again

if(led3Status==0) ​​//LED light status flip

{

led3Status = 1;

hrdLed3Off;

}

else

{

led3Status = 0;

hrdLed3On;

}

}

else if((dgtInBuf&(1< {

mmiFlag_Key3 = 0; //Set the flag to 0 and wait for the next key press

}

}

 

 

 

 

 

 

 

 

 

 

void mmiHandle_MMI(void)

{

if(dgtInBuf!=dgtInPre)//Judge whether the key input status is consistent with the last time

{

dgtInPre = dgtInBuf; //Assign this state to the Pre variable

dgtCount = 0; //Count cleared to 0

}

else //If the key input status is the same as last time

{

dgtCount++; // count plus 1

if(dgtCount>=5) //A delay of 5*1ms=5ms is performed. If the status is consistent for 5 times in a row, the input is considered valid.

{

dgtCount = 0;

mmiProcess_Key1();

mmiProcess_Key2();

mmiProcess_Key3();

}

}

}

int main()

{

ioInitialize_IO();

for(;;)

{

wait(1000); // 1ms delay

ioRefresh_IO();

mmiHandle_MMI();

}

  return 0;

}

Keywords:Button  LED  s3c24xx Reference address:Button-LED

Previous article:LCD Driver-JZ2440
Next article:Driver-button-interrupt mode

Recommended ReadingLatest update time:2024-11-16 13:56

Typical drive solutions for three types of LED area lighting power supplies
  From the application field, LED lighting covers different categories such as residential lighting, industrial lighting, street lighting, and restaurant, retail and service lighting. From the power level point of view, in addition to low-power lighting, it also includes high-power area lighting, typical applications
[Power Management]
Typical drive solutions for three types of LED area lighting power supplies
LED chip flip chip process principle and development trend
The reason why the chip is called "flip chip" is relative to the traditional metal wire bonding connection method (WireBonding) and the process after ball implantation. The electrical surface of the traditional chip connected to the substrate by metal wire bonding faces up, while the electrical surface of the flip chi
[Power Management]
LED chip flip chip process principle and development trend
Analysis of radiation loss during LED use
  Commonly used single chip system RAM test method LED is called the fourth generation lighting source or green light source. It has the characteristics of energy saving, environmental protection, long life and small size. It can be widely used in various indications, displays, decorations, backlight sources, general
[Microcontroller]
Summary of the current main new LED cooling technologies
Currently, there are 6 main new LED heat dissipation technologies.    1. SynJet replacement fan   Applied to the heat dissipation of LED lighting , the general principle of SynJet is that a component similar to a vibrating membrane vibrates at a certain frequency to compress the air in the chamber. After the air i
[Power Management]
Summary of the current main new LED cooling technologies
Four protection circuit designs for LED power supply
In recent years, with the increasing maturity of LED technology, LED light sources have been increasingly widely used due to their advantages of using low-voltage power supply, low energy consumption, strong applicability, high stability, short response time, and multi-color luminescence. Most LED power supplies use s
[Power Management]
How to choose the right LED lamp? Lighting designers have a trick!
  The selection of lighting equipment is one of the important factors in the performance of lighting design results. With the innovation of lighting technology, LED lighting has developed rapidly. Some laboratories can update a new generation of products in one month. The main performance of LED in lighting is:
[Power Management]
Six advantages of high-power LED desk lamps
  Table lamps are a must-have in our daily lives. Almost all families have one. Placing a table lamp at the bedside can facilitate nighttime activities. In addition, the desk is also a place where you can often see it. With the continuous advancement of technology and the continuous improvement of people's living stan
[Power Management]
Processor design based on solar LED lighting control system
0 Introduction Solar energy is a clean green energy source, and semiconductor light emitting diodes (LEDs) are also an environmentally friendly, energy-saving, and efficient solid-state electric light source. Combining LED technology with solar technology to develop solar semiconductor lighting is the best
[Power Management]
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号