Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Code editing for PIC6F877 using CCS C Compiler

Status
Not open for further replies.

yousafzai82

Member level 4
Joined
Jan 20, 2010
Messages
77
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Pakistan
Activity points
1,844
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

#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
_________________

Added after 3 hours 53 minutes:

I modified the code as follows. Is it alright. Will i be able to send the data this way????

#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();
}
}
 

Can someone confirm that the voltage reference at pin RA3 should be DC or Sinosoidal Voltage.

setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports( RA0_RA1_ANALOG_RA3_REF );
set_adc_channel(0);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top