| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| yousafzai82 
 
 
 Joined: 04 Mar 2010
 Posts: 13
 Location: Pakistna
 
 
			          
 
 | 
			
				| Code editing for PIC16F877 |  
				|  Posted: Tue Mar 09, 2010 1:51 am |   |  
				| 
 |  
				| Hello everyone.... 
 I want to programme pic16f877 2 channel 10 bit adc. I need two digital inputs as well. The program should send AT commands for SMS then the Value1, Value2, Status1, Status2 shown in the program below.
 
 If you can edit the Coding as 2 channel 10-bit ADCs only send the values as i.e.
 
 Value1= 0 to 1023
 Value2= 0 to 1023
 Status1= High or Low
 Status2= High or Low
 
  	  | Code: |  	  | #include<16F877.h>
 #device ADC=10
 #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
 #use delay(clock=10000000)
 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)
 #include<stdio.h>
 #include<math.h>
 #include<STDLIB.H>
 
 #Byte PortA=0x05
 #Byte PortB=0x06
 #use fast_io(A)
 #use fast_io(B)
 #Define Nop #Asm Nop #EndAsm
 
 int fuel, temp;
 
 void send_SMS(void)
 {
 printf("AT\r\n");
 delay_ms(5000);
 printf("at+cmgf=1\r\n");
 delay_ms(5000);
 printf("at+cmgs=\"+4478XXXXXXXX\"\r\n");
 delay_ms(5000);
 printf("%f/n/rfuel: %f/n/rtemp",(float)fuel,(float)temp);
 putc(0x1A);
 delay_ms(5000);
 }
 
 void main(){
 setup_adc( ADC_CLOCK_INTERNAL );
 setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
 set_adc_channel(0);
 
 SET_TRIS_A( 0b10000110 );
 SET_TRIS_B( 0b00000101 ); delay_ms(1);
 
 
 while(1){
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 
 fuel = read_adc();
 {
 set_adc_channel(1);
 
 SET_TRIS_A( 0b10000110 );
 SET_TRIS_B( 0b00000101 ); delay_ms(1);
 
 temp = read_adc();
 }
 
 send_SMS();
 }
 }
 
 | 
 Someone please suggest modification how to code Status1 and Status2 using RA4,RA5. Is my current program ok? It is urgent..
 
 The program should send SMS continuously after some time say 5 minutes.
 
 Zaky
 _________________
 zaky
 |  |  
		|  |  
		| yousafzai82 
 
 
 Joined: 04 Mar 2010
 Posts: 13
 Location: Pakistna
 
 
			          
 
 | 
			
				|  |  
				|  Posted: Tue Mar 09, 2010 5:42 am |   |  
				| 
 |  
				| I modified the code as follows. Is it alright ? Will I be able to send the data this way???? 
  	  | Code: |  	  | #include<16F877.h>
 #device ADC=10
 #fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,PUT
 #use delay(clock=10000000)
 #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=RS232,bits=8)
 #include<stdio.h>
 #include<math.h>
 #include<STDLIB.H>
 
 #Byte PortA=0x05
 #Byte PortB=0x06
 #use fast_io(A)
 #use fast_io(B)
 #Define Nop #Asm Nop #EndAsm
 
 int16 fuel, temp;
 int1 Genset, CP;
 
 
 void send_SMS(void)
 {
 printf("AT\r\n");
 delay_ms(5000);
 printf("at+cmgf=1\r\n");
 delay_ms(5000);
 printf("at+cmgs=\"+923469400983\"\r\n");
 delay_ms(5000);
 printf("%f/n/rfuel: %f/n/rtemp:%d/n/rGenset:%d/n/rCP:",(float)fuel,(float)temp,Genset,CP);
 putc(0x1A);
 delay_ms(5000);
 }
 
 
 void main(){
 
 
 setup_adc( ADC_CLOCK_INTERNAL );
 setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
 set_adc_channel(0);
 
 SET_TRIS_A( 0b10000110 );
 SET_TRIS_B( 0b00000101 ); delay_ms(1);
 
 
 while(1){
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 delay_ms( 30000);
 
 fuel = read_adc();
 {
 set_adc_channel(1);
 
 SET_TRIS_A( 0b10000110 );
 SET_TRIS_B( 0b00000101 ); delay_ms(1);
 
 temp = read_adc();
 }
 {
 Genset = input_state(pin_A4);
 }
 {
 CP = input_state(pin_A5);
 }
 send_SMS();
 }
 }
 | 
 _________________
 zaky
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |