找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2891|回復: 7
打印 上一主題 下一主題
收起左側

單片機程序編譯出現(xiàn)一大堆錯誤

[復制鏈接]
跳轉到指定樓層
樓主
ID:854138 發(fā)表于 2020-12-7 16:27 來自手機 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
50黑幣
這是什么意思?幫忙改一下

這是程序和仿真圖
#include <reg51.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define BUS PORTC
// Low level port/pin definitions         低級端口/引腳定義
#define sbit(x,PORT) (PORT) |= (1<<x)
#define cbit(x,PORT) (PORT) &= ~(1<<x)
#define pin(x,PIN) (PIN) & (1<<x)
// Pins definition          引腳定義
#define s_digit1 sbit(5,PORTC)
#define c_digit1 cbit(5,PORTC)
#define s_digit2 sbit(4,PORTC)
#define c_digit2 cbit(4,PORTC)
#define out PORTC
#define DQ_IN DDRA&=~(1<<7)
#define DQ_OUT DDRA|=(1<<7)
#define S_DQ sbit(7,PORTA)
#define C_DQ cbit(7,PORTA)
#define DQ pin(7,PINA)
// Function Prototypes           函數(shù)原型
void init_ds18b20(void);
uchar readbyte(void);
void writecommand(uchar);
uchar readtemp(void);
uchar a, b, tt;
// Main program          主函數(shù)
int main(void)
{ uchar i=0, temp;
// Initialize Stack Pointer          初始化堆棧指針
SPL=0x54;
SPH=0x04;
// Configure port pins   配置端口引腳
DDRC = 0xff;
DDRA = 0xff;
while(1)
{ temp = readtemp();
for(i=0; i<10; i++) // 10 measures
{ // output the units        輸出的單位
out = (temp/10) & 0x0f;
s_digit1;
c_digit2;
_delay_ms(5);
// output the tens         輸出十
out = (temp%10) & 0x0f;
c_digit1;
s_digit2;
_delay_ms(5);
}
}
}
// Start transaction with 1-wire line.          用單線啟動事務
void init_ds18b20(void)
{ DQ_OUT;
C_DQ ;
_delay_us(600);
S_DQ;
_delay_us(50);
DQ_IN;
while(DQ);
_delay_us(240);
DQ_OUT;
S_DQ;
_delay_us(300);
}
// Read a byte from the sensor        從傳感器讀取一個字節(jié)
uchar readbyte(void)
{ uchar i = 0,data = 0;
DQ_OUT;
for (i=0; i<8; i++)
{ C_DQ ;
data >>= 1;
_delay_us(3);
S_DQ;
DQ_IN;
_delay_us(12);
if(DQ)
data |= 0x80;
DQ_OUT;
S_DQ;
_delay_us(45);
_delay_us(5);
}
return(data);
}
// Write a command to the sensor  向傳感器寫入命令
void writecommand(uchar data)
{ uchar i;
for(i=0; i<8; i++)
{ C_DQ;
_delay_us(15);
if(data & 0x01)
S_DQ;
else
C_DQ;
_delay_us(45);
data >>= 1;
S_DQ;
_delay_us(2);
}
}
// Read value from the sensor        從傳感器讀取值
uchar readtemp(void)
{ uint t;
init_ds18b20();
// Convert          轉換
writecommand(0xCC);
writecommand(0x44);
init_ds18b20();
// Read Scratch memory area                讀暫存區(qū)
writecommand(0xCC);
writecommand(0xBE);
a = readbyte();
b = readbyte();
t = b;
t <<= 8;
t = t|a;
tt = t*0.0625;
return(tt);
}

最佳答案

查看完整內容

這是avr的程序,你用了51的頭文件。當然都是錯的。 應該包含這個 #include "avr/io.h"
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:831625 發(fā)表于 2020-12-7 16:27 | 只看該作者
這是avr的程序,你用了51的頭文件。當然都是錯的。 應該包含這個 #include  "avr/io.h"

評分

參與人數(shù) 1黑幣 +12 收起 理由
南風1closu + 12 贊一個!

查看全部評分

回復

使用道具 舉報

板凳
ID:328014 發(fā)表于 2020-12-8 01:45 | 只看該作者
這估計是頭文件的問題,看看第一個錯誤是什么?

評分

參與人數(shù) 1黑幣 +9 收起 理由
南風1closu + 9 贊一個!

查看全部評分

回復

使用道具 舉報

地板
ID:517466 發(fā)表于 2020-12-8 13:27 | 只看該作者
reg51.h中并沒有SPL、SPH這樣的寄存器定義啊?醇拇嫫髀暶,類似DDRA, PORTC這樣的寄存器好像是AVR Atmega里的,不是51系列的啊。你是不是引用了錯誤的頭文件?

評分

參與人數(shù) 1黑幣 +11 收起 理由
南風1closu + 11 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

5#
ID:854138 發(fā)表于 2020-12-8 20:44 | 只看該作者
關于這個圖的程序能寫出來嗎?
回復

使用道具 舉報

6#
ID:854138 發(fā)表于 2020-12-8 20:48 | 只看該作者
能不能寫一個關于這個圖的程序
回復

使用道具 舉報

7#
ID:854138 發(fā)表于 2020-12-8 20:49 | 只看該作者
ch14691612 發(fā)表于 2020-12-7 16:27
這是avr的程序,你用了51的頭文件。當然都是錯的。 應該包含這個 #include  "avr/io.h"

能不能寫一個關于這個圖片的程序
回復

使用道具 舉報

8#
ID:88256 發(fā)表于 2020-12-8 20:57 | 只看該作者
建議樓主通讀并理解程序里每行的作用,自己更改錯誤而不是靠他人,更不要靠別人寫程序,這樣對自己的進步很有幫助

評分

參與人數(shù) 1黑幣 +5 收起 理由
南風1closu + 5

查看全部評分

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表