Re: 請問p18F4520的這段程式詳細解釋?
|
||||
---|---|---|---|---|
新會員
|
參照:
那如果我要改成一開始七段顯示器顯示AA 再按下PORB0的按鈕後變成15 是不是改這樣就好呢? void main (void) {ADCON1=0b00000110; PORTD = 0x15; TRISD = 0; TRISBbits.TRISB0=1; while (1){ delay_ms(200); if(PORTBbits.RB0==1) PORTD=0x15 else PORTD=0xAA
發表於: 2010/1/15 7:34
|
|||
|
Re: 請問p18F4520的這段程式詳細解釋?
|
||||
---|---|---|---|---|
版主
|
致 aceapong,
看起來要要先了解的不是程式如何的動作,因為感覺起來 C 的敘述你還不了解所以無法看的懂這種解單的程式。 建議,先將 W401 看過後你就會了解 這些 I/O Port 與周邊的基本設定及使用方式。
發表於: 2010/1/14 10:05
|
|||
|
Re: 請問p18F4520的這段程式詳細解釋?
|
||||
---|---|---|---|---|
資深會員
|
這是曾老師書中的範例,簡單說就是讓燈有按了sw4時會往反方向跑!下面那個區段,分別是delay , 向左, 向右的副程式!
void main (void) {ADCON1=0b00000110; PORTD = 0x01; TRISD = 0; TRISAbits.TRISA4=1; while (1){ delay_ms(200); if(PORTAbits.RA4==1) rot_left(); else rot_right(); 而上面這段就是他要執行的主程式
發表於: 2010/1/14 9:28
|
|||
|
請問p18F4520的這段程式詳細解釋?
|
||||
---|---|---|---|---|
新會員
|
我在LAB的時候使用18f4520在MPLAB用到這段程式
可以告訴我這段程式碼每個地方的意思嗎? #include <p18f4520.h> #include <delays.h> #pragma config OSC=HS, WDT=OFF, LVP=OFF #define OSC_CLOCK 10 void delay_ms (long A); void rot_right(void); void rot_left(void); void main (void) {ADCON1=0b00000110; PORTD = 0x01; TRISD = 0; TRISAbits.TRISA4=1; while (1){ delay_ms(200); if(PORTAbits.RA4==1) rot_left(); else rot_right(); } } void delay_ms(long A) { long i; int us2TCY; us2TCY=(100*OSC_CLOCK)>>2; for(i=0;i<A;i++) Delay100TCYx(us2TCY); } void rot_right(void) { if(PORTD>1) PORTD=(PORTD>>1); else PORTD=127; } void rot_left(void) { if(PORTD<128) PORTD=(PORTD<<1); else PORTD=0x01; }
發表於: 2010/1/14 1:04
|
|||
|