• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:AVRマイコンでのコンパイルエラーについて)

AVRマイコンでのコンパイルエラーの解決方法

このQ&Aのポイント
  • AVRマイコンでのコンパイルエラーが発生し、(2)、(4)、(5)のSBI、CBI命令でエラー(Error: constant value required)が出る。
  • (1)と(3)でDATAの値をR16に受け渡したいが、方法がわからない。
  • AVRマイコン初心者が質問。エラー発生の理由とDATAの値の受け渡し方法を教えてほしい。

質問者が選んだベストアンサー

  • ベストアンサー
  • chie65535
  • ベストアンサー率43% (8536/19407)
回答No.1

>理由が全くわかりません。 「CBI、SBIは定数を要求する」がエラーの意味。 んで >asm("SBI PORTB,4");  ・・・・(2) >asm("CBI PORTB,4");  ・・・・(4) >asm("SBI PORTB,4");  ・・・・(5) って書いた場合「PORTBが何者であるか書いてない」ので「そこには定数を書けよ」って怒られる事になる。 このへん http://www9.plala.or.jp/fsson/NewHP_elc/AVR/Avr_100macroMemo.html を参考に、マクロで書くのが吉。

ron_nast
質問者

お礼

ご回答ありがとうございます。 参考にさせて頂きます。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • AVRマイコン UART動作異常

    AVRマイコンのATmega168にてPCとRS-232Cにてシリアル通信(UART)を行うと最初のスタートビット'L'が正常に出ず、スタートビット'L'の後すぐに'H'に戻ってその後データビットを送っています。2回目以降のスタートビットは正常に'L'が指定したボーレートの時間幅で出ており、問題はありません。最初のスタートビットが正常に出ない原因がわかりませんので教えてください。 システムクロック:1MHz(内部発振器のみ) ボーレート:4800bps データビット数:8bit ストップビット数:1bit パリティビット数:なし -------------------------------------------- #include <avr/io.h> #include <util/delay.h> #include <avr/pgmspace.h> #define sbi(addr,bit) addr |= (1<<bit) #define cbi(addr,bit) addr &= ~(1<<bit) void port_init(void){ PORTB = 0xFE; DDRB = 0xFF; asm("NOP"); } void uart_init(void){ sbi(DDRD,1); cbi(DDRD,0); asm("NOP"); } void uart_putchar(unsigned char c){ loop_until_bit_is_set(UCSR0A,UDRE0); // asm("NOP"); UDR0 = c; } void _delay_1s(void){ int i; for(i=0;i<100;i++){ _delay_ms(10); } } int main(void) { port_init(); uart_init(); UCSR0B = _BV(TXEN0); UCSR0C = 0b00000110; UBRR0H = (uint8_t)0; UBRR0L = (uint8_t)12; while(1) { uart_putchar(0b01011010); _delay_1s(); } return 0; } -----------------------------------------------

  • C言語でのコンパイルエラー

    初心者です。 非常に基本的な質問かもしれませんが、 ご回答いただけたらうれしいです。 void test1(unsigned char* data) { } void test2(unsigned char** data) { } int main(void) { unsigned char data1[6]; unsigned char data2[6][6]; test1(data1); test2(data2); } としてtest1はうまくいくのに、 test2はコンパイルエラーになります。 どっちもポインタになると思うのですが…。 また、unsigned char data2[6][6]を 他の関数の引数とする場合は どうすればよろしいのでしょうか? 宜しくお願いいたします。

  • dos.hについて

    outportbなどの関数を使用しようとして dos.hをインクルードしているのですが bccでコンパイルするとエラーをはきます。 原因がわかる方いれば教えてください。 下記にソースを載せています。 #include <dos.h > void outportb(unsigned int portid,unsigned char value){ _asm mov edx,portid _asm mov al,value _asm out de,al } エラーは エラー E2451 080311-1.c 6: 未定義のシンボル de(関数 outportb ) *** コンパイル中に 1 個のエラーが発生しました *** とでます。

  • R8Cマイコンの乗算

    R8C34Mを使っています。 例えば下記のコードを実行したら  unsigned long kai;  unsigned int xx;  unsigned int yy; xx = 0x07d0;  //10進で2000 yy = 0x0064;  //10進で100 kai = xx * yy; kaiは 0x30d40 となるはずが、0x0d40 でした。 kai = (unsigned long)xx * yy; と書き直したら、うまくいきました。 答えが2バイトを超えるのが分かっていたのでkaiはlong長にしました。 どうして右辺もキャストでlong長にしないといけないのでしょうか? また、下記のようにkaiをint長、xx,yyをchar長にした場合は、 kaiは意図する値の0x4e20 になりました。  unsigned int kai;  unsigned char xx;  unsigned char yy; xx = 0x00c8;  //10進で200 yy = 0x0064;  //10進で100 kai = xx * yy; どうして後者の場合はうまくできて、前者の場合はキャストしないといけないのでしょうか? この辺ご存知の方ご教授願います。

  • コンパイルに失敗します。(RaspberryPi)

    lwiringPiとOpenRTM-aistインストール済み ===コマンド===== gcc kasoku.c -lwiringPi =========== ======エラー=========== kasoku.c: In function ‘main’: kasoku.c:48:29: error: ‘rtc’ undeclared (first use in this function) kasoku.c:48:29: note: each undeclared identifier is reported only once for each function it appears in ========== ======ソースコード======== #include <stdio.h> #include <stdlib.h> #include <time.h> #include <unistd.h> #include <linux/i2c-dev.h> // I2C用インクルード #include <fcntl.h> #include <sys/ioctl.h> #include <wiringPi.h> // delay関数用にインクルード void L3GD20_readData(int *gyrodata, int fd); void L3GD20_write(unsigned char address, unsigned char data, int fd); unsigned char L3GD20_read(unsigned char address, int fd); void L3GD20_init(int fd); int main(int argc, char **argv) { int i2c_fd; // デバイスファイル用ファイルディスクリプタ // char *i2cFileName = "/dev/i2c-0"; // I2Cデバイスファイル名 char *i2cFileName = "/dev/i2c-1"; // RaspberryPiのリビジョンに合わせて変更 int i2cAddress = 0x6a; // L3GD20のI2Cアドレス int gyroData[3]; // ジャイロ3軸(x,y,z)データ格納用 printf("i2c Gyro(L3GD20) test program\n"); delay(500); // I2Cデバイスファイルをオープン if ((i2c_fd = open(i2cFileName, O_RDWR)) < 0) { printf("Faild to open i2c port\n"); exit(1); } // L3GD20用にセット if (ioctl(i2c_fd, I2C_SLAVE, i2cAddress) < 0) { printf("Unable to get bus access to talk to slave\n"); exit(1); } //デバイスイニシャライズ L3GD20_init(i2c_fd); // 1秒ごとに20回ジャイロデータを取得、表示 int i; for(i=0; i<20; i++){ // デバイスからデータ取得 L3GD20_readData(gyroData, rtc); // 取得したデータを校正して表示、1秒待ち printf("x, y, z : %5.2f, %5.2f, %5.2f\n",(float)gyroData[0]*0.00875,(float)gyroData[1]*0.00875,(float)gyroData[2]*0.00875); delay(1000); } return; } // L3GD20用 1バイト書き込みルーチン:addressで示すレジスタにdataを書き込む void L3GD20_write(unsigned char address, unsigned char data, int fd) { unsigned char buf[2]; buf[0] = address; buf[1] = data; if((write(fd,buf,2))!=2){ printf("Error writing to i2c slave\n"); exit(1);} return; } // L3GD20用 1バイト読み出しルーチン:addressで示すレジスタの値を読み出す // 戻り値がレジスタ値 unsigned char L3GD20_read(unsigned char address, int fd) { unsigned char buf[1]; buf[0] = address; if((write(fd,buf,1))!= 1){ // addressを一度書き込む所に注意 printf("Error writing to i2c slave\n"); exit(1);} if(read(fd,buf,1)!=1){ printf("Error reading from i2c slave\n"); exit(1);} return buf[0]; } // L3GD20用 ジャイロデータ読み出しルーチン:整数値配列へのポインタを使ってデータを受け渡す void L3GD20_readData(int *gyrodata, int fd) { unsigned char data[6]; // センサから3軸に対して2バイトずつデータを読み出す int i; for(i=0; i<6; i++){ data[i]=L3GD20_read(0x28+i,fd); } // 各数値を32bit幅の整数に整形する // センサの数値精度が16bit・2の補数表現での出力のため、シフトで加工 gyrodata[0]=((int)data[1]<<24|(int)data[0]<<16)>>16; gyrodata[1]=((int)data[3]<<24|(int)data[2]<<16)>>16; gyrodata[2]=((int)data[5]<<24|(int)data[4]<<16)>>16; return; } // L3GD20用 ジャイロデータイニシャライズルーチン void L3GD20_init(int fd) { unsigned char Data; printf("L3GD20 init seq. start\n"); // L3GD20 動作確認 // L3GD20の0x0fレジスタは常に0xd4にセットされているため動作確認ができる Data = L3GD20_read(0x0f,fd); if(Data != 0xd4){ printf("L3GD20 is not working\n"); exit(1);} delay(10); // レジスタへの書き込みチェックとイニシャライズを同時に行う printf("read OK, Now writing check...\n"); // 0x20レジスタに0x0fを書き込むことで動作させる L3GD20_write(0x20, 0x0f, fd); // 0x20レジスタに実際に0x0fが書かれたか確認 Data = L3GD20_read(0x20,fd); if(Data != 0x0f){ printf("Writing miss\n"); exit(1); } printf("Writing OK\n"); delay(10); return; } ===============

  • outportb関数について

    void outportb(unsigned int portid,unsigned char value){ _asm mov edx,portid _asm mov al,value _asm out dx,al } 上記のように outportb関数を定義してコンパイルすると 「問題が発生したため・・・・」 とウィンドウが開いて勝手に終了します。 アセンブラの部分を削除しコンパイルすると portid,valueの値が1度も使用されていないという警告が出ます。 dos.hをインクルードしても同じ結果でした。 原因はWindows XPはIOポートのアクセスする権限がないから なのでしょうか? またC++を使用していますので C++で解決法あれば教えてください。

  • PICマイコンで時間測定の方法を教えて!

    PICマイコン初心者です。時間を正確に測定して表示させたいのですが、時間を正確に測定する方法が分からず苦慮しています。教えてください。  デバイスはPIC16F877、プログラミング言語はMPLABに付属していた  Cコンパイラ(HI-TECH PICC Lite)です。 現在、考えてうまく動作していない記述を下記に示します。ご指摘頂きたく。  Buildは成功するのですが動作せず???? 私が考えていたのはRC0がLOWのときにdelay(100ms)をカウントしていき、 それをバイナリでPORTBに表示する方法です。 測定レンジは0.1 - 60secぐらいまでです。 ***************************************************************************** #include <pic.h> #define _XTAL_FREQ 16000000 __CONFIG(HS & DEBUGDIS & LVPDIS & BORDIS & PWRTEN & WDTDIS ); int main(void){ unsigned long T1 = 0 ; // iの変数設定 TRISC = 0b00000001 ; // RC0入力 その他は出力設定 TRISB = 0x00 ; // PORT B 出力 PORTC = 0xff    ; // PORTCをall 1を設定 PORTB = 0x00 ; // PORTBを"0"Resetする if ( RC0 == 1 ) { } else { __delay_ms(100) ; // 100ms wait T1++ ; // T1 = T1 + 1 PORTB = T1 ; } }

  • VC++でコンパイルエラーが出ますがお教えください。

    初心者で申し訳なくおもいます。 下記のソースでコンパイルエラーが出ます。 // CnstDst.cpp : アプリケーション用のエントリ ポイントの定義 // #include "stdafx.h" //CnstDst クラス定義 class CnstDst { char sDat[80]; public: CnstDst(char *s); ~CnstDst(); }; CnstDst cd1("テストです"); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: この位置にコードを記述してください。 MessageBox(NULL, "WinMainの入口", "WinMain", MB_OK); CnstDst cd2("テスト1"); MessageBox(NULL, "テスト2", "WinMain", MB_OK); return 0; } CnstDst::CnstDst(char *s) { lstrcpy(sDat, s); MessageBox(NULL, sDat, "コンストラクタ", MB_OK); } CnstDst::~CnstDst() { MessageBox(NULL, sDat, "デストラクタ", MB_OK); } コンパパイルエラーは下記です。 プロジェクト 'CnstDst - Win32 (WCE MIPSII_FP) Debug' 用の中間ファイルおよび出力ファイルを削除しています。 --------------------構成 : CnstDst - Win32 (WCE MIPSII_FP) Debug-------------------- リソースをコンパイル中... コンパイル中... StdAfx.cpp コンパイル中... CnstDst.cpp C:\Documents and Settings\中野\デスクトップ\テストフォルダ\CnstDst\CnstDst.cpp(22) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [14]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\Documents and Settings\中野\デスクトップ\テストフォルダ\CnstDst\CnstDst.cpp(24) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [9]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\Documents and Settings\中野\デスクトップ\テストフォルダ\CnstDst\CnstDst.cpp(31) : error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [80]' to 'unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\Documents and Settings\中野\デスクトップ\テストフォルダ\CnstDst\CnstDst.cpp(32) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [80]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\Documents and Settings\中野\デスクトップ\テストフォルダ\CnstDst\CnstDst.cpp(36) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [80]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast clmips.exe の実行エラー CnstDst.exe - エラー 5、警告 0 Microsoft eMbedded Visuai C++ Win32 WCE で行っております。

  • プロポからのパルス値解析ソースのコンパイルエラー(PICマイコン)

    プロポからのパルス値解析ソースのコンパイルエラー(PICマイコン) いつもこちらでお世話になっております。 さて下記ソースコードはプロポの1Chと2Chからの出力パルスを ポートA0、A1ピンより、読み込みPC画面でその値を 確認する為のコードのつもりですが、 コンパイルが成功出来ずエラー行の表示はないのですが、 HEXファイルが作成しないので、大変困っております。 使用コンパイラーはCCS社C(PCM版)、 PICは16F873Aを使用してます。 以下に、コードを記述します。 #include <16f873a.h> ====プリプロセッサ部分の記述は省略================= この部分の設定は既に、1Chのみ数値確認で実証済みを記述。 =============================================== void main() { int data,data1; set_tris_a(0x0f); setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256); while(1) { while (input(PIN_A0)); while (!(input(PIN_A0))); set_timer0(0); while (input(PIN_A0)); data = get_timer0(); printf("VALUE = %d\r\n",data); delay_ms(500); while (input(PIN_A1)); while (!(input(PIN_A1))); set_timer0(0); while (input(PIN_A1)); data1 = get_timer0(); printf("VALUE = %d\r\n",data1); delay_ms(500); } } 以上、while(1)コード内に構成上の問題があるのではと 思われますが何処にコンパイル上、無理が生じるのでしょうか? また、仮にこのコードでコンパイルが成功したとしても、 2つのチャンネルからの信号を読取る事が可能でしょうか? 目に留めて下さった方で、ご教示頂けるなら大変幸いです。 どうか宜しくお願いいたします。

  • 電源の制御法

    デバイスに電圧を印加するための電源の制御を、プログラミングを作成して行おうとしています。 PCと電源はパラレルポートでつながっています。 電源とデバイスはDサブコネクタでつながっています。 電源内でデバイスに印加する電圧を制御しています。 パラレルポートへのアクセスですが、PortTalkというドライバ を使用すればいいということは分かっていますが具体的に どう使用すればいいか教えてください。 また下記のソースが何言語で書かれているか、 これを理解するには何を(例:C言語、WINAPIなど)勉強すればいいかを教えてください。参考URLなどを教えていただければさらに助かります。 void outportb(unsigned int portid,unsigned char value){ _asm mov edx,portid _asm mov al,value _asm out dx,al 部分的にでもわかる方がいれば回答お願いします。