⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp3.txt

📁 基于单片机准双向I/O的键盘程序基于单片机准双向I/O的键盘程序
💻 TXT
字号:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.9 Evaluation
Automatic Program Generator
?Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 2007-5-14
Author  : Freeware, for evaluation and non-commercial use only
Company : 
Comments: 


Chip type           : ATmega16
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega16.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

int x=0;
unsigned char a;
unsigned char str1[4];
//unsigned char str2[]="R/Min"; 

void lcd(unsigned char g)
{
 str1[0]=g;              
 //lcd_gotoxy(x,0);
 lcd_puts(str1);
 //lcd_puts(str2); 
} 

unsigned char key_read(void)
{ unsigned char i,l=0; 
  //DDRA = 0x00;/*获取列地址*/ 
  DDRA = 0xF0;
  PORTA = 0x0F;  // 必须送2 次!!!
  PORTA = 0x0F;
  i = PINA&0x0f; 
  
  //DDRA = 0x00;/*获取行地址*/
  DDRA = 0x0F;
  PORTA = 0xF0;  // 必须送2 次!!!
  PORTA = 0xF0;
  l = PINA&0xf0; 
  
   a=i|l;
  switch (a) {/*将按键码转换成键值*/
  case  0x21: return '1';
  case  0x41: return '2';
  case  0x81: return '3';
  case  0x22: return '4';
  case  0x42: return '5';
  case  0x82: return '6';
  case  0x24: return '7';
  case  0x44: return '8';
  case  0x84: return '9';
  case  0x28: return '*';
  case  0x48: return '0';
  case  0x88: return '#';
  default : return 0x00;  }
}

#define key_input1 a// 按键输入口
#define key_state1_0 0
#define key_state1_1 1
#define key_state1_2 2
char read_key(void)
{
static char key_state1 = 0;
char key_press1, key_return1 = 0;
key_press1 = key_input1; // 读按键I/O 电平
switch (key_state1)
{
  case key_state1_0: // 按键初始态
    if (key_press1!=0) key_state1 = key_state1_1; // 键被按下,状态转换到键确认态
    break;
  case key_state1_1: // 按键确认态
    if (key_press1!=0)
     {  
       key_return1 = 1; // 按键仍按下,按键确认输出为“1”
       key_state1 = key_state1_2; // 状态转换到键释放态
     }
    else
       key_state1 = key_state1_0; // 按键已抬起,转换到按键初始态
    break;
  case key_state1_2:
    if (key_press1==0) key_state1 = key_state1_0; //按键已释放,转换到按键初始态
    break;
  }
return key_return1;
}


void main(void)
{
lcd_init(16);
PORTB=0x00;
DDRB=0xFF;  

while (1)
      {
        if(read_key())
         {
          if(++x>=32)
          {x=0;lcd_clear();} 
           lcd(key_read());
          }
       PORTB=key_read();
       
        
       }
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -