標(biāo)題: LMB162字符系列 基于AT89S52單片機(jī)的源代碼-拓普微LCM [打印本頁(yè)]

作者: xuan12321    時(shí)間: 2020-3-2 16:38
標(biāo)題: LMB162字符系列 基于AT89S52單片機(jī)的源代碼-拓普微LCM
還記得那個(gè)protus里面經(jīng)典的LCD 1602不?想當(dāng)年折騰了好久才點(diǎn)亮他;
為了讓大家方便點(diǎn)亮,把源碼貢獻(xiàn)出來,只要按照程序設(shè)置的IO口配置好原理圖,
然后用keil編譯產(chǎn)生hex文件,再把hex文件裝在在protus的單片機(jī)里,就可以點(diǎn)亮了,
.c源碼附上,動(dòng)動(dòng)手指你們也可以的!

有啥疑問可以寫在回復(fù)區(qū),有空了大家可以探討一下。

單片機(jī)源程序如下:
  1. #include <stdio.h>
  2. #include <reg52.h>
  3. #include <intrins.h>

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

  6. #define  LCDBUS P1
  7. sbit LCD_RS =P3^1;
  8. sbit LCD_RW =P3^7;
  9. sbit LCD_E  =P3^2;


  10. //-----------------------------------
  11. // dispaly data
  12. //-----------------------------------
  13. uchar code Logo1[]=
  14. {
  15. "TOPWAY  Char LCDM                       "
  16. "1234567890123456789012345678901234567890"
  17. };


  18. //-----------------------------------
  19. // Delay Routine
  20. //-----------------------------------
  21. void delayus(uint u)                        //delay routine
  22. {
  23.         uint i;
  24.         for(i=0;i<=u;i++)
  25.         {
  26.         _nop_();_nop_();
  27.         }
  28. }

  29. void delayms(uint m)
  30. {
  31.         uint j;
  32.         uint i;
  33.        
  34.         for(i=0; i<m; i++)
  35.             for(j=0; j<250; j++)
  36.                 _nop_();
  37. }

  38. //-----------------------------------
  39. // IO Routine
  40. //-----------------------------------
  41. void SdCmd(uchar command)                //send command
  42. {
  43.     LCD_E=0;
  44.     LCD_RW=0;
  45.     LCD_RS=0;
  46.     LCDBUS=command;
  47.     LCD_E=1;
  48.     _nop_();
  49.     _nop_();
  50.     _nop_();
  51.     LCD_E=0;
  52.     delayus(50);
  53. }

  54. void SdData(uchar DData)                //send data
  55. {
  56.     LCD_E=0;
  57.     LCD_RW=0;
  58.     LCD_RS=1;
  59.     LCDBUS=DData;
  60.     LCD_E=1;
  61.     _nop_();
  62.     _nop_();
  63.     _nop_();
  64.     LCD_E=0;
  65.     _nop_();
  66.     _nop_();
  67.     _nop_();
  68. }


  69. //-----------------------------------
  70. // Send a page of Display Data
  71. //-----------------------------------
  72. void SdPage(uchar *DisplayDataPtr)  // fill up a 40x2 DDRAM area
  73. {
  74.         uchar TempData;
  75.         uint i;

  76.         SdCmd(0x80);        // Set DDRAM Add ptr to 00h, 1st line
  77.         for(i=0;i<40;i++)
  78.         {
  79.              TempData=(*(DisplayDataPtr+i));
  80.                 SdData(TempData);
  81.         }
  82.         SdCmd(0xC0);        // Set DDRAM Add ptr to 40h, 2nd line
  83.         for(i=0;i<40;i++)
  84.         {
  85.              TempData=(*(DisplayDataPtr+i+40));
  86.         SdData(TempData);
  87.         }
  88. }

  89. //-----------------------------------
  90. // init
  91. //-----------------------------------
  92. void LCD_init()
  93. {
  94.         SdCmd(0x38);        //8bit I/F;2-linedisplay;5x8 font
  95.         SdCmd(0x04);        //No screen shifting
  96.         SdCmd(0x0c);        //Display on;cursor off;cursor-blinking off
  97.         SdCmd(0x01);    //clear screen
  98.         delayms(2);        //clear screen command takes more time
  99. }

  100. //-----------------------------------
  101. // Main Program
  102. //-----------------------------------
  103. void main()
  104. {
  105.           LCD_E=0;
  106.         LCD_RW=0;
  107.         LCD_RS=0;
  108.         LCDBUS=0x00;
  109.         SP=0x60;
  110.         EA = 0;                // disable interrupts
  111.         delayms(10);        // wait for LCD module power on reset

  112.         LCD_init();

  113.         SdPage(Logo1);

  114.         while(1);        //end of program
  115. }
復(fù)制代碼

所有資料51hei提供下載:
51單片機(jī)字符顯示源碼.rar (1019 Bytes, 下載次數(shù): 8)








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1