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.

mikroC to pic16f877a and sim900

Status
Not open for further replies.

dark_ages

Member level 1
Joined
Jan 8, 2011
Messages
39
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Koronadal City, Philippines
Activity points
1,577
hi,

does any one knows what are codes am i going to use when programming the pic16f877a connected with sim900, using the mikroC?

tnx for any help....
urgently need it.
 

This is a guide to Sim900 module.
**broken link removed**
 

Yes, you can.
The MikroC has a library called "Soft_UART" that can be used with microcontrollers those don't have the USART hardware. The library will configure the two pins you choose to be TXD and RXD of the UART.
I used it this library with PIC16F84A that doesn't have the USART hardware.

Hope this helps.
 

Hi dark_ages,

PIC16f877a has a hardware USART;
So it's better to use it, other than using software-uart.
That will save your code and variable memory; also minimize burden on uC.

Thank you,
 

how will I use USART?
I'm trying to use it but it has a red line on it.
do I have to declare something in order to use port c6 and c7 as TX and RX?
 

Please post your code.
I tried the USART library with 16F628A and 16F877A. It works fine with me.
So, please post your code if you want to get more help.
 

here it is sir.....
void main() {
while(1){
char lock = "LOCK ON";
char stat = "SYSTEM STATUS";
char read;

TRISA=0Xff;
TRISB=0X00;
Usart_Init(9600);
delay_ms(5000);
read=Usart_Read();
if(Usart_Data_Ready()){
if(read==lock)
{ delay_ms(2000);
portb.f0==1 ; //lock on.
delay_ms(2000);
Usart_WRITE_TEXT("AT+CMGS=");
delay_ms(1000);
Usart_WRITE(0X22); //"
delay_ms(2000);
Usart_WRITE_TEXT("+639183883776"); //MY NUMBER
delay_ms(2000);
Usart_WRITE(0X22); //"
Usart_WRITE(0X0D); //<CR> means enter
delay_ms(2000);
Usart_WRITE_TEXT("LOCK IS ON");
Usart_WRITE(0X0D); //<CR> means enter
delay_ms(2000);
Usart_WRITE(26);
delay_ms(2000);
Usart_WRITE(0X0D); //<CR> means enter
delay_ms(5000);}

else if(read==stat) //inquier for status
{ delay_ms(2000);
Usart_WRITE_TEXT("AT+CMGS=");
delay_ms(1000);
Usart_WRITE(0X22); //"
delay_ms(2000);
Usart_WRITE_TEXT("+639183883776"); //MY NUMBER
delay_ms(2000);
Usart_WRITE(0X22); //"
Usart_WRITE(0X0D); //<CR> means enter
delay_ms(2000);
if(porta.f0==0 && porta.f1==0)
{Usart_WRITE_TEXT("Your lights and outlet is on");} //loads are on

else if(porta.f0==1 && porta.f1==0)
{Usart_WRITE_TEXT("Light2 and Outlet is On");} //light two on

else if(porta.f0==0 && porta.f1==1)
{Usart_WRITE_TEXT("Light1 is On");} //light one on

else if(porta.f0==1 && porta.f1==1)
{Usart_WRITE_TEXT("All loads are Off");} //loads are off


Usart_WRITE(0X0D); //<CR> means enter
delay_ms(2000);
Usart_WRITE(26);
delay_ms(2000);
Usart_WRITE(0X0D); //<CR> means enter
delay_ms(5000); }
}

}
}
,,,,I check the Library Manager but it only have UART and it doesn't have a USART.

---------- Post added at 09:32 ---------- Previous post was at 09:25 ----------

i'm using mickroC PRO v4.60.0.0
 

OK, here you are some comments:

1-
Code:
	   char lock = "LOCK ON";
	   char stat = "SYSTEM STATUS";
These two variables should be defined as arrays or as pointers to array of characters.
Code:
	   char lock[] = "LOCK ON";
	   char stat[] = "SYSTEM STATUS";

2-
Code:
if(read==lock)
Here you are comparing a single character "read" to and array of characters "lock".
The data received by the Usart in a single byte, you have to create a buffer to store the complete string then, compare it.
Code:
unsigned short int Index=0;
char Byte[20];
char Read;
Read = Usart_Read();
while(Read!= '\0' || Read != '\n' )
	{
		Byte[Index] = Read;
		Index++;
	}
Now, you can compare an array to an array.

3-
Code:
delay_ms(2000);
This is too much delay, you can use 1mS as a delay between every two successive characters.
Your Baud Rate is 9600, that is you send a character every 105uS
So, 1mS delay will be enough.

4- The function "Usart_WRITE_TEXT" is missing in your posted code, may there's a problem with this function. Please post it as well.

5- I tried to compile your project, the MikroC gives me an error "Not Enough RAM"
I think this may be due to the small RAM size of the PIC16F877A.
I haven't suffer from such problem before.

I hope you find any of the comments useful.

Good Luck
 

a big tnx then,,does the version of mikroC affects the library it has?

---------- Post added at 11:00 ---------- Previous post was at 10:56 ----------

is there any codes for declaring a string?
 

To declare a string:
1- A pointer to a an array of characters. The size is defined by the number of characters in the string, plus the an invisible terminator called "null character"
Code:
char *String = "This is a string";

2- An explicit definition for an array of characters.
Code:
char String[] = "This is a string";

The two statements are equivalent.

Hope this helps.
 

I'll try it...tnx a lot....by the way, about the version of mikroC, does it affect the library it has? 'cause i'm using version 4
and it doesn't includes USART on its library.
 

Hi,

Are you using mikroC or mikroC PRO ?
mickroC Version: 8.1.0.0 and mikroC PRO V 4.1 have UART libraries.

Thanks
 

@seadolphine: ah ok, I think mikro c versions differs in their libraries,tnx...do you have the installer for that?
@dineshsl: yes, we're using mikroC. but i'm using a version without a usart library.
 
Last edited:

"seadolphine2000;849293]Yes, you can.
The MikroC has a library called "Soft_UART" that can be used with microcontrollers those don't have the USART hardware. The library will configure the two pins you choose to be TXD and RXD of the UART.
I used it this library with PIC16F84A that doesn't have the USART hardware.

Hope this helps."


Sir,Now me too working with the soft uart in PIC16f877a since i need o use two uarts..
can u help me with providing the code for sending and recieving message..
Kindly help sir...
 

Don't use Soft_UART for receiving SMS. It will not work. Also don't use Soft UART for receiving. Use hadware UART for receiving. If you need to receive data from two devices like GSM and RFID then better use a PIC18F with two UART. It cost 1 or 2 $ more.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top