下面部分从TXT拷出,拷到网页,代码部分缺省了很多空格,比较凌乱,请谅解!
//目标系统: 基于AVR单片机
//应用软件: ICC AVR
/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
实验内容:
循环扫描PA口接入的按键,并使用PB口的LED指示灯指示按键的码值。
----------------------------------------------------------------------
硬件连接:
将PB口的LED指示灯使能开关切换到"ON"状态,使其指示按键的码值。
LinkKeyBoard: K0----K7
| |
SMK1632: PA0--PA7
----------------------------------------------------------------------
注意事项:
(1)若有加载库程序,请将光盘根目录下的“库程序”下的“ICC_H”文件夹拷到D盘
(2)请详细阅读:光盘根目录下的“产品资料\开发板实验板\SMK系列\SMK1632\说明资料”
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
#include <iom16v.h>
#include "D:\ICC_H\CmmICC.H"
#define LED_DDR DDRB
#define LED_PORT PORTB
#define KEY_DDR DDRA
#define KEY_PORT PORTA
#define KEY_PIN PINA
/*--------------------------------------------------------------------
程序名称:链式按键扫描程序
程序功能:键盘检测
注意事项:
提示说明:
输 入:
返 回:
--------------------------------------------------------------------*/
void scanKey()
{
KEY_DDR = 0X01;
KEY_PORT = 0xFE;
delay50us(1);
if(KEY_PIN==0xFC)
LED_PORT=0x01;
if(KEY_PIN==0xFA)
LED_PORT=0x02;
if(KEY_PIN==0xF6)
LED_PORT=0x03;
if(KEY_PIN==0xEE)
LED_PORT=0x04;
if(KEY_PIN==0xDE)
LED_PORT=0x05;
if(KEY_PIN==0xBE)
LED_PORT=0x06;
if(KEY_PIN==0x7E)
LED_PORT=0x07;
KEY_DDR = 0X02;
KEY_PORT = 0xFD;
delay50us(1);
if(KEY_PIN==0xF9)
LED_PORT=0x08;
if(KEY_PIN==0xF5)
LED_PORT=0x09;
if(KEY_PIN==0xED)
LED_PORT=0x0A;
if(KEY_PIN==0xDD)
LED_PORT=0x0B;
if(KEY_PIN==0xBD)
LED_PORT=0x0C;
if(KEY_PIN==0x7D)
LED_PORT=0x0D;
KEY_DDR = 0X04;
KEY_PORT = 0xFB;
delay50us(1);
if(KEY_PIN==0xF3)
LED_PORT=0x0E;
if(KEY_PIN==0xEB)
LED_PORT=0x10;
if(KEY_PIN==0xDB)
LED_PORT=0x11;
if(KEY_PIN==0xBB)
LED_PORT=0x12;
if(KEY_PIN==0x7B)
LED_PORT=0x13;
KEY_DDR = 0X08;
KEY_PORT = 0xF7;
delay50us(1);
if(KEY_PIN==0xE7)
LED_PORT=0x14;
if(KEY_PIN==0xD7)
LED_PORT=0x15;
if(KEY_PIN==0xB7)
LED_PORT=0x16;
if(KEY_PIN==0x77)
LED_PORT=0x17;
KEY_DDR = 0X10;
KEY_PORT = 0xEF;
delay50us(1);
if(KEY_PIN==0xCF)
LED_PORT=0x18;
if(KEY_PIN==0xAF)
LED_PORT=0x19;
if(KEY_PIN==0x6F)
LED_PORT=0x1A;
KEY_DDR = 0X20;
KEY_PORT = 0xDF;
delay50us(1);
if(KEY_PIN==0x9F)
LED_PORT=0x1B;
if(KEY_PIN==0x5F)
LED_PORT=0x1C;
KEY_DDR = 0X40;
KEY_PORT = 0xBF;
delay50us(1);
if(KEY_PIN==0x3F)
LED_PORT=0x1D;
}
/*--------------------------------------------------------------------
程序名称:
程序功能:
注意事项:
提示说明:
输 入:
返 回:
--------------------------------------------------------------------*/
void main()
{
LED_DDR = 0XFF;
while(1)
scanKey();
}