标题: 一个简单的LCD16x2单片机小程序 [打印本页]

作者: oldspring    时间: 2018-10-14 10:20
标题: 一个简单的LCD16x2单片机小程序
前几天,发现了这个51hei网站,突发奇想,向大家推荐了一个51编译器,虽然得到了黑班主的50黑币,但是没有任何51黑弟兄们的捧场,实在遗憾。
今后,我会经常到这里来溜达溜达,推荐一些常见电路简单编程(诸如 LCD 16x2 or 16x4, LCD 12864, I2C, SPI, SD Card, 等等........) 。希望大家喜欢。
以下是一个简单的 LCD 16x2 的单片机小程序:
  1. // Lcd module connections
  2. sbit LCD_RS at P2_0_bit;
  3. sbit LCD_EN at P2_1_bit;

  4. sbit LCD_D4 at P2_2_bit;
  5. sbit LCD_D5 at P2_3_bit;
  6. sbit LCD_D6 at P2_4_bit;
  7. sbit LCD_D7 at P2_5_bit;
  8. // End Lcd module connections

  9. char txt1[] = "mikroElektronika";
  10. char txt2[] = "Easy8051B";
  11. char txt3[] = "Lcd4bit";
  12. char txt4[] = "example";

  13. char i;                              // Loop variable

  14. void Move_Delay() {                  // Function used for text moving
  15.   Delay_ms(500);                     // You can change the moving speed here
  16. }

  17. void main(){

  18.   Lcd_Init();                        // Initialize Lcd

  19.   Lcd_Cmd(_LCD_CLEAR);               // Clear display
  20.   Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  21.   Lcd_Out(1,6,txt3);                 // Write text in first row

  22.   Lcd_Out(2,6,txt4);                 // Write text in second row
  23.   Delay_ms(2000);
  24.   Lcd_Cmd(_LCD_CLEAR);               // Clear display

  25.   Lcd_Out(1,1,txt1);                 // Write text in first row
  26.   Lcd_Out(2,5,txt2);                 // Write text in second row

  27.   Delay_ms(2000);

  28.   // Moving text
  29.   for(i=0; i<4; i++) {               // Move text to the right 4 times
  30.     Lcd_Cmd(_LCD_SHIFT_RIGHT);
  31.     Move_Delay();
  32.   }

  33.   while(1) {                         // Endless loop
  34.     for(i=0; i<8; i++) {             // Move text to the left 7 times
  35.       Lcd_Cmd(_LCD_SHIFT_LEFT);
  36.       Move_Delay();
  37.     }

  38.     for(i=0; i<8; i++) {             // Move text to the right 7 times
  39.       Lcd_Cmd(_LCD_SHIFT_RIGHT);
  40.       Move_Delay();
  41.     }
  42.   }
  43. }
复制代码
附:简单电路图。





51-LCD16x2.jpg (41.75 KB, 下载次数: 64)

51-LCD16x2.jpg

作者: songxia8013    时间: 2018-10-14 17:00
这是个什么软件做的?没见过这个软件!
作者: oldspring    时间: 2018-10-15 09:37
http://www.51hei.com/bbs/dpj-136722-1.html






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