TQ210 bare metal programming - key lighting (Part 2)

Publisher:mancozcLatest update time:2020-12-18 Source: eefocusKeywords:TQ210 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Today, we use the interrupt method to program the button lighting of the TQ210 bare machine.


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

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

 

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

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

 

#define EXT_INT_0_CON *((volatile unsigned int *)0xE0200E00)

#define EXT_INT_0_MASK *((volatile unsigned int *)0xE0200F00)

 

#define VIC0INTSELECT *((volatile unsigned int *)0xF200000C)

#define VIC0INTENABLE *((volatile unsigned int *)0xF2000010)

 

#define VIC0VECTADDR0 *((volatile unsigned int *)0xF2000100)

#define VIC0VECTADDR1 *((volatile unsigned int *)0xF2000104)

 

#define VIC0ADDRESS  *((volatile unsigned int *)0xF2000F00)

 

#define EXT_INT_0_PEND *((volatile unsigned int *)0xE0200F40)

 

extern void key_isr(void);

 

void key_handle()

{

volatile unsigned char key_code = EXT_INT_0_PEND & 0x3;

VIC0ADDRESS = 0; /* Clear interrupt vector register */

EXT_INT_0_PEND |= 3; /* Clear interrupt pending register*/

if (key_code == 1) /* key1 */

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

else if (key_code == 2) /* key2 */

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

}

 

int main()

{

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

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

GPH0CON |= 0xFF << 0; /* Configure GPH0_0 and GPH0_1 as external interrupts: key1 and key2 */

EXT_INT_0_CON &= ~(0xFF << 0);

EXT_INT_0_CON |= 2 | (2 << 4); /* Configure EXT_INT[0] and EXT_INT[1] as falling edge trigger*/

EXT_INT_0_MASK &= ~3; /* Unmask external interrupts EXT_INT[0] and EXT_INT[1] */

VIC0INTSELECT &= ~3; /* Select external interrupt EXT_INT[0] and external interrupt EXT_INT[1] as IRQ type interrupt*/

VIC0INTENABLE |= 3; /* Enable external interrupts EXT_INT[0] and EXT_INT[1] */

VIC0VECTADDR0 = (int)key_isr; /* When EXT_INT[0] triggers an interrupt, that is, when the user presses key1,

The CPU will automatically assign the value of VIC0VECTADDR0 to VIC0ADDRESS and jump to this address to execute */

VIC0VECTADDR1 = (int)key_isr;

while (1);

return 0;

}

Keywords:TQ210 Reference address:TQ210 bare metal programming - key lighting (Part 2)

Previous article:TQ210 bare metal programming (3) - keystroke (query method)
Next article:TQ210 bare metal programming (8) - PWM

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号