Advertisement
Guest User

keypad

a guest
Jul 22nd, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /*This program is created by Shubham */
  2. /*This program is for appin project */
  3.  
  4. #include <stdio.h>
  5. #include <reg51.h>
  6.  
  7. sbit col1 = P0^0;
  8. sbit col2 = P0^1;
  9. sbit col3 = P0^2;
  10. sbit row1 = P0^3;
  11. sbit row2 = P0^4;
  12. sbit row3 = P0^5;
  13. sbit row4 = P0^6;
  14.  
  15. void delay(unsigned int msec) // Function to provide time delay in msec.
  16. {
  17. int i,j ;
  18. for(i=0;i<msec;i++)
  19. for(j=0;j<1275;j++);
  20. }
  21.  
  22. void check_col1() //Function for checking column one
  23. {
  24. row1=row2=row3=row4=1;
  25. row1=0;
  26. if(col1==0)
  27. {
  28. P1 = 0xf9;
  29. delay(100);
  30. }
  31. row1=1;
  32. row2=0;
  33. if(col1==0)
  34. {P1 = 0x99;
  35. delay(100);}
  36. row2=1;
  37. row3=0;
  38. if(col1==0)
  39. {
  40. P1 = 0xf8;
  41. delay(100);
  42. }
  43. row3=1;
  44. row4=0;
  45. if(col1==0)
  46. {
  47. P1 = 0x00;
  48. delay(100);
  49. }
  50. row4=1;
  51. }
  52.  
  53. void main()
  54. {
  55. col1=col2=col3=1; //Input Port
  56. while(1)
  57. {
  58. row1=row2=row3=row4=0;
  59. if(col1==0)
  60. check_col1();
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement