Problem to receive character in PIC18

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

Problem to receive character in PIC18

Postby nurul » Mon Jun 20, 2011 3:18 pm

hii..

My PIC18 has problem to receive a character from PC. I'm using Visual Basic 6 in PC to give command to PIC to read current temperature. I'm also using zigbee to transmit and receive data between PC and PIC. The coding in VB6 is to send a character 'a' when button command is clicked. So my PIC18 should receive the character and execute the next line of instruction where to measure temperature. How to read the character in PIC and proceed the next line using soft_uart?
I've tried this coding but the PIC seems like not receive the character..
Soft_UART_Read(inputr);

if (inputr == 'a')
{
measure temperature
}
nurul
Freshie
 
Posts: 4
Joined: Mon Jun 20, 2011 3:02 pm

Re: Problem to receive character in PIC18

Postby shahrul » Mon Jun 20, 2011 7:19 pm

nurul WROTE:I've tried this coding but the PIC seems like not receive the character..
Soft_UART_Read(inputr);

if (inputr == 'a')
{
measure temperature
}

What compiler you use that function?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Problem to receive character in PIC18

Postby kl84 » Thu Jun 23, 2011 2:47 pm

Did you successfully compiled the code? What's the Sof_UART_Read(inputr)'s actual code?
User avatar
kl84
Amateur
 
Posts: 166
Joined: Thu Jul 08, 2010 12:14 pm

Re: Problem to receive character in PIC18

Postby nurul » Mon Jun 27, 2011 3:37 pm

Thank you for ur reply :)
i use mikroC compiler version 8.2..
i successfully compiled the code..but i'm not sure on the coding..i've tried the template in help but it's not working.. my PC can receive the temperature using soft_uart_write function..i want to add a command from PC to request sensor to read the temperature..how pic wants to receive a character and execute the measuring code? actually when i click command button in PC it sends 'aaaaaa' non-stop..i assume when the pic receive 'a', the next line will run..
nurul
Freshie
 
Posts: 4
Joined: Mon Jun 20, 2011 3:02 pm

Re: Problem to receive character in PIC18

Postby Brian Griffin » Mon Jun 27, 2011 3:41 pm

nurul WROTE:Thank you for ur reply :)
i use mikroC compiler version 8.2..
i successfully compiled the code..but i'm not sure on the coding..i've tried the template in help but it's not working.. my PC can receive the temperature using soft_uart_write function..i want to add a command from PC to request sensor to read the temperature..how pic wants to receive a character and execute the measuring code? actually when i click command button in PC it sends 'aaaaaa' non-stop..i assume when the pic receive 'a', the next line will run..


Do you have a full code here so that we can point out the problem? :)

Also - what is the microcontroller used there?
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: Problem to receive character in PIC18

Postby nurul » Sun Jul 10, 2011 5:40 pm

I use PIC18F4558 with mikroc v8.2..

I've tried the coding below for PIC using mikroC to turn on LED if the PIC receive the command from VB, just for testing but it doesn't work. Where should i include to receive the 'a' in the coding? Plz help me..Is it Soft_Uart_Read must be used with Soft_Uart_Write? My problem is i just want to receive the character 'a' and go to next line, which is no need the write function..is there any other method which can solve my problem? Plz help me :(

do
{
data = Soft_Uart_Read(rec);
} while (!*rec);

if (data)
{
PORTB = 0x80;
}
nurul
Freshie
 
Posts: 4
Joined: Mon Jun 20, 2011 3:02 pm

Re: Problem to receive character in PIC18

Postby aurora » Sun Jul 10, 2011 10:35 pm

Did you use pointer intentionally? Try remove * from ! *rec
Did you declare data as char or int?
Did you assign data = 'a'?
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: Problem to receive character in PIC18

Postby nurul » Sun Jul 10, 2011 11:21 pm

Did you use pointer intentionally? Try remove * from ! *rec
Did you declare data as char or int?
Did you assign data = 'a'?


I've tried by remove the * but still not working..
i've also tried to declare the data as char or unsigned short as in the template but still doesn't works..
yes, i did the code:
if(data='a')
i'm still wondering why the soft_uart_write should be used together with the soft_uart_read..it seems like if the write function not included an error of _invertMaskWr:argument not found occurs..
maybe the PIC can't receive data from PC by using mikroc software..how to solve my problem?
nurul
Freshie
 
Posts: 4
Joined: Mon Jun 20, 2011 3:02 pm

Re: Problem to receive character in PIC18

Postby aurora » Mon Jul 11, 2011 10:19 pm

Seems like an old problem from an old thread: here

How about changing

data = Soft_Uart_Read(rec); into
data = Soft_Uart_Read(&rec);

source: here
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 4 guests