16F877a to PC to Handphone

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

16F877a to PC to Handphone

Postby E11022 » Sat Dec 10, 2011 8:46 am

Hi,
i am connecting PIC16f877a to my laptop using a USB-serial converter and then to handphone T630. Meanwhile, I am waiting for my USB-serial cable order to reach my doorstep.
My idea is when sensor is triggered, buzzer sounds and calling a number.

Below is my code :
#include <pic.h>
__CONFIG(0x3F32);

#define sensor RA0
#define sw RA1
#define buzzer RC5
#define led RC4
#define BAUD 9600
#define _XTAL_FREQ 20000000

void uart_transmit(char data);
void uart_string(const char*s);

void uart_transmit(char data){
while (TXIF==0)continue;
TXREG='j';
}
void uart_string(const char*s)
{while(*s)
uart_transmit(*s++);
}

void main (void)
{
ADCON1 = 0x06;
TRISA=0b11111111;
TRISC=0b00000000;
TXSTA=0b00100000;
RCSTA=0b10010000;
SPBRG=265;
SYNC=0;
BRGH=1;
SPEN=1;
TXEN=1;

sensor=0;
sw=0;
buzzer=0;
led=0;

while(1)
{
if ((sensor == 0) && (sw ==0))
{ led=1,buzzer=1;
uart_string("ATD++60136289844:");//call
uart_transmit(0x0D);}//enter
else if ((sensor == 0) && (sw ==1))
{ led=0,buzzer=0;}
else {led =0,buzzer =0;}
}
}

Now because i do not have the USB Serial cable, i cannot test the code. I am not so familiar with the UART_TRANSMIT , please give me some advises on the code, i felt something is wrong there.
P/S: compilation no errors.. >.<
E11022
Novice
 
Posts: 27
Joined: Tue Nov 15, 2011 10:13 pm

Re: 16F877a to PC to Handphone

Postby shahrul » Sat Dec 10, 2011 8:57 am

E11022 WROTE:Now because i do not have the USB Serial cable, i cannot test the code. I am not so familiar with the UART_TRANSMIT , please give me some advises on the code, i felt something is wrong there.
P/S: compilation no errors.. >.<

uart_transmit is to transmit single byte uart
uart_string is to transmit uart from a string
uart_transmit(0x0D) is transmit 'Enter'

You can connect the PIC with USB-to-UART converter to the hyperterminal. So, you can see what you are transmitting.
If using Win7, there is no hyperterminal so you directly use Visual Basic just for serial communication.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: 16F877a to PC to Handphone

Postby E11022 » Sat Dec 10, 2011 9:02 am

Because i do not have the USB-to-UART converter now, no idea whether the code is working. Any simulations program to suggest for me to test my code? I am using Window XP :)
Thanks
E11022
Novice
 
Posts: 27
Joined: Tue Nov 15, 2011 10:13 pm

Re: 16F877a to PC to Handphone

Postby ZaM » Sat Dec 10, 2011 12:19 pm

if using window7, copy hyperterminal(hypertrm.exe & hypertrm.dll) file from xp computer or donwload. for simulation can use proteus from lab center to test code. to connect proteus & hyperterminal, can see tutorial at youtube.
1.PNG
or
2.PNG
using rs232 port
ZaM
Moderator
 
Posts: 78
Joined: Tue Nov 23, 2010 4:16 pm

Re: 16F877a to PC to Handphone

Postby E11022 » Sun Dec 11, 2011 12:57 pm

thanks Zam.
The code is not working. None of my friend has experience working with serial programming. can anyone pin point what is the problem with the code? High appreciate your helps. Thanks.
E11022
Novice
 
Posts: 27
Joined: Tue Nov 15, 2011 10:13 pm

Re: 16F877a to PC to Handphone

Postby zhenning » Sun Dec 11, 2011 1:05 pm

You should try on hardware. Using Proteus to simulate might have it not working but in fact it did work on hardware. I have faced the problem before. Another thing is you should test your USB-serial converter cable. Some cables do not work well ^_^
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: 16F877a to PC to Handphone

Postby E11022 » Sun Dec 11, 2011 1:09 pm

i tried it out on hardware. it is not working. I am now connecting PIC to PC(dekstop) and then using a USB cable connect to my phone.
when i open hyperterminal, then only power up the microcontroller, there is no response on the Hyperterminal at all.
Now i just wanna know the problem lies on the coding or the problem lies on the hardware?
E11022
Novice
 
Posts: 27
Joined: Tue Nov 15, 2011 10:13 pm

Re: 16F877a to PC to Handphone

Postby zhenning » Sun Dec 11, 2011 1:14 pm

E11022 WROTE:i tried it out on hardware. it is not working. I am now connecting PIC to PC(dekstop) and then using a USB cable connect to my phone.



you are using usb-serial with desktop?
zhenning
Enthusiast
 
Posts: 351
Joined: Thu Dec 30, 2010 12:32 am

Re: 16F877a to PC to Handphone

Postby E11022 » Sun Dec 11, 2011 1:20 pm

zhenning WROTE:
E11022 WROTE:i tried it out on hardware. it is not working. I am now connecting PIC to PC(dekstop) and then using a USB cable connect to my phone.



you are using usb-serial with desktop?
i will be using USB-serial with my laptop only when interfacing with PC is working.

Nope. My PC got COM port, so i connected it like this:
Pin 2 (RS232) - Pin 14 (MAx232)
Pin 3 (RS232) - Pin 13 (MAX232)
Pin 12 (MAX 232) - Pin 25 (PIC)
Pin 13 (Max232 - Pin 26(PIC)

I am using Sony Ericsson T630 and i have it USB cable. I connected the USB cable to PC and installed the driver. If only interface Hyperterminal to Handphone, it is working. So i assume there is no problem with the PC.
E11022
Novice
 
Posts: 27
Joined: Tue Nov 15, 2011 10:13 pm

Re: 16F877a to PC to Handphone

Postby ZaM » Sun Dec 11, 2011 1:29 pm

why need to use PC? you can try PIC+GSM only. can hyperterminal support 2 com port?
ZaM
Moderator
 
Posts: 78
Joined: Tue Nov 23, 2010 4:16 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 3 guests

cron