资源描述:
《avr控制矩阵键盘,12864显示简单计算器》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、AVR控制矩阵键盘,12864显示简单计算器#include#include#defineuintunsignedint#defineucharunsignedchar#defineRS_0(PORTA&=~BIT(7))#defineRS_1(PORTA
2、=BIT(7))#defineWR_0(PORTA&=~BIT(6))#defineWR_1(PORTA
3、=BIT(6))#defineEN_0(PORTA&=~BIT(5))#defineEN_1(PORTA
4、=BIT(5))uchartemp,key,num,i,n,s,k
5、=0,d,w,h,jj,chen,ch,m;uchard=0x81;ucharjia[]="+";ucharjian[]="-";ucharcheng[]="*";ucharchu[]="/";voiddelay(uintz){uinti,j;for(i=z;i>0;i--)for(j=114;j>0;j--);}ucharanjian(){uchari;ucharnum1;PORTB=0xef;//高出低入,先扫描行DDRB=0xf0;//按键00000000000if((PINB&0x01)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时
6、消抖if((PINB&0x01)==0)//确实有按键按下{n++;delay(1);//延时消抖key=0;write_data(0x30+key);while((!PINA&0X01));if(s==1){h++;}if(s!=1){w++;}//return0;//等待按键松开}}//按键1if((PINB&0x02)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x02)==0)//确实有按键按下{n++;delay(1);//延时消抖key=1;write_data(0x30+key);while((!PIN
7、A&0X02));//等待按键松开//return1;if(s==1){h++;}if(s!=1){w++;}}}//按键2if((PINB&0x04)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x04)==0)//确实有按键按下{n++;delay(1);//延时消抖key=2;write_data(0x30+key);while((!PINA&0X04));//等待按键松开//return2;if(s==1){h++;}if(s!=1){w++;}}}//按键3if((PINB&0x08)==0)//判断PA0
8、是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x08)==0)//确实有按键按下{n++;delay(1);//延时消抖key=3;write_data(0x30+key);while((!PINA&0X08));//等待按键松开if(s==1){h++;}if(s!=1){w++;}}}PORTB=0xdf;delay(1);//延时消抖//按键4if((PINB&0x01)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x01)==0)//确实有按键按下{n++;delay(1);/
9、/延时消抖key=4;write_data(0x30+key);while((!PINA&0X01));//等待按键松开if(s==1){h++;}if(s!=1){w++;}}}//按键5if((PINB&0x02)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x02)==0)//确实有按键按下{n++;delay(1);//延时消抖while((!PINA&0X02));key=5;write_data(0x30+key);//等待按键松开if(s==1){h++;}if(s!=1){w++;}}}//按键6if
10、((PINB&0x04)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x04)==0)//确实有按键按下{n++;delay(1);//延时消抖key=6;while((!PINA&0X04));write_data(0x30+key);//等待按键松开if(s==1){h++;}if(s!=1){w++;}}}//按键7if((PINB&0x08)==0)//判断PA0是否是0,是则是s1按下了{delay(1);//延时消抖if((PINB&0x08)==0)//确实有按键按下{n