[問題] 請教程式設計

看板ASM (組合語言)作者 (無盡深淵、寂靜虛空)時間9年前 (2016/06/03 13:50), 9年前編輯推噓4(407)
留言11則, 4人參與, 最新討論串1/1
小弟在arduino平台上做些小東西 我的程度沒有很高 有一個問題想請教各位 我有兩個獨立的程式想要合併 函式庫都有 獨立編譯可以過 我整合一起就GG了 可能port上會衝突 請問要怎麼解決? 那些部份需要修改嗎? 請具體一點 因為我程度不高... 謝謝各位 先附我整合的程式碼 #include <i2cmaster.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); const float lowReading = 60; const float highReading = 75; const unsigned char separatorCharacter = 255; void setup() { pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); Serial.begin(9600); i2c_init(); PORTC = (1 << PORTC2) | (1 << PORTC3); Serial.println("completed setup"); lcd.begin(16, 2); for(int i = 0; i < 3; i++) { lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); } lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello, world!"); delay(1000); lcd.setCursor(0, 1); lcd.print("fuck up"); delay(8000); lcd.clear(); } float normf(float x, float low, float high) { float y = (x - low) * 255.f / (high - low); if (y > 255) { y = 255; } if (y < 0) { y = 0; } return y; } void loop() { int dev = 0x5A << 1; int data_low = 0; int data_high = 0; int pec = 0; i2c_start_wait(dev + I2C_WRITE); i2c_write(0x07); i2c_rep_start(dev + I2C_READ); data_low = i2c_readAck(); data_high = i2c_readAck(); pec = i2c_readNak(); i2c_stop(); double tempFactor = 0.02; double tempData = 0x0000; int frac; tempData = (double)(((data_high & 0x007F) << 8) + data_low); tempData = (tempData * tempFactor) - 0.01; float celcius = tempData - 273.15; float fahrenheit = (celcius * 1.8) + 32; float state = normf(fahrenheit, lowReading, highReading); Serial.print(celcius); Serial.print(" degrees C,"); Serial.print(fahrenheit); Serial.println(" degrees F"); lcd.setCursor(0, 0); lcd.print(celcius); lcd.print(" degrees C"); lcd.setCursor(0, 1); lcd.print(fahrenheit); lcd.print(" degrees F"); int r, g, b = 0; if (fahrenheit > 92) { r = 0; g = 1; b = 1; } else if (fahrenheit > 83) { r = 1; g = 0; b = 1; } else { r = 1; g = 1; b = 0; } int red = constrain((int)255 * r, 0, 255); int green = constrain((int)255 * g, 0, 255); int blue = constrain((int)255 * b, 0, 255); setLedColor(red, green, blue); } void setLedColor(int r, int g, int b) { analogWrite(8, r); analogWrite(9, g); analogWrite(10, b); } 以下是錯誤訊息 Arduino:1.6.9 (Windows 10), 板子:"Arduino/Genuino Uno" libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `i2c_init()': C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/ SoftI2CMaster.h:267: multiple definition of `i2c_init()' libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\ Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half': C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/ SoftI2CMaster.h:196: multiple definition of `i2c_start(unsigned char)' libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\ Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half': C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/ SoftI2CMaster.h:196: multiple definition of `i2c_rep_start(unsigned char)' libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\ Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here libraries\NewliquidCrystal\SI2CIO.cpp.o: In function `ass_i2c_delay_half': C:\Users\sha-nb\Documents\Arduino\libraries\NewliquidCrystal/ SoftI2CMaster.h:196: multiple definition of `i2c_start_wait(unsigned char)' libraries\ThermalFlashlight\twimaster.cpp.o:C:\Users\sha-nb\Documents\ Arduino\libraries\ThermalFlashlight/twimaster.cpp:31: first defined here collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board Arduino/Genuino Uno. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. 不好意思有點雜亂 謝謝各位 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.61.28.227 ※ 文章網址: https://www.ptt.cc/bbs/ASM/M.1464933014.A.6AC.html

06/03 15:25, , 1F
...先學著看錯誤訊息
06/03 15:25, 1F

06/03 15:25, , 2F
multiple definition of `i2c_init()'
06/03 15:25, 2F

06/03 15:26, , 3F
你有兩個一樣的函式 他問你要call哪一個
06/03 15:26, 3F

06/03 15:27, , 4F
下面基本上都是同類型錯誤
06/03 15:27, 4F
一樣的是指名稱一樣 但功能不一樣? 還是完全一樣? 所以我去函式庫砍掉一個就好了嗎? ※ 編輯: shan83 (61.230.53.137), 06/03/2016 17:02:27

06/03 17:40, , 5F
名稱 把他註解掉雖然不是好方法.但你可以試試看
06/03 17:40, 5F

06/03 17:41, , 6F
不過運作起來會怎樣我也不肯定
06/03 17:41, 6F
好的 謝謝 ※ 編輯: shan83 (61.230.53.137), 06/03/2016 22:29:02

06/04 21:15, , 7F
看起來就SoftI2CMaster裡面出包了.
06/04 21:15, 7F

06/04 21:16, , 8F
如果都引用同樣的函示庫,整合前應該也會出包吧
06/04 21:16, 8F

06/05 11:10, , 9F
整合前沒問題耶
06/05 11:10, 9F

06/05 22:05, , 10F
把第一個i2cmaster拿掉,編譯後再把缺的補回來
06/05 22:05, 10F

06/06 02:58, , 11F
好哦我試試,謝謝
06/06 02:58, 11F
文章代碼(AID): #1NKHgMQi (ASM)
文章代碼(AID): #1NKHgMQi (ASM)