| sonicdeejay 
 
 
 Joined: 20 Dec 2005
 Posts: 112
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Feb 24, 2006 5:26 pm |   |  
				| 
 |  
				| Schematic Diagram 
 
   
 
 main program
 
 
  	  | Code: |  	  | #include <18F2525.h> // Call for PIC18F2525 Driver #device ICD=TRUE
 #device ADC=10 // Use 10bits ADC
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=16000000) // 16Mhz Crystal is Used
 
 #include <MAX517mod.c>  //Call for MAX517mod.c function
 
 //Start main program
 void main()
 
 {
 
 while(1)
 {
 
 output_high(PIN_A0); //LED ON
 write_dac(0xFF);     //DAC output 5V
 delay_ms(5000);    //Delay
 
 output_low(PIN_A0); //LED OFF
 write_dac(0x00);   //DAC output 0V
 delay_ms(5000);    //Delay
 
 }
 
 
 }
 | 
 
 
 MAX517mod.c (It is same with MAX517.c and the only difference is PIN assignments)
 
 
  	  | Code: |  	  | #ifndef MAX517_SDA 
 #define MAX517_SDA    PIN_C4  //PIN assignment for PIC18F2525
 #define MAX517_CLK    PIN_C3  //PIN assignment for PIC18F2525
 
 #endif
 
 #use i2c(master, sda=MAX517_SDA, scl=MAX517_CLK, FAST)
 
 
 void write_dac(int data_byte) {
 
 i2c_start();
 i2c_write(0x58);           // AD0 and AD1 are tied to ground
 i2c_write(0);
 i2c_write(data_byte);      // Send the data to the device
 i2c_stop();
 }
 | 
 
 
  |  |