avr单片机基于ATmega16的4乘4矩阵按键驱动程序

上传人:飞*** 文档编号:35714574 上传时间:2018-03-19 格式:DOC 页数:3 大小:34KB
返回 下载 相关 举报
avr单片机基于ATmega16的4乘4矩阵按键驱动程序_第1页
第1页 / 共3页
avr单片机基于ATmega16的4乘4矩阵按键驱动程序_第2页
第2页 / 共3页
avr单片机基于ATmega16的4乘4矩阵按键驱动程序_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《avr单片机基于ATmega16的4乘4矩阵按键驱动程序》由会员分享,可在线阅读,更多相关《avr单片机基于ATmega16的4乘4矩阵按键驱动程序(3页珍藏版)》请在金锄头文库上搜索。

1、14*44*4 矩阵按键矩阵按键-控制数码管控制数码管 /ICC-AVR application builder : 2010-10-05 19:19:34 / Target : M16 / Crystal: 4.0000Mhz #include #include #define hang1 (PINA /16 表示无效键值 unsigned char xianshishuju8; /*CPU 器件初始化*/ void port_init(void) PORTA = 0xFF;DDRA = 0xF0;PORTB = 0x00;DDRB = 0xFF;PORTC = 0x00; /m103 ou

2、tput onlyDDRC = 0xFF;PORTD = 0xFF;DDRD = 0xFF; /call this routine to initialize all peripherals void init_devices(void) /stop errant interrupts until set upCLI(); /disable all interruptsport_init(); MCUCR = 0x00;GICR = 0x00;TIMSK = 0x00; /timer interrupt sourcesSEI(); /re-enable interrupts/all perip

3、herals are now initialized /*/ /*延时模块*/ void delay(unsigned int m) unsigned int i,j; for(i=0;im;i+)for(j=0;j570;j+); 2/*/ /*显示模块*/ unsigned char const duanma=0x3F,/*0*/0x06,/*1*/0x5B,/*2*/0x4F,/*3*/0x66,/*4*/0x6D,/*5*/0x7D,/*6*/0x07,/*7*/0x7F,/*8*/0x6F,/*9*/ ; void baweixianshi(void) unsigned char i

4、;for(i=0;i8;i+)PORTD=(BIT(i); PORTC=duanmaxianshishujui;delay(1);PORTC=0X00; /*/ /*键盘扫描模块*/ void keyscan(void) PORTA=0XEF;/高四位 1110 令第一列按键处于判断状态 低四位 1111 保持内部上拉 电阻 if(!hang1)key=0;if(!hang2)key=1;if(!hang3)key=2;if(!hang4)key=3; PORTB=key;PORTA=0XDF;/高四位 1101 令第二列按键处于判断状态 低四位 1111 保持内部上拉 电阻 if(!hang

5、1)key=4;if(!hang2)key=5;if(!hang3)key=6;if(!hang4)key=7; PORTB=key;PORTA=0XBF;/高四位 1011 令第三列按键处于判断状态 低四位 1111 保持内部上拉3电阻 if(!hang1)key=8;if(!hang2)key=9;if(!hang3)key=10;if(!hang4)key=11; PORTB=key;PORTA=0X7F;/高四位 0111 令第四列按键处于判断状态 低四位 1111 保持内部上拉 电阻 if(!hang1)key=12;if(!hang2)key=13;if(!hang3)key=14;if(!hang4)key=15; /*/ void main(void) init_devices();/insert your functional code here.while(1) keyscan();if(key10)xianshishuju7=key; baweixianshi();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 教育/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号