disable home key

 Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
   
   @Override
   public void run() {
    // TODO Auto-generated method stub
    getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
   }
  }, 300);
好的,这是一个比较典型的嵌入式系统应用,需要结合MSP430F6638的GPIO、LCD和Flash模块进行编程实现。下面是一个大致的代码框架: ```c #include <msp430.h> #include <stdint.h> #define KEY1 BIT0 #define KEY2 BIT1 #define LED BIT2 #define LCD_RS BIT3 #define LCD_E BIT4 #define LCD_DB4 BIT5 #define LCD_DB5 BIT6 #define LCD_DB6 BIT7 #define LCD_DB7 BIT8 #define CMD_CLEAR_LCD 0x01 #define CMD_RETURN_HOME 0x02 #define CMD_ENTRY_MODE_SET 0x04 #define CMD_DISPLAY_CONTROL 0x08 #define CMD_FUNCTION_SET 0x20 #define CMD_SET_CGRAM_ADDR 0x40 #define CMD_SET_DDRAM_ADDR 0x80 #define ENTRY_MODE_INCREMENT 0x02 #define ENTRY_MODE_SHIFT_CURSOR 0x00 #define DISPLAY_CONTROL_DISPLAY_ON 0x04 #define DISPLAY_CONTROL_CURSOR_ON 0x02 #define DISPLAY_CONTROL_BLINK_ON 0x01 #define FUNCTION_SET_8BIT_MODE 0x10 #define FUNCTION_SET_2LINE_MODE 0x08 #define FUNCTION_SET_FONT_5X8 0x00 #define FLASH_START_ADDR 0x1800 void lcd_write_nibble(uint8_t nibble, uint8_t rs); void lcd_write_byte(uint8_t byte, uint8_t rs); void lcd_init(); void lcd_clear(); void lcd_return_home(); void lcd_set_cursor(uint8_t row, uint8_t col); void lcd_write_char(char c); void lcd_write_string(const char* str); void delay_ms(unsigned int ms); void flash_write(uint16_t addr, uint8_t data); uint8_t flash_read(uint16_t addr); volatile uint8_t key1_pressed = 0; volatile uint8_t key2_pressed = 0; volatile uint8_t key2_released = 0; volatile uint16_t key1_count = 0; volatile uint16_t key2_count = 0; int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer PM5CTL0 &= ~LOCKLPM5; // disable high-impedance mode P1DIR |= LED; // set LED pin as output P1OUT &= ~LED; // turn off LED P1REN |= KEY1 | KEY2; // enable pull-up resistors on key pins P1IE |= KEY1 | KEY2; // enable interrupts on key pins P1IES |= KEY1 | KEY2; // trigger interrupt on falling edge P1IFG &= ~(KEY1 | KEY2); // clear interrupt flags on key pins lcd_init(); // initialize LCD lcd_clear(); // clear LCD screen delay_ms(10); // wait for LCD to stabilize lcd_write_string("Press Key1."); // display initial message __enable_interrupt(); // enable global interrupts while (1) { if (key1_pressed) { // handle Key1 press key1_pressed = 0; P1OUT ^= LED; // toggle LED key1_count++; // increment count lcd_set_cursor(1, 0); // set cursor to second line lcd_write_string("Key1: "); lcd_write_char(key1_count / 100 + '0'); // display count lcd_write_char((key1_count / 10) % 10 + '0'); lcd_write_char(key1_count % 10 + '0'); } if (key2_pressed) { // handle Key2 press key2_pressed = 0; key2_count = key1_count; // save count to flash flash_write(FLASH_START_ADDR, key2_count >> 8); flash_write(FLASH_START_ADDR + 1, key2_count & 0xFF); lcd_set_cursor(1, 0); // set cursor to second line lcd_write_string("Key2: Saved."); delay_ms(500); lcd_clear(); // clear LCD screen lcd_write_string("Press Key1."); // display initial message } if (key2_released) { // handle Key2 release key2_released = 0; uint16_t saved_count = (flash_read(FLASH_START_ADDR) << 8) | flash_read(FLASH_START_ADDR + 1); // read count from flash lcd_set_cursor(1, 0); // set cursor to second line lcd_write_string("Key2: "); lcd_write_char(saved_count / 100 + '0'); // display count lcd_write_char((saved_count / 10) % 10 + '0'); lcd_write_char(saved_count % 10 + '0'); } } } #pragma vector=PORT1_VECTOR __interrupt void PORT1_ISR() { if (P1IFG & KEY1) { // handle Key1 interrupt key1_pressed = 1; P1IFG &= ~KEY1; // clear interrupt flag } if (P1IFG & KEY2) { // handle Key2 interrupt if (P1IN & KEY2) { // handle Key2 release key2_released = 1; } else { // handle Key2 press key2_pressed = 1; } P1IFG &= ~KEY2; // clear interrupt flag } } void lcd_write_nibble(uint8_t nibble, uint8_t rs) { if (rs) { P1OUT |= LCD_RS; } else { P1OUT &= ~LCD_RS; } P1OUT &= ~(LCD_DB4 | LCD_DB5 | LCD_DB6 | LCD_DB7); P1OUT |= (nibble << 4) & (LCD_DB4 | LCD_DB5 | LCD_DB6 | LCD_DB7); P1OUT |= LCD_E; delay_ms(1); P1OUT &= ~LCD_E; delay_ms(1); } void lcd_write_byte(uint8_t byte, uint8_t rs) { lcd_write_nibble(byte >> 4, rs); lcd_write_nibble(byte & 0x0F, rs); } void lcd_init() { P1DIR |= LCD_RS | LCD_E | LCD_DB4 | LCD_DB5 | LCD_DB6 | LCD_DB7; delay_ms(50); lcd_write_nibble(0x03, 0); delay_ms(5); lcd_write_nibble(0x03, 0); delay_us(100); lcd_write_nibble(0x03, 0); delay_us(100); lcd_write_nibble(0x02, 0); lcd_write_byte(CMD_FUNCTION_SET | FUNCTION_SET_8BIT_MODE, 0); lcd_write_byte(CMD_DISPLAY_CONTROL | DISPLAY_CONTROL_DISPLAY_ON, 0); lcd_write_byte(CMD_ENTRY_MODE_SET | ENTRY_MODE_INCREMENT, 0); lcd_write_byte(CMD_CLEAR_LCD, 0); } void lcd_clear() { lcd_write_byte(CMD_CLEAR_LCD, 0); delay_ms(2); } void lcd_return_home() { lcd_write_byte(CMD_RETURN_HOME, 0); delay_ms(2); } void lcd_set_cursor(uint8_t row, uint8_t col) { uint8_t addr = col; if (row == 1) { addr += 0x40; } lcd_write_byte(CMD_SET_DDRAM_ADDR | addr, 0); } void lcd_write_char(char c) { lcd_write_byte(c, 1); } void lcd_write_string(const char* str) { while (*str) { lcd_write_char(*str++); } } void delay_ms(unsigned int ms) { __delay_cycles(1000 * ms); } void flash_write(uint16_t addr, uint8_t data) { FCTL3 = FWKEY; // unlock flash FCTL1 = FWKEY | WRT; // enable write mode *((uint8_t*)addr) = data; // write byte to flash FCTL1 = FWKEY; // disable write mode FCTL3 = FWKEY | LOCK; // lock flash } uint8_t flash_read(uint16_t addr) { return *((uint8_t*)addr); // read byte from flash } ``` 在这个代码框架中,我们首先定义了一些常量,例如按键、LED、LCD和Flash的引脚和指令,以及保存计数值的Flash地址。然后定义了一些函数,如LCD的基本操作函数、延时函数和Flash的读写函数。在`main()`函数中初始化各个模块,并进入主循环。主循环中,通过轮询的方式检查是否有按键按下或释放,并根据按键采取相应的操作。具体来说: - 当检测到Key1按下时,翻转LED并增加计数值,然后在LCD上显示计数值。 - 当检测到Key2按下时,将当前计数值保存到Flash中,并在LCD上显示“Saved.”的提示信息。 - 当检测到Key2释放时,从Flash中读取之前保存的计数值,并在LCD上显示该值。 在中断服务函数中,我们通过检查P1IFG寄存器来确定是哪个按键触发了中断,然后设置相应的标志位,在主循环中处理。 需要注意的是,LCD的初始化过程较为复杂,需要通过发送一系列指令来设置其工作模式和显示内容。在实际应用中,可能需要根据具体的LCD型号和接口来进行相应的修改。同时,Flash的写操作可能需要进行一些额外的保护,例如在写之前先擦除整个Flash扇区。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值