標(biāo)題: 字符液晶1602 proteus仿真測(cè)試 帶單片機(jī)程序 [打印本頁(yè)]

作者: 51黑ff    時(shí)間: 2016-10-8 23:32
標(biāo)題: 字符液晶1602 proteus仿真測(cè)試 帶單片機(jī)程序


仿真工程文件及所有完整程序等資料下載地址:
http://www.torrancerestoration.com/bbs/dpj-56304-1.html

  1. #include <REGX52.H>
  2. #include "LCD1602.h"

  3. unsigned char TempBuffer[10];
  4. void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
  5. {
  6.         unsigned char a[5]; char i, j;                                         
  7.         a[0]=(t/10000)%10;         //取得整數(shù)值到數(shù)組                 
  8.         a[1]=(t/1000)%10;                                             
  9.         a[2]=(t/100)%10;                                             
  10.         a[3]=(t/10)%10;                                               
  11.         a[4]=(t/1)%10;                                                
  12.                                                       
  13.         for(i=0; i<5; i++)         //轉(zhuǎn)成ASCII碼                     
  14.                 a[i]=a[i]+'0';                                            
  15.         for(i=0; a[i]=='0' && i<=3; i++);                             
  16.         for(j=5-n; j<i; j++)       //填充空格                        
  17.                 { *str=' ';  str++; }                                    
  18.         for(; i<5; i++)                                               
  19.                 { *str=a[i]; str++; }  //加入有效的數(shù)字                  
  20.         *str='\0';
  21. }

  22. void Delay1ms(unsigned int count)
  23. {
  24.         unsigned int i,j;
  25.         for(i=0;i<count;i++)
  26.         for(j=0;j<120;j++);
  27. }

  28. main()
  29. {
  30.         unsigned int Count = 0;
  31.         LCD_Initial();
  32.         GotoXY(0,0);
  33.         Print("The 1602LCD Test");
  34.         GotoXY(0,1);
  35.         Print("GO:       by JJJ");

  36.         while(1)
  37.         {
  38.                 IntToStr(Count++,&TempBuffer[0],5);
  39.                 GotoXY(3,1);
  40.                 Print(&TempBuffer[0]);
  41.                 Delay1ms(100);
  42.         }
  43. }
復(fù)制代碼








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