Re: PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
資深會員
|
RB0有AD的功能
如果沒有改變AD設定的話 預設會是AD PIN 所以當然沒有數位IO的功能了
發表於: 2008/4/27 13:51
|
|||
|
Re: PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
新會員
|
感謝樓上高手的回答,我大概知道您說的意思,但我昨天K完PIC18F4520的DATDSHEET後,真的還是有點有看沒有懂,加上我用C18寫,關於這部分真的還是有點模糊,是否可以請您再給我一些提示呢??拜託您了!!感謝。
發表於: 2008/4/27 11:48
|
|||
|
Re: PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
資深會員
|
因為你沒先把A/D設定好
請先把書上AD的章節K完再說 Good lucky
發表於: 2008/4/26 14:36
|
|||
|
Re: PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
資深會員
|
吐血,系統不支援tab符號?罷了罷了
發表於: 2008/4/25 19:37
|
|||
|
Re: PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
資深會員
|
為了測試新工具的自動排縮能力,我特別用它來幫你整理了一下
--- #include <p18f4520.h> #include <delays.h> #include <timers.h> #include <pwm.h> // 結構位元定義 #pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF // 工作時序頻率定義 #define OSC_CLOCK 10 void delay_ms(long A); void main (void) { unsigned char push_no=1; PORTD = 0x01; TRISD = 0; TRISAbits.TRISA4=1; TRISBbits.TRISB0=1; TRISCbits.TRISC2=0; OpenPWM1(0x9B); OpenTimer2(TIMER_INT_OFF&T2_PS_1_4&T2_POST_1_1); while (1) { delay_ms(10); if(PORTAbits.RA4==0) { push_no--; while(PORTAbits.RA4==0); if(push_no==0) { push_no=1; PORTD++; } else{ if(PORTBbits.RB0==0) { push_no--; while(PORTBbits.RB0==0); if(push_no==0) { push_no=1; PORTD--; } } } SetDCPWM1((unsigned int)PORTD<<2); } } } void delay_ms(long A) { long i; int us2TCY; us2TCY=(10*OSC_CLOCK)>>2; for(i=0;i<A;i++) Delay100TCYx(us2TCY); } --- 我假設你其它部份沒有問題,比如硬體或週邊設定均正常,這裡只簡單幫你移動個位置 --- while (1) { delay_ms(10); if(PORTAbits.RA4==0) { push_no--; while(PORTAbits.RA4==0); if(push_no==0) { push_no=1; PORTD++; } } else{ if(PORTBbits.RB0==0) { push_no--; while(PORTBbits.RB0==0); if(push_no==0) { push_no=1; PORTD--; } } } SetDCPWM1((unsigned int)PORTD<<2); } --- 程式還有很大的進步空間,自已努力吧
發表於: 2008/4/25 19:33
|
|||
|
PIC 18f4520之RB0問題
|
||||
---|---|---|---|---|
新會員
|
各位高手您好:
小弟目前想要撰寫一個簡單的利用開關SW3與SW4控制PWN及LED燈之程式,我利用SW3作為PWM DUTY增加與LED遞增之控制,目前是可行的,但寫到利用SW4作為PWM DUTY減少與LED遞減之控制卻無法實行。小弟的程式如下,因為小弟剛接觸PIC,因此懷疑是否為我的程式觀念有誤,懇請各位高手幫小弟看一下是否有解決方法!!小弟感激不盡。 以下為目前所撰寫之程式碼,其中SW4所對應之RB0腳無法做PWM DUTY減少與LED燈遞減的功能。 #include <p18f4520.h> #include <delays.h> #include <timers.h> #include <pwm.h> // 結構位元定義 #pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF // 工作時序頻率定義 #define OSC_CLOCK 10 void delay_ms(long A); void main (void) { unsigned char push_no=1; PORTD = 0x01; TRISD = 0; TRISAbits.TRISA4=1; TRISBbits.TRISB0=1; TRISCbits.TRISC2=0; OpenPWM1(0x9B); OpenTimer2(TIMER_INT_OFF&T2_PS_1_4&T2_POST_1_1); while (1) { delay_ms(10); if(PORTAbits.RA4==0) { push_no--; while(PORTAbits.RA4==0); if(push_no==0) { push_no=1; PORTD++; } else{ if(PORTBbits.RB0==0) { push_no--; while(PORTBbits.RB0==0); if(push_no==0) { push_no=1; PORTD--; } } } SetDCPWM1((unsigned int)PORTD<<2); } } } void delay_ms(long A) { long i; int us2TCY; us2TCY=(10*OSC_CLOCK)>>2; for(i=0;i<A;i++) Delay100TCYx(us2TCY); }
發表於: 2008/4/25 16:33
|
|||
|