欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4002|回復(fù): 5
收起左側(cè)

單片機(jī)程序顯示缺失函數(shù)原型UsartConfiguration,LcdInit,LcdWriteCom,求思路

[復(fù)制鏈接]
ID:865578 發(fā)表于 2020-12-23 11:14 | 顯示全部樓層 |閱讀模式
  1. #include<reg51.h>
  2. void main()
  3. {
  4.         int temp;
  5.         int datas1[] = {0, 0, 0, 0, 0};

  6.         UsartConfiguration();
  7.         LcdInit();                         //初始化LCD1602
  8.         LcdWriteCom(0x85);        //寫(xiě)地址 80表示初始地址
  9.         LcdWriteData('C');
  10.         SETTEMP=32;
  11.         datas1[0]=SETTEMP/10;
  12.                 datas1[1]=SETTEMP%10;
  13.                 LcdWriteCom(0x80+0x40+9);
  14.                 LcdWriteData(datas1[0]+'0');        
  15.                 LcdWriteCom(0x80+0x40+10);
  16.                 LcdWriteData(datas1[1]+'0');        
  17.         while(1)
  18.         {
  19.                 temp=Ds18b20ReadTemp();
  20.                 LcdDisplay(temp);
  21.                 Delay1ms(1000);//1s鐘刷一次
  22.                 if(k1==0)
  23.                 {
  24.                 Delay1ms(10);
  25.                 SETTEMP=SETTEMP+1;
  26.                 Delay1ms(1000);//1s鐘刷一次
  27.                 datas1[0]=SETTEMP/10;
  28.                 datas1[1]=SETTEMP%10;
  29.                 LcdWriteCom(0x80+0x40+9);
  30.                 LcdWriteData(datas1[0]+'0');        
  31.                 LcdWriteCom(0x80+0x40+10);
  32.                 LcdWriteData(datas1[1]+'0');                        
  33.                 }
  34.                 if(k2==0)
  35.                 {
  36.                 Delay1ms(10);
  37.                 SETTEMP=SETTEMP-1;
  38.                 datas1[0]=SETTEMP/10;
  39.                 datas1[1]=SETTEMP%10;
  40.                 LcdWriteCom(0x80+0x40+9);
  41.                 LcdWriteData(datas1[0]+'0');        
  42.                 LcdWriteCom(0x80+0x40+10);
  43.                 LcdWriteData(datas1[1]+'0');        
  44.                 }
  45.         }
  46. }
  47. #include"temp.h"
  48. void Ds18b20WriteByte(unsigned char dat)
  49. {
  50.         unsigned int i,j;
  51.         for(j=0;j<8;j++)
  52.         {
  53.                 DSPORT=0;                        //每寫(xiě)入一位數(shù)據(jù)之前先把總線拉低1us
  54.                 i++;
  55.                 DSPORT=dat&0x01; //然后寫(xiě)入一個(gè)數(shù)據(jù),從最低位開(kāi)始
  56.                 i=6;
  57.                 while(i--); //延時(shí)68us,持續(xù)時(shí)間最少60us
  58.                 DSPORT=1;        //然后釋放總線,至少1us給總線恢復(fù)時(shí)間才能接著寫(xiě)入第二個(gè)數(shù)值
  59.                 dat>>=1;
  60.         }
  61. }
  62. unsigned char Ds18b20ReadByte()
  63. {
  64.         unsigned char byte,bi;
  65.         unsigned int i,j;        
  66.         for(j=8;j>0;j--)
  67.         {
  68.                 DSPORT=0;//先將總線拉低1us
  69.                 i++;
  70.                 DSPORT=1;//然后釋放總線
  71.                 i++;
  72.                 i++;//延時(shí)6us等待數(shù)據(jù)穩(wěn)定
  73.                 bi=DSPORT;         //讀取數(shù)據(jù),從最低位開(kāi)始讀取
  74.                 /*將byte左移一位,然后與上右移7位后的bi,注意移動(dòng)之后移掉那位補(bǔ)0。*/
  75.                 byte=(byte>>1)|(bi<<7);                                                  
  76.                 i=4;                //讀取完之后等待48us再接著讀取下一個(gè)數(shù)
  77.                 while(i--);
  78.         }                                
  79.         return byte;
  80. }
  81. void  Ds18b20ChangTemp()
  82. {
  83.         Ds18b20Init();
  84.         Delay1ms(1);
  85.         Ds18b20WriteByte(0xcc);                //跳過(guò)ROM操作命令                 
  86.         Ds18b20WriteByte(0x44);            //溫度轉(zhuǎn)換命令
  87. }
  88. void  Ds18b20ReadTempCom()
  89. {        
  90.         Ds18b20Init();
  91.         Delay1ms(1);
  92.         Ds18b20WriteByte(0xcc);         //跳過(guò)ROM操作命令
  93.         Ds18b20WriteByte(0xbe);         //發(fā)送讀取溫度命令
  94. }
  95. int Ds18b20ReadTemp()
  96. {
  97.         int temp=0;
  98.         unsigned char tmh,tml;
  99.         Ds18b20ChangTemp();                                 //先寫(xiě)入轉(zhuǎn)換命令
  100.         Ds18b20ReadTempCom();                        //然后等待轉(zhuǎn)換完后發(fā)送讀取溫度命令
  101.         tml=Ds18b20ReadByte();                //讀取溫度值共16位,先讀低字節(jié)
  102.         tmh=Ds18b20ReadByte();                //再讀高字節(jié)
  103.         temp=tmh;
  104.         temp<<=8;
  105.         temp|=tml;
  106.         return temp;
  107. }
  108. void LcdDisplay(int temp)          //lcd顯示
  109. {
  110.           unsigned char i, datas[] = {0, 0, 0, 0, 0}; //定義數(shù)組
  111.                 float tp;  

  112.           LcdWriteCom(0x80);                //寫(xiě)地址 80表示初始地址
  113.                 tp=temp;
  114.                 temp=tp*0.0625*100+0.5;        
  115.                 if((temp/100)>(SETTEMP-1))
  116.                 {
  117.                         beep=0;
  118.                 }
  119.                 else
  120.                 {
  121.                 beep=1;
  122.                 }
  123.                 //留兩個(gè)小數(shù)點(diǎn)就*100,+0.5是四舍五入,因?yàn)镃語(yǔ)言浮點(diǎn)數(shù)轉(zhuǎn)換為整型的時(shí)候把小數(shù)點(diǎn)
  124.                 //后面的數(shù)自動(dòng)去掉,不管是否大于0.5,而+0.5之后大于0.5的就是進(jìn)1了,小于0.5的就
  125.                 datas[1] = temp % 10000 / 1000;
  126.                 datas[2] = temp % 1000 / 100;
  127.                 datas[3] = temp % 100 / 10;
  128.                 datas[4] = temp % 10;
  129.                
  130.                
  131.                 str[0]=datas[1]+'0';
  132.                 str[1]=datas[2]+'0';
  133.                 str[2]='.';
  134.                 str[3]=datas[3]+'0';
  135.                 str[4]='T';
  136.                 str[5]=SETTEMP/10+'0';
  137.                 str[6]=SETTEMP%10+'0';
  138.                 str[7]='U';
  139.                 LcdWriteCom(0x80);                 //寫(xiě)地址 80表示初始地址
  140.                 LcdWriteData('t');        
  141.                 LcdWriteCom(0x81);                 //寫(xiě)地址 80表示初始地址
  142.                 LcdWriteData('e');        
  143.                 LcdWriteCom(0x82);                 //寫(xiě)地址 80表示初始地址
  144.                 LcdWriteData('m');
  145.                 LcdWriteCom(0x83);                 //寫(xiě)地址 80表示初始地址
  146.                 LcdWriteData('p');        
  147.                 LcdWriteCom(0x84);                 //寫(xiě)地址 80表示初始地址
  148.                 LcdWriteData(':');               
  149.                 LcdWriteCom(0x85);                 //寫(xiě)地址 80表示初始地址
  150.                 LcdWriteData('0'+datas[1]); //十位
  151.                 LcdWriteCom(0x86);                //寫(xiě)地址 80表示初始地址
  152.                 LcdWriteData('0'+datas[2]); //個(gè)位
  153.                 LcdWriteCom(0x87);                //寫(xiě)地址 80表示初始地址
  154.                 LcdWriteData('.');                 //顯示 ‘.’
  155.                 LcdWriteCom(0x88);                 //寫(xiě)地址 80表示初始地址
  156.                 LcdWriteData('0'+datas[3]); //顯示小數(shù)點(diǎn)  
  157.                 LcdWriteCom(0x89);                 //寫(xiě)地址 80表示初始地址
  158.                 LcdWriteData('C'); //顯示小數(shù)點(diǎn)
  159.                 LcdWriteCom(0x80+0x40);                 //寫(xiě)地址 80表示初始地址
  160.                 for(i=0;i<=8;i++)
  161.                                 {
  162.                                         LcdWriteData(CNCHAR[i]);
  163.                                 }
  164.                 LcdWriteCom(0x80+0x40+13);
  165.                 LcdWriteData('C');               
  166. //                datas1[0]=SETTEMP/10;
  167. //                datas1[1]=SETTEMP%10;
  168. //                LcdWriteCom(0x80+0x40+9);
  169. //                LcdWriteData(datas1[0]+'0');        
  170. //                LcdWriteCom(0x80+0x40+10);
  171. //                LcdWriteData(datas1[1]+'0');        
  172.                 LcdWriteCom(0x80+0x40+11);
  173.                 LcdWriteData('.');        
  174.                 LcdWriteCom(0x80+0x40+12);
  175.                 LcdWriteData('0');
  176.                 }
  177. //串口配置
  178.         SCON &= (uint8_t)((uint8_t)( ~( UART_MODE | UART_RX )));        //清SM0 SM1 REN
  179.         SCON |= (uint8_t)( UART_8BAUDRATE_VOLATILE | UART_RX );
  180.         
  181.         //TIM1配置
  182.         TMOD &= (uint8_t)((uint8_t)( ~TIM1_MODE ));
  183.         TMOD |= TIM1_MODE_2;        //8位自動(dòng)重裝
  184.         PCON = 0x00;
  185.         TH1 = 0xFD;                                //波特率默認(rèn)配置為9600
  186.         TL1 = 0xFD;
  187.         
  188.         TI = 1;                                        //清發(fā)送標(biāo)志                                                
  189.         TR1 = 1;                                //使能定時(shí)器
  190. }
  191. uint8_t drv_uart_rx_bytes( uint8_t* RxBuffer )
  192. {
  193.         uint8_t l_RxLength = 0;
  194.         uint16_t l_UartRxTimOut = 0x7FFF;
  195.         
  196.         while( l_UartRxTimOut-- )                //在超時(shí)范圍內(nèi)檢測(cè)數(shù)據(jù)
  197.         {
  198.                 if( 0 != RI )                                //檢測(cè)是否接收到數(shù)據(jù)
  199.                 {
  200.                         RI = 0;                                        //清標(biāo)志位               
  201.                         *RxBuffer = SBUF;                //讀數(shù)據(jù)
  202.                         RxBuffer++;
  203.                         l_RxLength++;
  204.                         l_UartRxTimOut = 0x7FFF;//重置超時(shí)檢測(cè)
  205.                 }
  206.         }
  207.         return l_RxLength;                        //等待超時(shí),數(shù)據(jù)接收完成
  208. }
復(fù)制代碼
51hei圖片20201223111356.png
回復(fù)

使用道具 舉報(bào)

ID:854384 發(fā)表于 2020-12-23 14:07 | 顯示全部樓層
程序里面LCD函數(shù)沒(méi)有定義完,顯示的應(yīng)該是程序缺失,添加一個(gè)頭文件,里面定義LCDwrite等函數(shù)
回復(fù)

使用道具 舉報(bào)

ID:824490 發(fā)表于 2020-12-23 14:17 | 顯示全部樓層
你把void main()這個(gè)函數(shù)放到主C文件的最末就OK了
或者把主C文件中的所有函數(shù)(main()除外)的函數(shù)名copy到C文件的#include段之后,MAIN()之前。
或者另寫(xiě)一個(gè)MAIN.H文件,把這些函數(shù)名聲明一次。在主C文件中再include這個(gè)H文件。
回復(fù)

使用道具 舉報(bào)

ID:824490 發(fā)表于 2020-12-23 14:19 | 顯示全部樓層
上一條回復(fù)錯(cuò)了,應(yīng)該是你的主C文件沒(méi)有include到LCD.C的頭文件
回復(fù)

使用道具 舉報(bào)

ID:739545 發(fā)表于 2020-12-23 14:37 | 顯示全部樓層
把函數(shù)放到main函數(shù)前面去
回復(fù)

使用道具 舉報(bào)

ID:822755 發(fā)表于 2020-12-23 23:48 | 顯示全部樓層
看函數(shù)名,應(yīng)該是串口設(shè)置,液晶初始化,寫(xiě)數(shù)據(jù)到液晶。這些都可以根據(jù)手冊(cè)自己完成。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表