ARM7 lpc2148 GPIO key input test

Publisher:梦回归处Latest update time:2021-07-05 Source: eefocusKeywords:ARM7  lpc2148  GPIO Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction: In this experiment, after pressing a key, the relevant signal is transmitted to 74HC165 in parallel, and then transmitted to the processor in serial mode. The processor controls the buzzer by controlling the P0.22 port (MAT0.0).


In this experiment, after pressing a key, the relevant signal is transmitted to 74HC165 in parallel, and then transmitted to the processor in serial mode. The processor controls the buzzer by controlling the P0.22 port (MAT0.0).


#include


//Macro definition

#define SCLK 0x01<<24

#define SCK0 0x01<<4

#define MISO 0x01<<5

#define MOSI 0x01<<6

#define RCK 0x01<<7


void HC595_Init(void);

void WriteByte(unsigned char data);

void Write595(void);

void HC165_CS(char flag);

unsigned char Read165(void);

void Delayn(unsigned long n);

//595 extended interface data display cache

unsigned int HC595_DATA = 0xFFFFFFFF;

//Initialize 595 interface

void HC595_Init(void)

{

IO0DIR |= MOSI|RCK|SCK0;

IO1DIR |= SCLK;

IO1CLR |= SCLK;

IO0DIR |= RCK;

HC595_DATA = 0xFFFFFFFF; Write595();

}

//Write bytes

void WriteByte(unsigned char data)

{

unsigned char i;

//IO0CLR = RCK;

for(i=0;i<8;i++)

{

if(data&0x01) IO0SET=MOSI;

else IO0CLR=MOSI;

IO1SET=SCLK;

data>>=1;

IO1CLR=SCLK;

}

//IO0SET = RCK;

}

//Refresh 595 data

void Write595(void)

{

IO0CLR = RCK;

WriteByte(HC595_DATA&0xff);

WriteByte((HC595_DATA&0xff00)>>8);

WriteByte((HC595_DATA&0xff0000)>>16);

WriteByte((HC595_DATA&0xff000000)>>24);

IO0SET = RCK;

}

//165 chip select

void HC165_CS(char flag)

{

if(flag) ////CLK INH writes high level,

HC595_DATA &= ~(1<<1);

else

HC595_DATA |= (1<<1);

Write595();

}

//Read the data of 165

unsigned char Read165(void)

{

unsigned char RD=0,i;

HC165_CS(1); //

IO1CLR_bit.P1_25 = 1; //Write 1 to make the corresponding pin output low level, even if S/L (pin 1) gets low level, before the arm board receives data, the pin must be pulled low, the purpose is to load the data on the parallel data A--H into the internal register, which reflects the LOAD function

Delayn(10);

IO1SET_bit.P1_25 = 1; //Write 1 to make the corresponding pin output high level. Then, in the process of receiving data, the pin must be pulled high to enable the data in the register to be moved, so as to move the data from QH or QN' into the microcontroller. This reflects the SHIFT function.

for(i=0;i<8;i++)

{

RD <<= 1; //Shift left one bit

if(IO0PIN&MISO) //MISO0 is the serial data output by 74HC165. Check whether 74HC165 receives the data. If MISO0 is not 0, it means that the data is received.

RD |= 1; //Accept high position first

IO0SET=SCK0; //The clock is high, and the next data is shifted out on the rising edge (CE is allowed to change from low to high only when CP is high)

Delayn(10);

IO0CLR=SCK0; //Clock low level (We only need to pull down or raise a port of the arm processor, so that the data can be received step by step. Please remember that the rising edge is valid.)

}

HC165_CS(0);

return RD;

}

main()

{

PINSEL0=0x000000;

PINSEL1=0x000000; //All pins are connected to GPIO


unsigned char HC165_DATA;

IO1DIR_bit.P1_25 = 1;

IO1SET_bit.P1_25 = 1;

PINSEL0_bit.P0_5 = 0;

//IO0DIR_bit.P0_5 = 0; //HC165 input pin


IO0DIR=1<<22; //Buzzer control port is set to output, the rest are input

HC595_Init();


while(1)

{

HC165_DATA = Read165();

if((HC165_DATA&(1<<4))==0) IO0SET=1<<22; //When KEY2 is pressed, the buzzer sounds (see below for explanation)

else IO0CLR=1<<22; //Release KEY2, the buzzer stops beeping

}

}

//Delay cycle number

void Delayn(unsigned long n)

{

while(n--);


}


Final Notes:


Explanation of if((HC165_DATA&(1<<4))==0) IO0SET=1<<22 in the main function, 1<<4 makes the 4th bit become 1, there is a functional diagram in the 74HC165 data sheet:


 It can be seen that the peripheral pin corresponding to the 4th bit is 3. From the connection diagram of the 74HC165 in the first figure above, it can be found that it is connected to KEY INT2, so the corresponding key is KEY2.


The data transmission method of 74HC165 in the program needs to be studied. The reason why 74HC595 is used is that the board of Litian Electronics connects the chip select (165 CS) of 74HC165 to 595 during design, so 595 must be operated accordingly.

Keywords:ARM7  lpc2148  GPIO Reference address:ARM7 lpc2148 GPIO key input test

Previous article:Implementation of Bootloader in Embedded System
Next article:ARM architecture/features (processors)

Recommended ReadingLatest update time:2024-11-15 19:57

Explanation of problems caused by not understanding the STM32 GPIO mode
Today, when I was writing Flash programs, at the end, all the programs had been written and tested, and there were no problems. The next step was to organize the programs and encapsulate some functions by myself, which would facilitate my own transplantation in the future, but the problem appeared here. During the pac
[Microcontroller]
STM8S Self-study Notes-006 GPIO input: key input and key filtering
GPIO Input In "STM8S Self-study Notes-003 GPIO Output: Lighting up LEDs and Marquee Effects", we have set the GPIO of the LED to push-pull output mode, which is only one of the GPIO output functions. Similarly, GPIO has more than one input function. Floating input, no interrupt Pull-up input, no interrupt Floating i
[Microcontroller]
ARM7 Getting Started 2, Hello world program
   Main file code: /******************************************************************************/ /*  This file is part of the uVision/ARM development tools                    */ /*  Copyright KEIL ELEKTRONIK GmbH 2002-2004                                  */ /*************************************************
[Microcontroller]
ARM7 Getting Started 2, Hello world program
Interface Design between LCD and LPC2134 Based on T6963C
  0 Preface   As a commonly used display device, the liquid crystal module has the characteristics of low power consumption, rich display content, and flexible control. Among the medium-sized graphic liquid crystal display modules, the LCD module with built-in T6963C controller is currently a more commonly used buil
[Microcontroller]
Interface Design between LCD and LPC2134 Based on T6963C
STM32 learning record GPIO
The purpose of this study:  1. Learn the basic operations of STM32 chip GPIO  2. Re-encapsulate the relevant functions of GPIO for later development The GPIO schematic diagram of the development board is as follows  As shown in the figure, the LED is connected to PC0-PC7 of GPIOC. STM's GPIO has the following 8 modes
[Microcontroller]
Understanding GPIO_Init in STM32 library function
The configuration style of GPIO in STM32 is very different from that of the MCUs studied previously. It took me a long time to figure it out.   typedef enum { GPIO_Mode_AIN = 0x0,   GPIO_Mode_IN_FLOATING = 0x04,   GPIO_Mode_IPD = 0x28,   GPIO_Mode_IPU = 0x48,   GPIO_Mode_Out_OD = 0x14,   GPIO_Mode_Out_PP = 0x10,   GPI
[Microcontroller]
PIC reading notes 1: compile, link, GPIO initialization, 5V voltage compatibility
The book I borrowed from the library is "16-bit MCU C Language Programming Based on PIC24", published by People's Posts and Telecommunications Press. It is a very good book. After reading the book, I found that there are many parts that I have ignored and despised in my learning process, so I will record them one by on
[Microcontroller]
Networked Real-time Color Analysis Virtual Instrument Based on ARM7-VxWorks
The foundation of special light sources, color display and other industries is the restoration and transmission of color. In the field of optical metrology, it belongs to the category of light source photometry and colorimetry. Color coordinates and brightness factor are one of the main parameters. The performance of p
[Test Measurement]
Networked Real-time Color Analysis Virtual Instrument Based on ARM7-VxWorks
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号