Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <LPC23xx.H> /* ???????? LPC23xx */
  2.  
  3. #define STB 26 //Port1.26
  4. # define CLK 27 //Port1.27
  5. # define DIO 28 //Port1.28
  6.  
  7. void delay(unsigned int count) {
  8. unsigned int i;
  9. for (i = 0; i < count; i++) {}
  10. }
  11. void tm1638_sendbyte(unsigned int x) {
  12. unsigned int i;
  13. IODIR1 |= (1 << DIO);
  14. for (i = 0; i < 8; i++) {
  15. IOCLR1 = (1 << CLK);
  16. delay(0xfff);
  17. if (x & 1) {
  18. IOSET1 = (1 << DIO);
  19. }
  20. else {
  21. IOCLR1 = (1 << DIO);
  22. }
  23. delay(0xfff); //????????
  24. x >>= 1;
  25. IOSET1 = (1 << CLK); //?????? CLK ????????????? ? 1
  26. delay(0x1fff);
  27. }
  28. }
  29. unsigned int tm1638_receivebyte() {
  30. unsigned int i;
  31. unsigned int x = 0;
  32. IODIR1 &= ~(1 << DIO);
  33. for (i = 0; i < 32; i++) {
  34. IOCLR1 = (1 << CLK);
  35. delay(0xfff);
  36. if (IOPIN1 & (1 << DIO)) {
  37. x |= (1 << i);
  38. }
  39. delay(0xfff);
  40. IOSET1 = (1 << CLK);
  41. delay(0x1fff);
  42. }
  43. return x;
  44. }
  45. void tm1638_sendcmd(unsigned int x) {
  46. IOSET1 = (1 << STB);
  47.  
  48. IODIR1 = (1 << CLK) | (1 << DIO) | (1 << STB);
  49.  
  50. IOCLR1 = (1 << STB);
  51. tm1638_sendbyte(x);
  52. }
  53. void tm1638_setadr(unsigned int adr) {
  54.  
  55. tm1638_sendcmd(0xC0 | adr);
  56. }
  57. void tm1638_init() {
  58. unsigned int i;
  59. tm1638_sendcmd(0x88);
  60.  
  61. tm1638_sendcmd(0x40);
  62. tm1638_setadr(0);
  63.  
  64. for (i = 0; i <= 0xf; i++)
  65. tm1638_sendbyte(0);
  66.  
  67. tm1638_sendcmd(0x44);
  68. }
  69. int main(void) {
  70. unsigned int n, i;
  71. tm1638_init();
  72. while (1) {
  73.  
  74. for (n = 1; n <= 0xf; n += 2) {
  75. i = 1;
  76. while (i != 0) {
  77. // 0x46 means 0100 0110.
  78. //This command is used to read from keyboard register
  79. // using fixed-address mode
  80. tm1638_sendcmd(0x46);
  81.  
  82. // Receiving current keyboard state
  83. i = tm1638_receivebyte();
  84. }
  85.  
  86. // Setting the address of the LED Indication Register
  87. tm1638_setadr(n);
  88. // Sending a data to the register
  89. tm1638_sendbyte(n);
  90. delay(0xffff);
  91. // Turning of the LED
  92. tm1638_sendbyte(0);
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement