PDA

View Full Version : SERIN AND SEROUT PROBELM USING 16f690 PIC



Charles
- 18th January 2007, 00:45
HI , i have a little project...i have problem in sending data from one pic to another PIC using serin and serout...i'm using keypad to get the input(therefore the input will be a number) and i want to send it to the second pIC and display it on the LCD.

The problem is when i press the keypad, when i display it on the LCD it always give 0..i'm sure myway accessing the keypad is correct but the way to sending the data to the another pic maybe isn't correct..

CAN ANY ONE HELP ME PLEASE WITH THIS PROBLEM BECAUSE I ONLY HAVE 2WEEKS LEFT BEFORE MY PROJECT due date time..

HERE IS MY CODE

---------KEYPAD(TRANSMITTER)---------

INCLUDE "bs2defs.bas"
DEFINE CHAR_PACING 500
ANSEL=0
TRISC = %10000111 ; port for keypad
TRISB = %00000000
dgood var portB.4 ;indicate that anykey has been pressed or not
outpin var portB.7 ; output to another PIC

col1 var portC.0
col2 var portC.1
col3 var portC.2
row1 var portC.3
row2 var portC.4
row3 var portC.5
row4 var portC.6
val var byte

define OSC 8

getkey:
pause 50
high dgood ; if high no key is pressed

;check which number has been pressed
row1=0
if col1 = 0 then one
if col2 = 0 then two
if col3=0 then three
row1 =1

row2=0
if col1 = 0 then four
if col2 = 0 then five
if col3=0 then six
row2 =1

row3=0
if col1 = 0 then seven
if col2 = 0 then eight
if col3=0 then nine
row3 =1
row4=0
if col1 = 0 then star
if col2 = 0 then zero
if col3=0 then hash
row4 =1
goto getkey

one:
val =1
goto valid
two:
val =2
goto valid
three:
val =3
goto valid
four:
val =4
goto valid
five:
val =5
goto valid
six:
val=6
goto valid
seven:
val =7
goto valid
eight:
val =8
goto valid
nine:
val =9
goto valid
star:
val =%00101010
goto valid
hash:
val =%00100011
goto valid
valid:
low dgood ; if any key pressed make it low and star send data
serout outpin,t2400,[val]
keypress:
if (col1&col2&col3)<>1 then keypress;check if key has been released or not
goto getkey


------------------receiver---------------
INCLUDE "bs2defs.bas"
DEFINE LCD_DREG portC
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG portA
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG portA
DEFINE LCD_EBIT 1
DEFINE LCD_LINES 2
DEFINE LCD_BITS 8
DEFINE LOADER_USED 1
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAAUS 250
DEFINE OSC 8

ABSEL =0
trisB=%11111111
keyinput var portB.5 ;port that received data from the transmitter
num var byte ; containing the numbers that will be display
valid var byte;indicator that key has been pressed and start receive data

pause 50
loop:
lcdout $FE,1
LCDOUT $FE,$80
lcdout "ENTER polarity"
LCDOUT $C0
LCDOUT "1)+ 2)-"
gosub wait1
LCDOUT $FE,$C0+11,#num
pause 500
goto loop

wait1: ;wait until key has been pressed
if valid =1 then wait1
serin keyinput,t2400,num

wait2:;wait until key has been released
if valid = 0 then wait2
return
end

HOPE U GUYS CAN HELP ME>..THANX VERY MUCH

end
thanx

skimask
- 18th January 2007, 02:01
CAN ANY ONE HELP ME PLEASE WITH THIS PROBLEM BECAUSE I ONLY HAVE 2WEEKS LEFT BEFORE MY PROJECT due date time..

HOPE U GUYS CAN HELP ME>..THANX VERY MUCH

end
thanx



Somebody stop me before I get started!!! :D

skimask
- 18th January 2007, 02:05
Q: What sets the valid in the RX code?
A: Nothing.

So the program is doing exactly what you set it up to do...nothing but sit in a stuck loop. Which loop? Your turn to figure that one out. Hopefully it doesn't take you 2 weeks to do that. Maybe ask your instructor for some instruction on how to follow basic logic from start to finish...or in this case, from start to stuck...

Charles
- 18th January 2007, 02:15
what sets the valid in Rx is the dgood(pin) from transmitter so whenever the key pressed, the dgood become low and it is connected through wire to the valid pin in receiver so it will go out from the wait loop and display...
the thing is all goes well accept the value inside the num(register) is 0 when i display..is the way i use the serin and serout is correct?...do u have any suggestion..thanx very much

skimask
- 18th January 2007, 02:19
what sets the valid in Rx is the dgood(pin) from transmitter so whenever the key pressed, the dgood become low and it is connected through wire to the valid pin in receiver so it will go out from the wait loop and display...
the thing is all goes well accept the value inside the num(register) is 0 when i display..is the way i use the serin and serout is correct?...do u have any suggestion..thanx very much


Ok, back to you again, what sets valid = 1 or valid = 0?

Charles
- 18th January 2007, 02:27
in the transmitter part
u see the dgood pin..it is connected to valid pin in receiver...
therefore whenever i press the keypad, dgood become low which indicate valid =0...therefore it will goes out from the wait loop (in the receiver part) and display the number inside

Archangel
- 18th January 2007, 02:46
Hey Charles, you suppose we could see a schematic? It sort of looks as if you want to send serial data from one pic to the other, hence skimasks question, but if you have everything all hardwired together, then we need to see how.
JS

Darrel Taylor
- 18th January 2007, 02:55
in the transmitter part
u see the dgood pin..it is connected to valid pin in receiver...

Yes, but on the receiver side, valid is a BYTE, not a Pin.

So back to skimask's question,
"What sets the valid in the RX code?"
<br>

Charles
- 18th January 2007, 02:56
dgood (portB.4) from PIC1 i connect it to valid(portB.6) from PIC2...sorry there is a mistype in the code it should be valid var portB.6 not valid var byte...then otupin(portB.7) from PIC1 is connected to keyinput(portB.5) from PIC2)/....yup i'm trying to send data serially from pic1 to pic2...any suggestion?thanx very much...

best regards
Charles

skimask
- 18th January 2007, 03:04
Yes, but on the receiver side, valid is a BYTE, not a Pin.

So back to skimask's question,
"What sets the valid in the RX code?"
<br>

But he's only got TWO WEEKS!!!! AAAaaaaaaaaaaaaa.............

Darrel Taylor
- 18th January 2007, 03:33
Easy skimask, Down boy, Down!

Let me take this one ...

I'm always skeptical when someone Cut&Pastes their entire program into a Post.
And, the one thing that points out a definate cause of the described problem suddenly turns into a "typo".

In the middle of a Cut&Paste? Come on!

See, I can do it too. :(

Ok well, my advice is to dump the keypad routine, and use this...

Matrix Keypad routine (mister_e)
http://www.picbasic.co.uk/forum/showthread.php?t=3250

Then take a look here...

How to make your own PIC network (mister_e)
http://www.picbasic.co.uk/forum/showthread.php?p=5708
Not exactly what you are doing, but the concepts are the same. Just 2 PIC's instead of many.
<br>

Charles
- 18th January 2007, 03:34
The output my program right now when i display on the lcd is

ENTER POLARITY
1)+ 2)- 0(this zero should be number that is pressed on the keypad)

Darrel Taylor
- 18th January 2007, 03:46
OK skimask,

You have my permission.

Pfft!
<br>

skimask
- 18th January 2007, 03:59
OK skimask,

You have my permission.

Pfft!
<br>

Well, I'm guessing that he's using one of them thar 17C756, or maybe not. I can't tell.

And I'm also guessing that he's using a bunch of switches, maybe even, dare I say, a telephone keypad, probably without any pullup or pulldown resistors (although there are ways around that). Again, I can't tell.

And I'm betting that the search function hasn't been used much, 'cause there's a lot of info out there on connecting 2 PICs together and using a matrix style keypad. I'm at a loss...

Oh, and I've got this car, it's making this noise. Can you help?

Back at ya...