| 
	
	
		
			
			 
				
				giup code dspic 4011
			 
			 
			
		
		
		
		e viết code như thế nào trong chương trình mikroC pro for dspic nhưng không chạy mong anh Nam giúp e xem e sai ở chỗ nào và chỉ dùm e! timer k ngắt dc 
 
 
unsigned int i,truoc,sau,trai,phai; 
unsigned int struoc,ssau,strai,sphai; 
void 
void khaibaoPLL(){ 
  // 7.3728MHz/2*32/2                                       7.3728*8= 58.9824/4 =14.7456    1/14.7456= 0.068 
  //1/58.9824=0.017 
  RCONbits.SWDTEN = 0; // disable watchdog timer 
  while(OSCCONbits.LOCK != 1) ; //wait PLL to lock 
  } 
  void khoitaotimer1 (){ 
  T1CON.T1IE=1; 
  T1CON.T1IF=0; 
  TMR1=65533; //10us 
  T1CON=0x8000;//prescale 1:1 
  } 
  void Timer1Int () iv IVT_ADDR_T1INTERRUPT { 
       if(T1IF){ 
                      T1IF_bit=0; 
                      TMR1=65533; 
                      i++; 
                      if(i>2000){ 
                                 i=0; 
                                 LATD=0xff; 
                                 } 
                      if(i>=truoc){RD0_bit=0;} 
                      if(i>=sau){RD1_bit=0;} 
                      if(i>=trai){RD2_bit=0;} 
                      if(i>=phai){RD3_bit=0;} 
     } 
    } 
void capnhat(){ 
struoc= truoc-truoc; 
ssau= truoc-sau; 
strai= truoc-trai; 
sphai= truoc-phai; 
} 
void len(){ 
truoc=truoc++; 
sau= truoc+ssau; 
trai= truoc+strai; 
phai= truoc+sphai; 
} 
 
void main () { 
ADPCFG = 0xFFFF; 
 
khoitaotimer1(); 
khaibaoPLL(); 
TRISD=0x00; 
LATD=0xFF; 
truoc = 100; sau=100;trai=100;phai=100; 
 
//capnhat(); 
//len(); 
 
} 
		
	
		
		
		
		
		
	
	 |