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.

usart programs in pic controller

Status
Not open for further replies.

subhash2505

Newbie level 4
Joined
Jun 22, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,335
hi gyus
im doing my project in pic16f877 controller in that im facing the problem in my usart program, i have written one program in that if i run the program in microC compiler means im not getting any error but then i dumbed into the controller im not getting any response from the tx pin the controller, here a pasetd my program, i kindly request you that any one please help with the program....................................:-D:-D:-D:-D:-D



unsigned char i,k,j,l,m,n,in;
unsigned char init[4]="AT\r";
unsigned char mes[11]="AT+CMGF=1\r";
unsigned char num[22]="AT+CMGS=\"9790058470\"\r";
unsigned char dat1[25]="First text";
unsigned char dat2[25]="Second text";
unsigned char dat3[25]="Third text";
unsigned char dat4[25]="fourth text";
unsigned char end=0x1A;
void sendmsg1();
void sendmsg2(unsigned char array[]);
void delay();


void main()
{
ADCON1 = 0x82;
TRISB=0XFF;
PORTC = 0;
TRISC = 0XBE;


for(i=0;i<=0;i++)
{
switch(PORTB)
{
case (0x01):
{sendmsg1();
delay_ms(1000);
sendmsg2(dat1);
break;
}
case(0x02):
{sendmsg1();
delay_ms(1000);
sendmsg2(dat2);
break;
}
case(0x03):
{sendmsg1();
delay_ms(1000);
sendmsg2(dat3);
break;
}
case(0x02):
{sendmsg1();
delay();
sendmsg2(dat4);
break;
}
}
}
}

void sendmsg1()
{
usart_init(9600);
for(j=0;j<4;j++)
{
usart_write(init[j]); //Veryfing gsm modem
}
delay(); //30sec delays
usart_write(0x0A); //new line
for(l=0;l<11;l++)
{
usart_write(mes[l]); //setting the format
}
delay();
usart_write(0x0A);
for(m=0;m<22;m++)
{
usart_write(num[m]); //setting the number
}
delay();
usart_write(0x0A);
}

void sendmsg2(unsigned char array[])
{
for(n=0;n<=25;n++)
{
usart_write(array[n]); //Transmitting the message
}
usart_write(0x0A);
delay();
usart_write(end);
delay();

}

void delay() //30sec delay
{
unsigned char y;
for(y=0;y<30;y++)
{
Delay_ms(1000);
}
}


please kindly help me and im very thankful to you
 

I didn´t see at your program the statements wich enables and configures serial communications ( baud rate, pins, etc... ).

+++
 

I didn´t see at your program the statements wich enables and configures serial communications ( baud rate, pins, etc... ).

+++


sir, actually i initiated the baudrate at the funtion "sendmsg()" i.e is im initiating the buadrate every time s started to send the new msg, actually my problem with this program is that im getting constant 5volt at the transmitter pin (PORTRC6), PLAESE KINLY HELP ME TO COMPLETE MY PROJECT THIS IS JUST AN ONE PART OF MY PROJECT PROGRAM ONLY AND ALSO I PLANNED TO RECEIVE THE MSG FORM THE MODEM AND ACCORDING TO THAT THE PERIPHERAL HAS TO WORK
 

i think it maynot the problem of the program but not proper handshaking of the gsm modem, check the device by connecting it to the PC's serial port and give the return message as the gsm modem give. if the messages and the program ready give the proper hand shaking to gsm modem. that is the good and professional way. shorting some pins may also give the proper O/P, but it is not a good way.
 

thank you for your answer , actually i used to check the output voltage at the output pin. when i use the atmel controller in keilc i saw the variation of changing the voltage. in pic i get just the 5 volt only without any variations
 

...actually i initiated the baudrate at the funtion "sendmsg()" i.e is im initiating the buadrate every time s started to send the new msg...

This is not a proper way to implement a communication process flow.
You must setup UART module once.

In general, hardware modules after setup behaves differentlly than in continous operation.
For instance, there are some 8051 branches, whose UART have issues regarding loose of transmission of 1st character after setup.

+++
 

the (25th) transmition pin of the pic controller, but now what happeing means i connected my controller with the hyper terminal from my guidance advaise, im getting the some characters but not what i mentioned in the program, and aslo in microC software's hyper terminal
 

Is not yet clear if you considered what was pointed above.

+++
 

thank you to all now i can able to send the message from the controller, actually the problem is with my controller only and not in the program the mentioned above program is correct only, now any one can help to receive the message from the GSM modem and and control the any device with that,



i'm requesting to all that please reply me as soon as possible
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top