TQ210 bare metal programming (3) - keystroke (query method)

Publisher:大酉幽华1Latest update time:2020-12-18 Source: elecfansKeywords:TQ210 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First, check the bottom board schematic diagram of TQ210


This time, only KEY1 and KEY2 are operated. Search for XEINT0 in the TQ210 core board schematic diagram.

It can be seen that KEY1 and KEY2 are connected to the GPH0_0 and GPH0_1 pins of S5PV210 respectively.

This programming uses the query method. You need to set these two pins to input mode, and then read the pin status in a loop. When the user presses the button, the corresponding pin is at a low level and the LED status changes.


View S5PV210 chip manual

start.S

.global _start @Declare a global label

_start:

bl main @jump to C function to execute

halt:

b halt @Dead loop


key.c


 


 


#define GPC0CON *((volatile unsigned int *)0xE0200060)

#define GPC0DAT *((volatile unsigned int *)0xE0200064)

 

#define GPH0CON *((volatile unsigned int *)0xE0200C00)

#define GPH0DAT *((volatile unsigned int *)0xE0200C04)

 

void delay(volatile unsigned int t)

{

volatile unsigned int t2 = 0xFFFF;

while (t--)

for (; t2; t2--);

}

 

int main()

{

int key_val = 0;

int bit;

GPC0CON &= ~(0xFF << 12);

GPC0CON |= 0x11 << 12; // Configure GPC0_3 and GPC0_4 as outputs: LED1 and LED2

GPH0CON &= ~(0xFF << 0); // Configure GPH0_0 and GPH0_1 as input: key1 and key2

while (1)

{

key_val = GPH0DAT & 0x3;

if (key_val)

{

delay(500000); // Anti-shake delay

key_val = GPH0DAT & 0x3;

if (key_val)

{

if (0x01 == key_val) // key1

GPC0DAT ^= 1 << 3; // toggle LED1

else if (0x02 == key_val) // key2

GPC0DAT ^= 1 << 4; // toggle LED2

}

}

}

return 0;

}


Makefile


key.bin: start.o key.o

arm-linux-ld -Ttext 0x20000000 -o key.elf $^

arm-linux-objcopy -O binary key.elf $@

arm-linux-objdump -D key.elf > key.dis

key.o : key.c

arm-linux-gcc -c $< -o $@

start.o : start.S

arm-linux-gcc -c $< -o $@

clean:

rm *.o *.elf *.bin *.dis


For the download method, please refer to "TQ210 Bare Metal Programming (1) - Lighting up an LED"


After downloading the program:


Press key1, LED1 lights up, press key1 again, LED1 turns off


Press key2, LED2 lights up, press key2 again, LED2 turns off

Keywords:TQ210 Reference address:TQ210 bare metal programming (3) - keystroke (query method)

Previous article:S5PV210 (TQ210) study notes - 8-bit HWECC and YAFFS2 OOB layout
Next article:TQ210 bare metal programming - key lighting (Part 2)

Latest Microcontroller Articles
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号