AVR128 Program - Matrix Buttons

Publisher:心灵飞翔Latest update time:2016-03-04 Source: eefocusKeywords:AVR128 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include  
#include
#define uchar unsigned char
#define uint unsigned int
      
void Delayms(uint MS);     
 
uchar key_scan(void);
void init_io(void);
 
uchar led_discode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
                       0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
                     
uchar   key_val=0;
 
void main (viod)
{
     uchar key_io;
init_io();
while(1)
{
     PORTD=0XF0;
 Delayms(5);
 key_io=PIND & 0xf0;
     if(key_io !=0xf0)
     {
     PORTD=0XF0;
     Delayms(1);
   key_io=PIND & 0xf0;
     if(key_io !=0xf0)
   {
  key_val=key_scan();   
      key_val |= key_io ;
   }
     switch(key_val)
              {     
               case 0xee: key_val=0x00;   break;    //Key K1
                          
 case 0xde: key_val=0x01;   break;    //Key K2
                        
 case 0xbe: key_val=0x02;   break;    //Key K3
                        
 case 0x7e: key_val=0x03;   break;    //Key K4
                          
 case 0xed: key_val=0x04;   break;    //Key K5
                         
 case 0xdd: key_val=0x05;   break;    //Key K6
                        
 case 0xbd: key_val=0x06;   break;    //Key K7
                       
 case 0x7d: key_val=0x07;   break;    //Key K8
                          
 case 0xeb: key_val=0x08;   break;    //Press key K9
                        
 case 0xdb: key_val=0x09;   break;    //Key K10
                        
 case 0xbb: key_val=0x0a;   break;    //Key K11
                        
 case 0x7b: key_val=0x0b;   break;    //Key K12
                          
 case 0xe7: key_val=0x0c;   break;    //Key K13
                        
 case 0xd7: key_val=0x0d;   break;    //key K14
                            
                 case 0xb7: key_val=0x0e;   break;    //Key K15
                        
 case 0x77: key_val=0x0f;   break;   //key K16                
              }   
 }                   
 PORTD=0XF0;
 key_io=PIND & 0xf0;
 while(key_io !=0xf0)
 {
 key_io=PIND & 0xf0;
 }
 PORTC=led_discode[key_val];    
}          
}
 
void init_io(void)
{
     DDRA=0XFF;
PORT=0XFF;
 
DDRB=0XFF;             
     PORTB=0XFF;             
 
DDRC=0XFF;              
PORTC=0XFF;             
 
DDRD=0X0F;              
     PORTD=0XF0;   
 
DDRF=0X0E;
PORTF=0X0E;
PORTF&=0XF7;            
 
DDRB |=0X10;           
PORTB|=0X10;         
}
 
uchar key_scan(void)
{
     fly m,temp=0xf7;
for(m=0;m<4;m++)
{
    PORTD=temp | 0xf0;
    Delayms(1);
if((PIND & 0XF0)!=0XF0)
    return(temp & 0x0f);
temp>>=1;
}
}
 
void Delayms(uint MS)  
{
     uint i,j;
     for( i=0;i
     for(j=0;j<1141;j++);
}
 
Keywords:AVR128 Reference address:AVR128 Program - Matrix Buttons

Previous article:AVR128 program - external interrupt
Next article:AVR128 Program - Blink a Single LED

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号