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.

Problem with code for pic16f628 and PC communication via serial port(rs232)

Status
Not open for further replies.

scgoo

Newbie level 4
Joined
Mar 6, 2006
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malacca
Activity points
1,352
hi, im using PIC16f628 for my design. the program will receive signal in the form of character as shown in the code below. PC and PIC will communicate via serial port(rs232).

but when i send a "A" to the PIC, it didnt go to the "TurnLeft" subroutine, but it go to the "Confuse". it is same happen when i send "B", "C" , D, E to the PIC. it will go to the "Confuse". but when i send a character "W" ,it will take it as "D" and go to the Sad , and send "Y" it will take it as "C", and send "u" it will take it as "E".

why will this happen??
i'm confusing...
any suggestion? pointer?
thanks!



''''''''''''initialization'''''''''''
success = 0: i = 0 : bell_on = 0

init:
INTCON = %11000000
PIE1.5 = 1
ON INTERRUPT GoTo handler




main:
if success = 1 then
bell_on = 1
confirm = 0
i = 200
while (i != 0)
i = i - 1
pause 5
wend

if (store = "A" ) then
gosub TurnLeft
confirm = 1
endif

if ( store = "B" and confirm <> 0 ) then
gosub TurnRight
confirm = 1
endif

if (store = "C" and confirm <> 1) then
gosub Happy
confirm = 1
endif

if (store = "D" and confirm <> 1) then
gosub Sad
confirm = 1
ENdif

if (store ="E" and confirm <> 1) then
gosub Angry
confirm = 1
endif

if (confirm <> 1) then
gosub Confuse
ENdif

confirm = 0
success = 0
bell_on = 0

endif

goto main

Happy:
LED = 1
PORTA = %00000111
PAUSE 500
LED = 0
PAUSE 500
return

Sad:
PORTA = %00000010
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return

Angry:
PORTA = %00000011
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return


Confuse:
PORTA = %00000100
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return


TurnLeft:
PORTA = %00000101
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return


TurnRight:
PORTA = %00000110
LED = 1
PAUSE 500
LED = 0
PAUSE 500
return


'''''''''''''''interrupt'''''''''''
disable

handler:
hserin 10,error,[store]
success = 1


ERROR:
resume
enable
 

pic16f628 HELP!!

Hi scgoo!

You haven't posted the complete code. Check the serial port initialization registers in pic and set appropriate baud rate in pc as well.

Giri
 

Re: pic16f628 HELP!!

Salam Scgoo,

i didn't try your code but what i remember is that the IF - THEN statement is not written like that : "if ( store = "B" and confirm <> 0 ) then"

You should write it like that : "IF (store = "B") AND (confirm <> 0) THEN"

Finally My advice is to Try using C language it would make it much easier for u

Hope that helps

Regards,
 

Re: pic16f628 HELP!!

thanks for tour reply.!

define OSC 20
define HSER_BAUD 9600
DEFINE HSER_CLOERR 1
define HSER_RCSTA 90H
DEFINE HSER_TXSTA 20H

i use 9600 baud rate. same for my hardware device

and i have changed to

if ( store = "B") and (confirm <> 1) then
gosub TurnRight
confirm = 1
endif

it also cant work.
 

Re: pic16f628 HELP!!

Hello Scgoo,

I'm not sure what compiler you are using, but two things come to mind here.

if (store = "A" ) then

Most development environments I've used use = to equate, and == to test equality, so you might try
Code:
 if (store == "A") then ...

Also, you could try
Code:
 if (store == 0x41)

hex41 being the ascii for 'A' (bin 01000001) If this works, then you need to convert your letters to ascii codes.

Hope this helps,
Robert
 

Re: pic16f628 HELP!!

Salam Scgoo,

First u have to adjust your PC terminal to the same options u used for your code (the same as what u used in your defines - parity, error, baudrate).

All the Pins u made input in your Code must be pulled high or low throught a resistance.

Don't use "==" for conditions is PICBasic, just use "=".

Finally I don't see anything Wrong in your Code, it's Very simple and straight forward so i would like to ask u about the hardware interface between the PIC and the PC what kind of RS232 transievers have u used?

Waiting for your reply

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top