⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdinterface.lst

📁 这是C8051F330的LCD驱动程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 382   2            RCLK = 0;                        // turn off clock
 383   2      
 384   2            P1MDIN  &= ~0x10;                // configure COM1 to ANALOG_IN;
 385   2            P1MDIN  |= 0x20;                 // and COM2 to digital
 386   2      
 387   2            P1MDOUT &= ~0x10;                // make COM1 an open-drain
 388   2            P1MDOUT |= 0x20;                 // make COM2 a push-pull
 389   2            COM1    = 1;                     // set COM1 to high impedance
 390   2            COM2    = 1 ^ com_invert;        // start the COM2 cycle
 391   2            com_cycle = 3;                   // next state
 392   2         }
 393   1      
 394   1         else if (com_cycle == 3)
 395   1         {
 396   2            SER = D6C ^ com_invert;     Strobe();
 397   2            SER = D6G ^ com_invert;     Strobe();
 398   2            SER = D5C ^ com_invert;     Strobe();
 399   2            SER = D5G ^ com_invert;     Strobe();
 400   2            SER = D4C ^ com_invert;     Strobe();
 401   2            SER = D4G ^ com_invert;     Strobe();
 402   2            SER = D3C ^ com_invert;     Strobe();
 403   2            SER = D3G ^ com_invert;     Strobe();
 404   2            SER = D2C ^ com_invert;     Strobe();
 405   2            SER = D2G ^ com_invert;     Strobe();
 406   2            SER = D1C ^ com_invert;     Strobe();
 407   2            SER = D1G ^ com_invert;     Strobe();
 408   2            SER = 1   ^ com_invert;     Strobe();      // non-existent segment
 409   2            SER = 1   ^ com_invert;     Strobe();      // non-existent segment
 410   2            SER = 1   ^ com_invert;     Strobe();      // non-existent segment
 411   2      
 412   2            RCLK = 1;                        // put shifted data to LCD - rising edge
 413   2            for (i=0; i<PULSE_LENGTH; i++);  // keep clock high for a while
 414   2            RCLK = 0;                        // turn off clock
 415   2      
 416   2            P1MDIN  &= ~0x20;                // configure COM2 to ANALOG_IN;
 417   2            P1MDIN  |= 0x40;                 // and COM3 to digital
 418   2      
 419   2            P1MDOUT &= ~0x20;                // make COM2 an open-drain
 420   2            P1MDOUT |= 0x40;                 // make COM3 a push-pull
 421   2            COM2    = 1;                     // set COM2 to high impedance
 422   2            COM3    = 1 ^ com_invert;        // start the COM3 cycle
 423   2            com_cycle = 4;                   // next state
 424   2         }
 425   1      
 426   1         else if (com_cycle == 4)
 427   1         {
C51 COMPILER V8.02   LCDINTERFACE                                                          03/15/2009 20:48:19 PAGE 8   

 428   2            SER = D6D ^ com_invert;     Strobe();
 429   2            SER = D6E ^ com_invert;     Strobe();
 430   2            SER = D5D ^ com_invert;     Strobe();
 431   2            SER = D5E ^ com_invert;     Strobe();
 432   2            SER = D4D ^ com_invert;     Strobe();
 433   2            SER = D4E ^ com_invert;     Strobe();
 434   2            SER = D3D ^ com_invert;     Strobe();
 435   2            SER = D3E ^ com_invert;     Strobe();
 436   2            SER = D2D ^ com_invert;     Strobe();
 437   2            SER = D2E ^ com_invert;     Strobe();
 438   2            SER = D1D ^ com_invert;     Strobe();
 439   2            SER = D1E ^ com_invert;     Strobe();
 440   2            SER = 1   ^ com_invert;     Strobe();         // non-existent segment
 441   2            SER = 1   ^ com_invert;     Strobe();         // non-existent segment
 442   2            SER = 1   ^ com_invert;     Strobe();         // non-existent segment
 443   2      
 444   2            RCLK = 1;                        // put shifted data to LCD - rising edge
 445   2            for (i=0; i<PULSE_LENGTH; i++);  // keep clock high for a while
 446   2            RCLK = 0;                        // turn off clock
 447   2      
 448   2            P1MDIN  &= ~0x40;                // configure COM3 to ANALOG_IN;
 449   2            P1MDIN  |= 0x80;                 // and COM4 to digital
 450   2      
 451   2            P1MDOUT &= ~0x40;                // make COM3 an open-drain
 452   2            P1MDOUT |= 0x80;                 // make COM4 a push-pull
 453   2            COM3    = 1;                     // set COM3 to high impedance
 454   2            COM4    = 1 ^ com_invert;        // start the COM4 cycle
 455   2            com_cycle = 1;                   // next state
 456   2      
 457   2            com_invert = com_invert ^ 1;     // toggle com_invert
 458   2         }
 459   1      
 460   1         TF2H = 0;                           // clear TF2
 461   1      
 462   1      } // end LCDrefresh_ISR
 463          
 464          //-----------------------------------------------------------------------------
 465          // Strobe
 466          //-----------------------------------------------------------------------------
 467          //
 468          // Strobe is used to clock the data into the 74HC595 shift registers
 469          //
 470          void Strobe()
 471          {
 472   1         int i = 0;
 473   1      
 474   1         SRCLK = 1;
 475   1         for (i = 0; i < PULSE_LENGTH; i++);          // wait a few cycles
 476   1         SRCLK = 0;
 477   1         for (i = 0; i < PULSE_LENGTH; i++);          // wait a few cycles
 478   1      
 479   1      }
 480          
 481          //-----------------------------------------------------------------------------
 482          // wait_one_msec
 483          //-----------------------------------------------------------------------------
 484          //
 485          // Assumes Timer3 overflows once every 500 usec
 486          //
 487          void wait_one_ms(unsigned int count)
 488          {
 489   1         count = count * 2;                  // overflows once every 500 usec
C51 COMPILER V8.02   LCDINTERFACE                                                          03/15/2009 20:48:19 PAGE 9   

 490   1                                             // so double that is 1 ms
 491   1      
 492   1         TMR3CN &= ~0x80;                    // Clear Timer3 overflow flag
 493   1         TMR3 = TMR3RL;
 494   1         TMR3CN  = 0x04;                     // Start Timer3
 495   1      
 496   1         while (count--)
 497   1         {
 498   2            while (!(TMR3CN & 0x80)) {}      // wait for overflow
 499   2            TMR3CN &= ~0x80;                 // clear overflow indicator
 500   2         }
 501   1      
 502   1         TMR3CN &= ~0x04;                    // Stop Timer3
 503   1      }
 504          
 505          //-----------------------------------------------------------------------------
 506          // LCD functions
 507          //-----------------------------------------------------------------------------
 508          
 509          //-----------------------------------------------------------------------------
 510          // putchar
 511          //-----------------------------------------------------------------------------
 512          //
 513          // putchar only handles the digit components on the LCD screen.
 514          // This functions shifts the digit values to the left, shifting out the
 515          // left-most digit.  This function has 3 potential actions based on the input:
 516          //
 517          // 1. Any input whose ASCII code is between 0 and 127 gets translated
 518          //    according to the translation table above
 519          //
 520          // 2. Any input whose ASCII code is between 128 and 255 is directly sent to
 521          //    the LCD. The lower 7 bits indicate which of the seven segments are lit.
 522          //
 523          // 3. Passing a newline char '\n' to this function clears all 6 digits
 524          //
 525          // This function, unlike standard putchar, does not have any error return msgs.
 526          //
 527          // This function will not cause an interrupt to force output.  The input char
 528          // will be displayed on the screen on the next refresh cycle
 529          
 530          char putchar(char charIN)
 531          {
 532   1         unsigned char iter = 0;
 533   1      
 534   1         if (charIN != '\n')                              // not a new line
 535   1         {
 536   2            if ((charIN & 0x80) == 0) {                   // translation necesssary
 537   3              charIN = translation_table [charIN]; }      // quick lookup
 538   2      
 539   2            EA = 0;                                       // prevent partial display
 540   2      
 541   2            for (iter = 0; iter < 5; iter++) {            // shift the digits left
 542   3               LCD_digits[iter] = LCD_digits[iter+1]; }
 543   2      
 544   2            LCD_digits[5] = charIN;                       // new digit is rightmost
 545   2      
 546   2            EA = 1;                                       // enable interrupts again
 547   2         }
 548   1      
 549   1         else                                             // input is a newline
 550   1         {
 551   2            EA = 0;                                       // disable interrupts
C51 COMPILER V8.02   LCDINTERFACE                                                          03/15/2009 20:48:19 PAGE 10  

 552   2            for (iter = 0; iter < 6; iter++) {
 553   3               LCD_digits[iter] = 0xFF; }                 // clear all digits
 554   2            EA = 1;                                       // enable interrupts
 555   2         }
 556   1      
 557   1         if (charIN == 0xFF) {                            // couldn't interpret OR space
 558   2            charIN = ' '; }                               // return space
 559   1      
 560   1         return charIN;                                   // just like putchar
 561   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    934    ----
   CONSTANT SIZE    =    137    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      8    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -