大家好,我是一个AVR初学者,变了一个数码管动态显示矩阵键盘的值的程序,是用AVR-GCC编的,但是显示不了值,但我将头文件改了,在ICCAVR上就可以正常显示。求各位大侠帮我解决下,希望在AVR-GCC上能够正常运行,小弟将非常感谢! #include <avr/io.h> //#define F_CPU 1000000UL //延时 //#include <util/delay.h> //#include <iom16v.h> //#include <macros.h> unsigned char const table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39,0x5e,0x79,0x71};// 显示段码值01234567 0~F unsigned char tabwei[]={0,1,2,3};//位选码 unsigned char keybuff[4];//按键值缓存 void _delay_ms(unsigned int z) { while(z--); } void display(void) { unsigned char i; for (i=0;i<4;i++) { PORTA = table[keybuff]; PORTC = tabwei; _delay_ms(200); } } unsigned char keyboard(void) { /*unsigned char key1,cord_h,cord_l; DDRD = 0xf0; //设置低四位端口为输入 PORTD = 0x0f; //PD4`PD7列线全设置为0 _delay_ms(100); cord_l = PIND | 0x0f; //读入行线值 if (cord_l !=0x0f) //先检测有无按键按下 { _delay_ms(100); //去抖 if (cord_l !=0x0f) //在判断 { cord_l = PIND | 0x0f; //读入行线值 DDRD =0x0f; PORTD=cord_l|0xf0; //输出当前行线值 _delay_ms(100); cord_h=PIND&0xf0; //读入列线值 key1=cord_h+cord_l;//键盘最后组合码值 } else key1=0xff; switch(key1) { case 0xee:return 0;break;//0 case 0xde:return 1;break;//1 case 0xbe:return 2;break; case 0x7e:return 3;break; case 0xed:return 4;break; case 0xdd:return 5;break; case 0xbd:return 6;break; case 0x7d:return 7;break; case 0xeb:return 8;break; case 0xdb:return 9;break; case 0xbb:return 10;break; case 0x7b:return 11;break; case 0xe7:return 12;break; case 0xd7:return 13;break; case 0xb7:return 14;break; case 0x77:return 15;break; } return 16; } } int main(void) { unsigned char key,t; DDRA = 0xFF; // 定义为输出 PORTA = 0xFF; // 输出高电平 DDRC=0xff; DDRD = 0xff; PORTD = 0xff; while(1) { //TODO:: Please write your application code display(); key = keyboard(); if (key<16) { if (t<4) { keybuff[t]=key; } t++; if(t==4) t=0; while (key<16) { key=keyboard(); display(); } } } }
|