pic 4*4 keyboard scanning program

Publisher:Tiger8Latest update time:2017-12-07 Source: eefocusKeywords:pic  4*4 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include

             
 __CONFIG(0x1832);    
const char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X90}; //Define the data table of constants 0-9   

 volatile unsigned char result=0,temp=0,f=0;  
 volatile unsigned int total=0,ge=0,shi=0,bai=0,qian=0,c=1; 
 void delay(); //delay function declaration 
 void init(); //I/O port initialization function declaration 
 void s CAN (); //Key scanning program declaration 
 void display(unsigned int x); //Display function declaration 
//--------------------------------------------------- 
                             //Main program   
void main() 

   init(); //Call initialization subroutine 
  while(1) //Loop work 
    { 
          
       scan();                 
       display(result);  
    } 
 } 
  
//--------------------------------------------------- 
//Initialization function 
void init()  
 { 
   
  ADCON1=0X07; //Set port A as a normal I/O port 
  TR ISA =0B00000000; //Set the high 2 bits of port A to output and the low 4 bits to input 
  TRISC=0B11110000; //Set the high 4 bits of port C as input and the low 4 bits as output 
  TRISD=0X00; //Set port D as output 
  PORTA=0XFF;               
  PORTD=0XFF; //Clear all displays first 
 } 

//-----------------------------------------------3--- 
//Key scanning program 
void scan(){  
               PORTC=0xff; 
               RC3=0; { if(RC4==0) result=1; if(RC5==0) result=2; if(RC6==0) result=3; if(RC7==0) result=4;} 
                
               
               PORTC=0xff; 
               RC2=0; { if(RC4==0) result=5; if(RC5==0) result=6; if(RC6==0) result=7; if(RC7==0) result=8;} 

               
               PORTC=0xff; 
               RC1=0; { if(RC4==0) result=9; if(RC5==0) result=10; if(RC6==0) result=11; if(RC7==0) result=12;} 
               
              
               PORTC=0xff; 
               RC0=0; { if(RC4==0) result=13; if(RC5==0) result=14; if(RC6==0) result=15; if(RC7==0) result=16;} 
            // if(temp!=result) {f++; if(f==1) qian=1000*result ; if(f==2) bai=100*result; if(f==3) shi=10*result; if(f==4) ge=result; } if(f==4) while(1){total=ge+shi+bai+qian; display(total); }  
  
 } 

//---------------------------------------------------------------- 
//Display program 
 void display(unsigned int x) // Voltage display function   
   { 
    
     unsigned int g,s,b,q; //define 6 temporary variables 
    // temp=result; c=1; 
     q=x/1000; 
     b=x%1000/100; //find the thousands displayed         
     s=x%100/10; //find the hundreds displayed 
     g=x%10; //find the tens displayed 
   
     PORTD=TABLE[q]; //display a decimal point 
     PORTA=0B111111110; //RA0 output lowlevel , light up the thousands display      
     delay(1);  

     PORTD=TABLE[b]; //Look up the table to get the code for the hundreds display 
     PORTA=0B11111101; //RA1 outputs low level, light up the hundreds display 
     delay(1); //Delay for a certain time to ensure the display brightness 

     PORTD=TABLE[s]; //Look up the table to get the code for the tens display 
     PORTA=0B11111011; //RA2 outputs low level, light up the tens display 
     delay(1); //Delay for a certain time to ensure the brightness 

     PORTD=TABLE[g]; //Look up the table to get the code for the tens display 
     PORTA=0B11110111; //RA3 outputs low level, light up the tens display 
     delay(1); //Delay for a certain time to ensure the brightness 

     PORTD=0xff; 

   }  
//------------------------------------------------------------------ 
//Delay program 
void delay() //Delay program 
    { 
     int i; //Define integer variables 
     for(i=0x100;i--;); //Delay 
    } 


Keywords:pic  4*4 Reference address:pic 4*4 keyboard scanning program

Previous article:LCD1602 C Program
Next article:PIC microcontroller LED water light program

Latest Microcontroller Articles
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号