20X7微型点阵屏,可切换字体。

2020-02-04 09:15发布

本帖最后由 oufuqiang 于 2012-4-11 13:19 编辑

20X7微型点阵屏,可切换字体。 595控制的。

http://v.youku.com/v_show/id_XMzc5NDMyNDI0.html

IMG_0594.jpg (750.83 KB, 下载次数: 0) 下载附件 2012-4-11 13:18 上传

  1. #include <reg52.h>

  2. sbit scl = P1^0;
  3. sbit sda = P1^1;
  4. sbit upd = P1^2;
  5. sbit dpy = P1^7;

  6. sbit key1 = P2^0;
  7. sbit key2 = P2^1;
  8. sbit key3 = P2^2;
  9. sbit key4 = P2^4;
  10. sbit key5 = P2^5;

  11. unsigned char line,c1,c2,c3,c4;
  12. unsigned char code scantab[5]={0x02,0x04,0x08,0x10,0x20};
  13. bit charface,dot;
  14. unsigned char code numdot1[]={
  15. 0x00,0x60,0xFA,0x60,0x00,0x08,0x70,0x08,0x70,0x00,0x28,0x7C,0x28,0x7C,0x28,0x20,
  16. 0x54,0xFE,0x54,0x08,0x64,0x68,0x10,0x2C,0x4C,0x1C,0x62,0xBA,0x64,0x3A,0x00,0x02,
  17. 0x0C,0x00,0x00,0x00,0x38,0x44,0x82,0x00,0x82,0x44,0x38,0x00,0x00,0x48,0x30,0xFC,
  18. 0x30,0x48,0x00,0x10,0x7C,0x10,0x00,0x00,0x02,0x0C,0x00,0x00,0x00,0x08,0x08,0x08,
  19. 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x02,0x1C,0x60,0x80,0x00,0x7C,0x92,0xA2,0x7C,
  20. 0x00,0x42,0xFE,0x02,0x00,0x00,0x66,0x8A,0x92,0x62,0x00,0x44,0x92,0x92,0x6C,0x00,
  21. 0x38,0x4A,0xFE,0x0A,0x00,0xE4,0x92,0x92,0x8C,0x00,0x7C,0x92,0x92,0x0C,0x00,0xC0,
  22. 0x9E,0xA0,0xC0,0x00,0x6C,0x92,0x92,0x6C,0x00,0x60,0x92,0x92,0x7C,0x00,0x00,0x44,
  23. 0x00,0x00,0x00,0x02,0x4C,0x00,0x00,0x10,0x28,0x44,0x82,0x00,0x00,0x24,0x24,0x24,
  24. 0x24,0x00,0x82,0x44,0x28,0x10,0x00,0x60,0x8A,0x90,0x60,0x7C,0x82,0x9A,0xAA,0x7A,
  25. 0x00,0x3E,0xC8,0x78,0x0E,0x00,0x82,0xFE,0x92,0x6C,0x00,0x7C,0x82,0x82,0x44,0x00,
  26. 0x82,0xFE,0x82,0x7C,0x00,0xFE,0x92,0x92,0x82,0x00,0xFE,0x90,0x90,0x80,0x00,0x7C,
  27. 0x82,0x8A,0x4C,0x00,0xFE,0x10,0x10,0xFE,0x00,0x82,0xFE,0x82,0x00,0x00,0x06,0x82,
  28. 0xFC,0x80,0x00,0xFE,0x10,0x28,0x44,0x00,0xFE,0x02,0x02,0x02,0xFE,0xF0,0x0E,0xF0,
  29. 0xFE,0xFE,0x20,0x10,0x08,0xFE,0x00,0x7C,0x82,0x82,0x7C,0x00,0xFE,0x88,0x88,0x70,
  30. 0x00,0x7C,0x82,0x84,0x7A,0x00,0xFE,0x90,0x98,0x66,0x00,0x64,0x92,0x92,0x4C,0x80,
  31. 0x80,0xFE,0x80,0x80,0x00,0xFC,0x02,0x02,0xFC,0x00,0xF8,0x06,0x1C,0xE0,0xE0,0x1E,
  32. 0xF0,0x1E,0xE0,0x82,0x6C,0x10,0x6C,0x82,0x80,0xE2,0x1E,0xE2,0x80,0x00,0x00,0x8E,
  33. 0x92,0xE2};
  34. unsigned char code numdot2[]={
  35. 0x00,0x60,0xFA,0x60,0x00,0x08,0x70,0x08,0x70,0x00,0x28,0x7C,0x28,0x7C,0x28,0x20,
  36. 0x54,0xFE,0x54,0x08,0x64,0x68,0x10,0x2C,0x4C,0x1C,0x62,0xBA,0x64,0x3A,0x00,0x02,
  37. 0x0C,0x00,0x00,0x00,0x38,0x44,0x82,0x00,0x82,0x44,0x38,0x00,0x00,0x48,0x30,0xFC,
  38. 0x30,0x48,0x00,0x10,0x7C,0x10,0x00,0x00,0x02,0x0C,0x00,0x00,0x00,0x08,0x08,0x08,
  39. 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x02,0x1C,0x60,0x80,0x00,0xFE,0x82,0x82,0xFE,
  40. 0x00,0x00,0x00,0x00,0xFE,0x00,0x9E,0x92,0x92,0xF2,0x00,0x92,0x92,0x92,0xFE,0x00,
  41. 0xF0,0x10,0x10,0xFE,0x00,0xF2,0x92,0x92,0x9E,0x00,0xFE,0x92,0x92,0x9E,0x00,0xE0,
  42. 0x80,0x80,0xFE,0x00,0xFE,0x92,0x92,0xFE,0x00,0xF2,0x92,0x92,0xFE,0x00,0x00,0x44,
  43. 0x00,0x00,0x00,0x02,0x4C,0x00,0x00,0x10,0x28,0x44,0x82,0x00,0x00,0x24,0x24,0x24,
  44. 0x24,0x00,0x82,0x44,0x28,0x10,0x00,0x60,0x8A,0x90,0x60,0x7C,0x82,0x9A,0xAA,0x7A,
  45. 0x00,0x3E,0xC8,0x78,0x0E,0x00,0x82,0xFE,0x92,0x6C,0x00,0x7C,0x82,0x82,0x44,0x00,
  46. 0x82,0xFE,0x82,0x7C,0x00,0xFE,0x92,0x92,0x82,0x00,0xFE,0x90,0x90,0x80,0x00,0x7C,
  47. 0x82,0x8A,0x4C,0x00,0xFE,0x10,0x10,0xFE,0x00,0x82,0xFE,0x82,0x00,0x00,0x06,0x82,
  48. 0xFC,0x80,0x00,0xFE,0x10,0x28,0x44,0x00,0xFE,0x02,0x02,0x02,0xFE,0xF0,0x0E,0xF0,
  49. 0xFE,0xFE,0x20,0x10,0x08,0xFE,0x00,0x7C,0x82,0x82,0x7C,0x00,0xFE,0x88,0x88,0x70,
  50. 0x00,0x7C,0x82,0x84,0x7A,0x00,0xFE,0x90,0x98,0x66,0x00,0x64,0x92,0x92,0x4C,0x80,
  51. 0x80,0xFE,0x80,0x80,0x00,0xFC,0x02,0x02,0xFC,0x00,0xF8,0x06,0x1C,0xE0,0xE0,0x1E,
  52. 0xF0,0x1E,0xE0,0x82,0x6C,0x10,0x6C,0x82,0x80,0xE2,0x1E,0xE2,0x80,0x00,0x00,0x8E,
  53. 0x92,0xE2};

  54. //void yanshi(unsigned int time)
  55. // {
  56. // while(--time);
  57. // }
  58. void send595(unsigned char dat)
  59.   {
  60.   unsigned char i;
  61.   i=8;
  62.   do{
  63.         sda=dat&0x01;
  64.         scl=1;
  65.         scl=0;
  66.         dat=dat>>1;
  67.         }while(--i);
  68.   }
  69. void scandot(void)
  70.   {
  71.   if(charface)
  72.     {
  73.         send595(numdot1[c1*5+line]);
  74.         send595(numdot1[c2*5+line]);
  75.         send595(numdot1[c3*5+line]|dot);
  76.         send595(numdot1[c4*5+line]);
  77.         }
  78.   else
  79.     {
  80.         send595(numdot2[c1*5+line]);
  81.         send595(numdot2[c2*5+line]);
  82.         send595(numdot2[c3*5+line]|dot);
  83.         send595(numdot2[c4*5+line]);
  84.         }
  85.   send595(scantab[line]);
  86.   upd=1;
  87.   upd=0;
  88.   line++;
  89.   if(line>=5)
  90.     {
  91.     line=0;
  92.     }
  93.   }
  94. void main(void)
  95. {
  96.   TMOD=0X01;
  97.   TR0=1;
  98.   EA=1;
  99.   ET0=1;
  100.   scl=sda=upd=0;
  101.   c1=c2=c3=c4=15;
  102.   send595(0xFF);
  103.   send595(0xFF);
  104.   send595(0xFF);
  105.   send595(0xFF);
  106.   send595(0xFF);
  107.   upd=1;
  108.   upd=0;
  109.   while(key5);
  110. while(1)
  111.   {
  112.   scandot();
  113.   if(key1==0)
  114.     {
  115.         c4++;
  116.         if(c4>=25){c4=15;}
  117.         while(key1==0)
  118.           {
  119.           scandot();
  120.           }
  121.     }
  122.   if(key2==0)
  123.     {
  124.         c3++;
  125.         if(c3>=25){c3=15;}
  126.         while(key2==0)
  127.           {
  128.           scandot();
  129.           }
  130.     }
  131.   if(key3==0)
  132.     {
  133.         c2++;
  134.         if(c2>=25){c2=15;}
  135.         while(key3==0)
  136.           {
  137.           scandot();
  138.           }
  139.     }
  140.   if(key4==0)
  141.     {
  142.         c1++;
  143.         if(c1>=25){c1=15;}
  144.         while(key4==0)
  145.           {
  146.           scandot();
  147.           }
  148.     }
  149.   if(key5==0)
  150.     {
  151.         charface=!charface;
  152.         while(key5==0)
  153.           {
  154.           scandot();
  155.           }
  156.         }
  157.   }
  158. }

  159. void timer0(void) interrupt 1
  160. {
  161. static count,sec;
  162. TH0=(65536-49990)/256;
  163. TL0=(65536-49990)%256;
  164. count++;
  165. if(count>=40)
  166.   {
  167.   count=0;
  168.   dot=!dot;
  169.   sec++;
  170.   if(sec>=60)
  171.     {
  172.         sec=0;
  173.         c1++;
  174.         if(c1>=25)
  175.           {
  176.           c1=15;
  177.           c2++;
  178.           if(c2>=21)
  179.             {
  180.                 c2=15;
  181.                 c3++;
  182.                 if(c3>=25)
  183.                   {
  184.                   c3=15;
  185.                   c4++;
  186.                   if(c4>=21)
  187.                     {
  188.                         c1=c2=c3=c4=15;
  189.                         }
  190.                   }
  191.                 }
  192.           }
  193.         }
  194.   }
  195. }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。