閲覧総計:23932  (本日:1  昨日:1)

スイッチ入力(12F683)

12F683(8ピンPIC)でスイッチ入力(スイッチのオン(ON)、オフ(OFF)信号をPICに取り込む)
を実現する場合、多くの項目の初期設定を行う必要がある。
その実例を紹介します。  07/02/12

1.内部発振器を8MHzで使用
2.各ピンをデジタル入出力で使用
  ANSEL = 0b00000000; //GP0-5をデジタル利用に設定
  CMCON0 = 0b00000111; //コンパレータを使わない
3.信号入力ピンを内部プルアップする
  OPTION_REG.NOT_GPPU = 0; //内部プルアップ利用に設定
  WPU = 0b00000100; //GP2を内部プルアップ

P1010295.JPG
/**
* スイッチ入力
* (スイッチを押している間だけON、はなすとOFF)
*
* LED: GP4  スイッチ: GP2
*Clock: 8.0MHz 内蔵発振器使用
*Device Flags:
* _CP_OFF  _MCLRE_OFF _PWRTE_ON _WDT_OFF _INTRC_OSC_NOCLKOUT
*
* MikroC v2.1
*/
void main() {
    TRISIO = 0b00000100; //GP2を1:入力に、他を0:出力設定
    //内蔵発振器 8MHz使用に設定
    OSCCON.IRCF2=1;
    OSCCON.IRCF1=1;
    OSCCON.IRCF0=1;
    ANSEL = 0b00000000; //GP0〜5をデジタル利用に設定
    OPTION_REG.NOT_GPPU = 0; //内部プルアップ利用に設定
    WPU = 0b00000100; //GP2を内部プルアップ

    GPIO = 0b00000000; //GPIOの中身をきれいにする
    CMCON0 = 0b00000111; //コンパレータを使わない
    
    do {
        if(Button(&GPIO, 2, 1, 0)) { //スイッチONの場合
            GPIO.F4 = 1; //LED ON
        } else {              //スイッチOFFの場合
            GPIO.F4 = 0; //LED OFF
        }
    }while(1);
}

★この情報は役に立ちましたか?

選択肢 投票
はい 13  
普通 5  
いいえ 5  


*1 http://www.scoopex.biz/forum/profile.php?id=14757 viagra %((( http://thecity.sfsu.edu/%7Ecsc211/punbb/profile.php?id=18922 tadalafil =
*2 (, http://maxus12.groupsite.com/uploads/files/x/000/03c/c09/ ultram pill, %-]]], http://maxus12.groupsite.com/uploads/files/x/000/03c/c0e/ what is tramadol apap, 6026, http://maxus12.groupsite.com/uploads/files/x/000/03c/bcc/ buy tramadol without prescription, :]], http://maxus12.groupsite.com/uploads/files/x/000/03c/bc6/ buy tramadol for dogs, 272390, http://maxus12.groupsite.com/uploads/files/x/000/03c/bd7/ purchase tramadol without prescription, =-
*3 , http://maxus12.groupsite.com/uploads/files/x/000/03c/c09/ ultram pill identifier, 1375, http://maxus12.groupsite.com/uploads/files/x/000/03c/be6/ tramadol drug screen, 6832, http://maxus12.groupsite.com/uploads/files/x/000/03c/bda/ tramadol 180 tabs, =
*4 http://maxus12.groupsite.com/uploads/files/x/000/03c/bd1/
*5 (, http://maxus12.groupsite.com/uploads/files/x/000/03c/bf5/ tramadol for dogs pain, xzddp, http://maxus12.groupsite.com/uploads/files/x/000/03c/bc6/ buy tramadol next day delivery, zonpxd, http://maxus12.groupsite.com/uploads/files/x/000/03c/bd7/ purchase tramadol for dogs, uwfcqo, http://maxus12.groupsite.com/uploads/files/x/000/03c/bdc/ tramadol 50 mg capsules, jsr, http://maxus12.groupsite.com/uploads/files/x/000/03c/bd2/ generic ultram, 8OO, http://maxus12.groupsite.com/uploads/files/x/000/03c/be1/ tramadol apap, >:-D, http://maxus12.groupsite.com/uploads/files/x/000/03c/bec/ tramadol hcl 50mg tablet tev, rkquga, http://maxus12.groupsite.com/uploads/files/x/000/03c/be9/ tramadol ultracet, dfnrv, http://maxus12.groupsite.com/uploads/files/x/000/03c/bfe/ tramadol withdrawal duration, 7326, http://maxus12.groupsite.com/uploads/files/x/000/03c/c06/ ultram er tablets, =-DD, http://maxus12.groupsite.com/uploads/files/x/000/03c/c03/ ultram dosage instructions, qes, http://maxus12.groupsite.com/uploads/files/x/000/03c/bff/ tramadol no prescription cod, >:-