标题: 请大神看看这个TM1621B的单片机驱动程序哪里不对 [打印本页]

作者: PDDDF    时间: 2020-3-9 12:19
标题: 请大神看看这个TM1621B的单片机驱动程序哪里不对
  1. #include <STC15W408AS.h>
  2. #include <intrins.h>

  3. #define uchar unsigned char
  4. #define uint unsigned int

  5. #define BIAS 0x52 //0x29
  6. #define SYSEN 0x02 //0x01
  7. #define SYSDIS 0x00
  8. #define LCD_ON 0x06 //0x03
  9. #define LCD_OFF 0x04 //0x02

  10. sbit DATA = P3^3;
  11. sbit WR = P3^4;
  12. sbit CS = P2^3;

  13. uchar time,c;

  14. void send_Hbit_data(uchar dat,uchar cnt)
  15. {
  16.         uchar i;
  17.         for (i = 0;i<cnt;i++)
  18.         {
  19.                 if(dat & 0x80) {DATA = 1;}
  20.                 else {DATA = 0;}
  21.                 _nop_();
  22.                 WR = 0;
  23.                 _nop_();
  24.                 WR = 1;
  25.                 dat<<=1;
  26.         }
  27.         WR = 0;
  28.         DATA = 0;
  29. }

  30. void send_Lbit_data(uchar dat,uchar cnt)
  31. {
  32.         uchar i;
  33.         for(i = 0;i<cnt;i++)
  34.         {
  35.                 if(dat & 0x01) {DATA = 1;}
  36.           else {DATA = 0;}
  37.     _nop_();
  38.     WR = 0;
  39.     _nop_();
  40.     WR = 1;
  41.                 dat>>=1;
  42.         }
  43.         WR = 0;
  44.         DATA = 0;
  45. }

  46. void command(uchar cmd)
  47. {
  48.         CS = 0;
  49.         send_Hbit_data(0x80,4);
  50.         send_Hbit_data(cmd,8);
  51.         CS = 1;
  52. }

  53. void display(uchar add,uchar dat)
  54. {
  55.         CS = 0;
  56.         send_Hbit_data(0xa0,3);
  57.         send_Hbit_data(add<<2,6);
  58.         send_Lbit_data(dat,4);
  59.         CS = 1;
  60. }

  61. void initT0()//20ms
  62. {
  63.   TMOD = 0x00;
  64.   TH0 = 0xb1;
  65.   TL0 = 0xdf;
  66.   EA = 1;
  67.   ET0 = 1;
  68.   TR0 = 1;
  69.         PT0 = 1;
  70. }

  71. void T0int() interrupt 1
  72. {
  73.         time++;
  74.         if(time == 50) {time = 0;c++;}
  75. }

  76. void delay(uchar a)
  77. {
  78.         uchar b;
  79.         b = 200;
  80.         while(a--)
  81.         {
  82.                 while(b--);
  83.         }
  84. }

  85. void main()
  86. {
  87.         initT0();
  88.         delay(1);
  89.         while(1)
  90.         {
  91.                 if(c == 5)
  92.                 {
  93.                         command(BIAS); //A
  94.             command(SYSEN); //B
  95.             command(LCD_ON); //C
  96. display(0x09,0x0f);
  97.                         while(1);
  98.                 }
  99.         }
  100. }
复制代码
ABC三条命令发送完后,整个液晶屏所有的灯都亮了,后面那个display函数功能无法体现,求教

作者: zhanghyg    时间: 2020-3-9 15:01
程序死在最后那个 while(1);上了




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1