| 
	
	
		
		
		
		 và đây là đoạn code nhận analog ( giả lập tín hiệu tương tự bằng biến trở 10k) . Em đang ngồi chờ máy anh giúp em cho hoàn thiện 1 chương trình !! 
 
Code : 
 
#include <18f4620.h> 
#device ADC = 10 
#include <string.h> 
#use delay(clock = 12m ) 
#fuses HS,NOWDT 
 
char bang[20] = "hh:mm:ss (am)"; 
void write_lcd(int c, short mode) 
{ output_bit(pin_e2,mode); 
  output_d(c); 
  output_high(pin_e1); 
  delay_ms(1); 
  output_low(pin_e1); 
  delay_ms(1); 
} 
void init_lcd(void) 
{ write_lcd(0x38,0); 
  write_lcd(0x0e,0); 
  write_lcd(0x01,0); 
  delay_ms(25); 
} 
void string_lcd(char c[]) 
{ int i; 
  for(i=0;i<strlen(c);i++) 
   write_lcd(c[i],1); 
} 
void goto_lcd(int x, int y) 
{  switch(y) 
   { case 0 : write_lcd(0x80+x,0);break; 
     case 1 : write_lcd(0xc0+x,0);break; 
   } 
   delay_ms(5); 
} 
void main(void) 
{  int16 value=0; 
   set_tris_b(0);/// 
   set_tris_e(0); 
   set_tris_a(0x0f); 
   setup_adc_ports(A0_A3_A1_A2); 
   setup_adc(ADC_CLOCK_DIV_32); 
   output_low(pin_a5); 
   output_high(pin_e0); 
   init_lcd(); 
   goto_lcd(2,0); 
   string_lcd(bang); 
   goto_lcd(1,1); 
   string_lcd(bang); 
    
   /// set_adc_channel( 0 ); 
   //   value = read_adc(); 
 
   while(1) 
   { set_adc_channel( 0 ); 
     value = read_adc(); 
     output_d(value&0x0ff); 
     delay_ms(200); 
 
    
   } 
    
} 
		
	
		
		
		
		
		
	
	 |