input // "0"=>output while(1) PORTB = i >> x; Delay(); x++; if(x==9) x=0;"> input // "0"=>output while(1) PORTB = i >> x; Delay(); x++; if(x==9) x=0;">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

基本IO.

Similar presentations


Presentation on theme: "基本IO."— Presentation transcript:

1 基本IO

2

3 TRIS(X)代表著控制通用輸入輸出埠(輸入:1,輸出:0) PORT(X)代表通用輸入輸出埠
PORTB有9個位元 PORTC有3個位元 PORTD有4個位元 PORTE有6個位元 PORTF有7個位元

4 /* 功能為每個位元輸出 */ #include <stdio.h> //呼叫stdio(標準輸入輸出)指令巨集 #include <p30F4011.h> //呼叫p30F4011(IC)指令巨集 _FWDT(WDT_OFF); //關閉看門狗 /* 延遲副函式 */ void Delay( void ) { int j=0,k=0; for(j=0;j<150;j++) for(k=0;k<2000;k++); } unsigned int i=0x1ff; int main(void) ADPCFG=0xffff; //關閉AD輸入腳 作為一般IO用 int x=0; TRISB = 0x0000 ; // 0B // "1"=>input // "0"=>output while(1) PORTB = i >> x; Delay(); x++; if(x==9) x=0;

5 /* 功能為判斷輸入是1或0在由LED輸出 */
#include <stdio.h> //呼叫stdio(標準輸入輸出)指令巨集 #include <p30F4011.h> //呼叫p30F4011(IC)指令巨集 _FWDT(WDT_OFF); //關閉看門狗 /* 延遲副函式 */ void Delay( void ) { int j=0,k=0; for(j=0;j<150;j++) for(k=0;k<2000;k++); } int main(void) unsigned int a; TRISB = 0x1ff; // 0B // "1"=>input // "0"=>output TRISF = 0x000; ADPCFG=0x0001; //關閉AD輸入腳 Set RB0 as Digital input mode while(1) a=PORTB&0x001; //PORTB輸入 //PORTB = a<<4; if (a==0) PORTF=0x001; //PORTF輸出 else PORTF=0x002; Delay();

6 請設計一個輸入為high時,進行LED跑馬燈的動作,Low時不動作


Download ppt "基本IO."

Similar presentations


Ads by Google