Re: 副程式的問題?
|
||||
---|---|---|---|---|
版主
|
老實說,我真的看不懂你所寫的程式,中斷方式不對,邏輯架構流程看不懂... 真的不知道要從何處說明起。不過大家都會有這一種共同的過程,建議你 C18 W401 的講義及練習先研究一下,尤其是第五章有關中斷的說明。
發表於: 2007/12/27 15:54
|
|||
|
副程式的問題?
|
||||
---|---|---|---|---|
初級會員
|
各位大大好!下面是我自己寫的控制馬達程式~抱歉想請問一下~我自己所寫的duty_cycle副程式~我把它放在main裡~像這樣
void main() { while(1){ duty_cycle(48); Delay10KTCYx(20); duty_cycle(24); Delay10KTCYx(20); } } 可是不知道為什麼?duty_cycle(48);不會被duty_cycle(24);取代~因為我想產生2種不一樣的工作週期~想不出來.....??可以交我一下嗎? #define timer_initial_value 15536 void low_timer(char i); void duty_cycle(char i1); void hi_timer(void);//a a,b,c要一樣 #pragma code hi_timer_1=0x0008 void hi_timer_1() { hi_timer(); }//b a,b,c要一樣 #pragma code int i,j,x[50]={12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36, 37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60}; void low_timer(char i) { TRISE=0X00; TRISD=0X00; TRISB=0X00; TRISJ=0X00; PORTE=0X18; PORTJbits.RJ0=0; //選擇控制選項 選項間用 "&" 來連結 OpenTimer0(TIMER_INT_ON&T0_16BIT&T0_SOURCE_INT&T0_PS_1_1); //TIMER_INT_ON(中斷啟動),T0_16BIT(16位元模式),T0_SOURCE_INT(使用內部時脈工作),T0_PS_1_1(除頻1:1) //如果50000*4/10M*1=20ms ,是否可以設"計數器初值"為65536-50000=15536(0x3cb0) INTCONbits.GIEH=1; while(1) { PORTJbits.RJ0=0; } } void hi_timer(void)//C a,b,c要一樣 { TMR0L=timer_initial_value%256; //TMR0L=0Xb0; TMR0H=timer_initial_value/256; //TMR0H=0X3c; INTCON=0B00100000; PORTJbits.RJ0=1; Delay100TCYx(x[i]); //0-48 ,0:0.5ms, 48:2.5ms, 每1次41us INTCON=0B10100000; } void duty_cycle(char i1) { i=i1; low_timer(i); hi_timer(); } void main() { duty_cycle(48); //0-48 ,0:0.5ms, 48:2.5ms, 每1次41us Delay10KTCYx(20); duty_cycle(24); //0-48 ,0:0.5ms, 48:2.5ms, 每1次41us Delay10KTCYx(20); }
發表於: 2007/12/27 13:07
|
|||
|