LED16x32_595.c
上传用户:wxxy1999
上传日期:2008-02-13
资源大小:1k
文件大小:1k
源码类别:

多显示器编程

开发平台:

C/C++

  1. //2005-8-10
  2. //移位寄存器用74LS595
  3. #include <at89x51.h>
  4. #define SCK P0_0
  5. #define SCLR  P0_1
  6. #define RCK P0_2
  7. #define OEN P0_3
  8. #define SER P0_4
  9. unsigned char code table_zhu[]={
  10. 0xF7,0xBF,0x77,0xBB,0xAC,0x0B,0xDF,0xB7,
  11. 0xAF,0xAF,0x68,0x01,0xF7,0xBF,0xE7,0x7F,
  12. 0xD6,0x03,0xB4,0xFB,0x72,0xFB,0xF6,0x03,
  13. 0xF6,0xFB,0xEE,0xFB,0xAE,0x03,0xDE,0xFB};/*"猪",0*/
  14. unsigned char code table_tou[]={
  15. 0xFF,0x7F,0xEF,0x7F,0xF3,0x7F,0xFB,0x7F,
  16. 0xEF,0x7F,0xF3,0x7F,0xF7,0x7F,0xFF,0x7F,
  17. 0x00,0x01,0xFF,0x7F,0xFE,0xBF,0xFD,0xDF,
  18. 0xFB,0xCF,0xF7,0xE7,0xEF,0xF3,0xDF,0xF7};/*"头",1*/
  19. void display(unsigned char);
  20. void delay1ms(void);
  21. void main (void)
  22. {
  23. unsigned char i;
  24. while (1)
  25. {
  26. for(i=0;i<16;i++)
  27. {
  28. P2=0x00+i;
  29. OEN=1;
  30. SCLR=0;
  31. SCLR=1;
  32. display(table_tou[2*i+1]);
  33. display(table_tou[2*i]);
  34. display(table_zhu[2*i+1]);
  35. display(table_zhu[2*i]);
  36. RCK=0;
  37. RCK=1;
  38. OEN=0;
  39. delay1ms();
  40. }
  41. }
  42. }
  43. void display(unsigned char dispcode)
  44. {
  45. unsigned char i;
  46. unsigned char temp;
  47. for (i=0;i<8;i++)
  48. {
  49. temp=dispcode&0x80;//一定要用变量代换;
  50. if (temp==0x80)
  51. {
  52. SER=1;
  53. }
  54. else
  55. {
  56. SER=0;
  57. }
  58. SCK=0;
  59. SCK=1;
  60. dispcode=dispcode<<1;//dispcode移位,不是temp移位;
  61. }
  62. }
  63. void delay1ms(void)
  64. {
  65. unsigned char j,k;
  66. // for(i=20;i>0;i--)
  67. for(j=2;j>0;j--)
  68. for(k=248;k>0;k--);
  69. }