#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}; #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