• 追加された行はこの色です。
  • 削除された行はこの色です。
#freeze
 閲覧総計:&counter();  (本日:&counter(today);  昨日:&counter(yesterday);)
 
 *A/D値でLED点滅間隔変更 [#d667f35f]
 
 【目次】(項目をクリックすると飛べます)
 #contents
 ~
 「A/D変換」を利用した簡単なプログラムを作成し、18F2320の「A/D変換」機能の利用法、
 稼働を確認しました。
 
 A/D変換値(0〜1023)を用いて発光ダイオード(LED)の点滅間隔を0msec〜1023msec
 にスムーズに変化させる。 07/10/06
 
 ※C18のプログラムを追記した。 08/08/31
 
 |&attachref(P1010554.JPG,zoom,150x150,button){新しい写真添付};|&attachref(,zoom,150x150,button){新しい写真添付};|
 
 *Mikro Cのプログラム [#caec292c]
  /**
  * 18F2320 アナログ入力テスト 0-5V入力−LED点滅時間
  * A/D値で発光ダイオード(LED)の点滅間隔を変更する
  *
  * PIC18F2320
  *
  * A/D: RA1(AN1) (10KΩ半固定抵抗で分圧しアナログ値を生成)
  * LED: RC1
  *
  *Clock: 8.0MHz 内蔵発振器使用
  *Device Flags:
  * _INTIO2_OSC_1H _WDT_OFF_2H _MCLRE_OFF_3H _LVP_OFF_4L
  * (その他はデフォルト設定でOK)
  *
  * MikroC v7.0.0.3
  */
  void main()
  {
      unsigned int temp; //使用変数の定義
  
      //PICの初期化
      PORTA = 0b00000000; //PORTAの中身をきれいにする
      PORTC = 0b00000000; //PortCの中身をきれいにする
      OSCCON = 0b01110000; //内蔵発信機 8MHz使用に設定
      //A/D変換clock設定 0.125us*16倍=2.0us
      ADCON2.ADCS2=1;
      ADCON2.ADCS1=0;
      ADCON2.ADCS0=1;
      TRISA = 0b00000010; //RA1のみ1:入力に設定、他は0:出力
      TRISC = 0b00000000; //PortC 8個全て0:出力設定
      //マイコンの初期化終わり
  
      do
      {
          //アナログデータの取得 10bit(0~1023)
          temp = ADC_Read(1); //RA1(AN1)アナログ入力
  
          //LED点滅間隔が0-1023msecで滑らかに変更出来る
          PORTC.F1 = 1;
          VDelay_ms(temp);
          PORTC.F1 = 0;
          VDelay_ms(temp);
      } while(1);
  }
 
 ★この情報は役に立ちましたか?
 #vote(はい[4],いいえ[2])
 - interesting work thx i love your site <a href=" http://community.vh1.com/Post/youporno/052C98A01018AC9520008009FD88B ">eskimo tube</a> +))) <a href=" http://community.vh1.com/Post/hq-tube/052C98A01018AC9520008009FD899 ">x tube</a> -- [[pornhub]] &new{2008-09-08 (月) 16:40:22};
 - good site nice work thanks <a href=" http://community.vh1.com/Post/pornotube/052C98A01018AC9520008009FD420 ">sextube</a> ;)) <a href=" http://community.vh1.com/Post/red-tube/052C98A01018AC9520008009FD849 ">zootube</a> -- [[pornotube]] &new{2008-09-08 (月) 16:41:06};
 - nice work thx bookmark you <a href=" http://community.vh1.com/Post/pornhube/052C98A01018AC9520008009FD8D1 ">porno hub</a> 0)) <a href=" http://community.vh1.com/Post/porntube/052C98A01018AC9520008009FD8D2 ">hqtube</a> -- [[pornhube]] &new{2008-09-08 (月) 22:52:31};
 - cool site great work thx <a href=" http://community.vh1.com/Post/xvideos/052C98A01018AC9520008009FD8C9 ">pornhube</a> ')) <a href=" http://community.vh1.com/Post/tube-8/052C98A01018AC9520008009FD8CF ">pornos</a> -- [[xvideos]] &new{2008-09-08 (月) 22:52:45};
 - interesting post thanks dude see u <a href=" http://community.vh1.com/Post/uporn/052C98A01018AC9520008009FD8BB ">pornos</a> +)) <a href=" http://community.vh1.com/Post/nexxx/052C98A01018AC9520008009FD8C3 ">red tube</a> -- [[uporn]] &new{2008-09-08 (月) 22:53:03};
 - gdfgdfg dsfg hgh df gh <a href=" http://community.vh1.com/Post/pornotub/052C98A01018AC9520008009FD8D4 ">porno tv</a> gfd hgfh dfghdgfh dgf <a href=" http://community.vh1.com/Post/pornotv/052C98A01018AC9520008009FD8E1 ">x tube</a> -- [[pornotube]] &new{2008-09-09 (火) 05:47:10};
 - gdf gdfh gh dfhdgfh  fdh <a href=" http://community.vh1.com/Post/hot-tube/052C98A01018AC9520008009FD936 ">beast tube</a>  fdgdsfgg gdsfg gdfg dfsgh dgsh <a href=" http://community.vh1.com/Post/boob-tube/052C98A01018AC9520008009FD93B ">uporn</a> -- [[xtube]] &new{2008-09-09 (火) 05:48:54};
 - hgfh dfgf hds gh dfhg dfh <a href=" http://community.vh1.com/Post/youporn/052C98A01018AC9520008009FD8FB ">porn hub</a> gdf hgdgfh hdgh fghfg <a href=" http://community.vh1.com/Post/pornohub/052C98A01018AC9520008009FD908 ">eskimo tube</a> -- [[pornotub]] &new{2008-09-09 (火) 05:49:13};
 - hgf hfd hjhgdj sd hgfh dfg <a href=" http://community.vh1.com/Post/hqtube/052C98A01018AC9520008009FD921 ">porn hub</a> hgfh fgh fgh fgdh f  <a href=" http://community.vh1.com/Post/porn-hub/052C98A01018AC9520008009FD924 ">zoo tube</a> -- [[nudetube]] &new{2008-09-09 (火) 05:49:24};
 - hgfh  hjgdj hgj hgfj g <a href=" http://community.vh1.com/Post/porno-tube/052C98A01018AC9520008009FD93C ">tube8</a> hgfh dfgh dgfh  hgfh <a href=" http://community.vh1.com/Post/eskimo-tube/052C98A01018AC9520008009FD93E ">youporn</a> -- [[eskimotube]] &new{2008-09-09 (火) 16:51:35};
 - dfhfdg hdf hjgdgf fhjf fgjhf gjh  <a href=" http://community.vh1.com/Post/beast-tube/052C98A01018AC9520008009FD94C ">porn hub</a> gdfgdsfg sdg dsfg <a href=" http://community.vh1.com/Post/porn-hub/052C98A01018AC9520008009FD950 ">porn hub</a> -- [[youporn]] &new{2008-09-09 (火) 16:53:43};
 - ggh dfhdh jhg jgfj gfhj fg hj g <a href=" http://community.vh1.com/Post/porno-tv/052C98A01018AC9520008009FD965 ">porno hub</a> dfg dfg  <a href=" http://community.vh1.com/Post/pornos/052C98A01018AC9520008009FD971 ">nude tube</a> df g dh dgfh dfgh <a href=" http://community.vh1.com/Post/porno-hub/052C98A01018AC9520008009FD989 ">sextube</a> fd gdgsh dgfh d <a href=" http://community.vh1.com/Post/redtub/052C98A01018AC9520008009FD994 ">porno tube</a> d hg fgh dfgh dfgh f <a href=" http://community.vh1.com/Post/youtubeporno/052C98A01018AC9520008009FD99A ">pornos</a>  -- [[nexxx]] &new{2008-09-09 (火) 17:01:57};
 - sweet site thanks ;)) <a href=" http://youporno.u.yuku.com/ ">pornhub</a> ))) <a href=" http://hqtubez.u.yuku.com/ ">x tube</a> -- [[pornhub]] &new{2008-09-10 (水) 19:37:22};
 - great site great work thanks <a href=" http://pornotubez.u.yuku.com ">redtube</a> =) <a href=" http://redtubez.u.yuku.com ">tube8</a> -- [[pornotube]] &new{2008-09-10 (水) 19:38:09};
 - interesting post thx bookmark you <a href=" http://tube8z.u.yuku.com/ ">boob tube</a> 0)))) <a href=" http://xtubez.u.yuku.com/ ">pornotube</a> -- [[youporno]] &new{2008-09-10 (水) 19:38:17};
 - cool site dude thanks <a href=" http://youporne.u.yuku.com/ ">nexxx</a> '))) <a href=" http://sextubez.u.yuku.com/ ">porno hub</a> -- [[youporno]] &new{2008-09-11 (木) 00:23:27};
 - wow cool site man 10x )) <a href=" http://xvideos.u.yuku.com/ ">animal sex tube</a> --))) <a href=" http://tube8zz.u.yuku.com/ ">tube8</a> -- [[xvideos]] &new{2008-09-11 (木) 00:25:25};
 - nice post dude thanks see u <a href=" http://pornhube.u.yuku.com/ ">x tube</a> ;))) <a href=" http://porntubez.u.yuku.com/ ">animal sex tube</a> -- [[hqtube]] &new{2008-09-11 (木) 00:25:40};
 - cool work good site dude <a href=" http://uporn.u.yuku.com/ ">pornhub</a> +))) <a href=" http://nexxx.u.yuku.com/ ">eskimo tube</a> -- [[nexxx]] &new{2008-09-11 (木) 00:26:11};
 - nice work cool site =) <a href=" http://hqtubezz.u.yuku.com/ ">nude tube</a> 8)) <a href=" http://pornhubzz.u.yuku.com/ ">youporno</a> -- [[xtube]] &new{2008-09-11 (木) 06:03:31};
 - i like your site thx <a href=" http://pornotub.u.yuku.com/ ">porno tube</a> and <a href=" http://pornotv.u.yuku.com/ ">redtube</a> -- [[boobtube]] &new{2008-09-11 (木) 06:04:55};
 - cool post man thanks bookmark you <a href=" http://youpornz.u.yuku.com/ ">youporn</a> 9))) <a href=" http://pornohub.u.yuku.com/ ">tube8</a> -- [[eskimotube]] &new{2008-09-11 (木) 06:05:29};
 - nice work cool site 10x see u <a href=" http://hottube.u.yuku.com/ ">xtube</a> ')) <a href=" http://boobtubez.u.yuku.com/ ">x tube</a> -- [[hottube]] &new{2008-09-11 (木) 06:08:14};
 - hgh h hfgh fdgh dsfs ghgfh fdgh <a href=" http://pornotubezz.u.yuku.com/ ">youtubeporno</a> gfdg dfh dgfh dgfh dgfh fgh <a href=" http://eskimotube.u.yuku.com/ ">eskimo tube</a> -- [[pornotub]] &new{2008-09-11 (木) 17:59:07};
 - g ghfd hfdg jhgfj dfg jhgj dg jgfhj hgf j <a href=" http://pornotvz.u.yuku.com/ ">youtubeporno</a> gdf hfhg dh dfg hdfg hdfhgs <a href=" http://pornos.u.yuku.com/ ">uporn</a> -- [[nexxx]] &new{2008-09-11 (木) 17:59:44};
 - g ghfd hfdg jhgfj dfg jhgj dg jgfhj hgf j <a href=" http://pornotvz.u.yuku.com/ ">youtubeporno</a> gdf hfhg dh dfg hdfg hdfhgs <a href=" http://pornos.u.yuku.com/ ">uporn</a> -- [[nexxx]] &new{2008-09-11 (木) 18:00:19};
 
 #comment
 
 *C18のプログラム [#cf6e87f6]
  /**
  * 18F2320の稼働テスト アナログ値の取得
  * A/D値で発光ダイオード(LED)の点滅間隔を変更する
  *
  * A/D:RA1 (10KΩ半固定抵抗で分圧しアナログ値を生成)
  * LED:RC1
  * Clock: 8.0MHz 内蔵発振器使用
  *
  * C18 StudentEdition v3.12
  */
  #include <p18f2320.h>
  #include <adc.h>
  #include <delays.h>
  
  //config設定
  #pragma config OSC = INTIO2 //内部発振器を利用
  #pragma config WDT = OFF //ウォッチドッグタイマOFF
  #pragma config MCLRE = OFF //MCLRをOFFし、RE3として利用
  #pragma config DEBUG = OFF //デバッグ可にし、RB6,RB7はICD用に利用
  #pragma config LVP = OFF //低電圧ICSP制御OFF
  //その他のconfigはデフォルト設定のまま
  
  //関数のプロトタイプ宣言
  void my_delay_ms(unsigned int x); //at 8MHz
  
  void
  main(void)
  {
      //使用変数の定義
      int result; //A/D値(10bit)の受け
      
      //PICの初期化
      OSCCON = 0b01110000; //内蔵発振器を8MHz使用に設定
      TRISA = 0b00000010; //PortAのRA1を1:入力に他は0:出力に設定    
      TRISC = 0b00000000; //PortC 8個全て0:出力設定
  	
      OpenADC( //第1引数
               ADC_FOSC_16 & //AD変換用クロック:システムクロックの16倍 0.125μsec*16=2.0μsec
               ADC_RIGHT_JUST & //変換結果の保存方法 右詰め
               ADC_0_TAD, //AD変換のアクイジションタイム選択 0Tad 
               //第2引数
               ADC_CH1 & //AD変換するのチャンネル選択(PIC18Fは同時に複数のAD変換はできない) 
               ADC_INT_OFF & //AD変換での割込み使用の有無 割込み無し
               ADC_VREFPLUS_VDD & //Vref+の設定 PICの電源電圧と同じ:ADC_VREFPLUS_VDD or 外部(AN3)の電圧:ADC_VREFPLUS_EXT
               ADC_VREFMINUS_VSS, //Vref-の設定 PICの0V:ADC_VREFMINUS_VSS or 外部(AN2)の電圧:ADC_VREFMINUS_EXT
               //第3引数
               0b0000); //ポートのアナログ・デジタル選択 (ADCON1の下位4ビットを記載) AN0-AN12全てアナログ使用
      Delay10TCYx( 5 ); //50TCY待つ
  
      while (1)
      {
           ConvertADC(); //AD変換実行
           while( BusyADC() ); //AD変換が終わるまで待つ
           result = ReadADC(); //AD変換値(10bit)読込み
  
           LATCbits.LATC1 = 1; //LED ON
           my_delay_ms(result);
           LATCbits.LATC1 = 0; //LED OFF
           my_delay_ms(result);
       }
  }
  
  void
  my_delay_ms(unsigned int x) //at 8MHz
  {
      while (x)
      {
          Delay1KTCYx(2); //1mS遅延 at 8MHz
          x--;
      }
  }
 
 ★この情報は役に立ちましたか?
 #vote(はい[0],いいえ[0])
 
 #comment