欢迎来到天天文库
浏览记录
ID:15396452
大小:28.50 KB
页数:3页
时间:2018-08-03
《avr单片机基于atmega16的按键数码管程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、江西渝州科技职业学院按键数码管程序//Target:M16//Crystal:4.0000Mhz#include#include#definehuang1(PINB&BIT(PB0))#definehuang2(PINB&BIT(PB1))#definehuang3(PINB&BIT(PB2))#definehuang4(PINB&BIT(PB3))unsignedcharxianshishuju[8];unsignedcharkey=16;//16表示无效键值voidport_init(void){PORTA=0xff;DDRA=0
2、xff;PORTB=0xff;DDRB=0xf0;PORTC=0x00;//m103outputonlyDDRC=0xff;PORTD=0x00;DDRD=0x00;}//callthisroutinetoinitializeallperipheralsvoidinit_devices(void){//stoperrantinterruptsuntilsetupCLI();//disableallinterruptsport_init();MCUCR=0x00;GICR=0x00;TIMSK=0x00;//timerinterruptsourcesSEI();//re-en
3、ableinterrupts//allperipheralsarenowinitialized}//voiddelay(unsignedcharm){unsignedchari,j;for(i=0;i4、u(void){unsignedchari;for(i=0;i<8;i++){PORTC=~BIT(i);PORTA=duanma[xianshishuju[i]];delay(1);PORTA=0X00;}}voidmain(void){unsignedchari;init_devices();//insertyourfunctionalcodewhile(1){//for(i=0;i<10;i++)baweixianshishuju();PORTB=0XEF;if(!huang1)key=3;if(!huang2)key=6;if(!huang3)key=9;PORTB5、=0XDF;if(!huang1)key=2;if(!huang2)key=5;if(!huang3)key=8;if(!huang4)key=0;PORTB=0XBF;3小强出版江西渝州科技职业学院if(!huang1)key=1;if(!huang2)key=4;if(!huang3)key=7;do{baweixianshishuju();PORTB=0X0F;}while(PINB!=0x0F);if(key<10){xianshishuju[0]=xianshishuju[1];xianshishuju[1]=xianshishuju[2];xianshishuj6、u[2]=xianshishuju[3];xianshishuju[3]=xianshishuju[4];xianshishuju[4]=xianshishuju[5];xianshishuju[5]=xianshishuju[6];xianshishuju[6]=xianshishuju[7];xianshishuju[7]=key;key=16;}baweixianshishuju();}}3小强出版
4、u(void){unsignedchari;for(i=0;i<8;i++){PORTC=~BIT(i);PORTA=duanma[xianshishuju[i]];delay(1);PORTA=0X00;}}voidmain(void){unsignedchari;init_devices();//insertyourfunctionalcodewhile(1){//for(i=0;i<10;i++)baweixianshishuju();PORTB=0XEF;if(!huang1)key=3;if(!huang2)key=6;if(!huang3)key=9;PORTB
5、=0XDF;if(!huang1)key=2;if(!huang2)key=5;if(!huang3)key=8;if(!huang4)key=0;PORTB=0XBF;3小强出版江西渝州科技职业学院if(!huang1)key=1;if(!huang2)key=4;if(!huang3)key=7;do{baweixianshishuju();PORTB=0X0F;}while(PINB!=0x0F);if(key<10){xianshishuju[0]=xianshishuju[1];xianshishuju[1]=xianshishuju[2];xianshishuj
6、u[2]=xianshishuju[3];xianshishuju[3]=xianshishuju[4];xianshishuju[4]=xianshishuju[5];xianshishuju[5]=xianshishuju[6];xianshishuju[6]=xianshishuju[7];xianshishuju[7]=key;key=16;}baweixianshishuju();}}3小强出版
此文档下载收益归作者所有