PDA

View Full Version : is it possible?



SuB-ZeRo
- 12th June 2005, 01:57
Hi it's me again :) with my strange question.
Here is the question.
i have pic 16F877 connected to 2 x 16F628 and 2 x (16x2) LCD and a keyboard
i want to use pic 16F877 as master controller connected with PC (1. connection) and try to use another LCD controlled by 16F628 again connected with 16F877 (2. connection) and the last connection again connected with 16F628 (3. connection)
in the picture u can see the shema of the question.
How can i use HSERIN and HSEROUT commands to control them?Is there any solution to control them.If any body could give me an example i will really be glad.Thanks for reading my strange question.

mister_e
- 12th June 2005, 12:39
O.K that's not strange and i see one improvement that should be done first to make it simple.

About those LCDs, you can control more than 1 LCD with the same PIC, you just need few external parts. see the following thread, everything is really well explain. code and schematic are included
http://www.picbasic.co.uk/forum/showthread.php?t=626
so now you save one PIC, code, money, time....

Now, about the other 16F628... what will be his purpose, do you want to have bidirectional communication, i mean, do you want that the master send a command then receive the according answer from the 16F628???
If so, kepp the HSERIN/HSEROUT for your PC communication and use SERIN/SEROUT/SERIN2/SEROUT2 to talk to that device.



' This is the snip of the Master PIC16F877
'
' This will send a byte to the PIC16F628 and
' waiting for a reply. If there's no reply
' after 2 second it will display an error
' message to the LCD.
'
SerialOUTToPIC16F628 var PORTC.0
SerialINFromPIC16F628 var PORTC.1

SentByPIC16F628 var byte

SendMeBeer con 0 ' command bytes
SendMeFruit con 1 ' to be
SendMeCash con 2 ' send
'
T2400 con 396 ' used for baudrate=2400
TimeoutDelay con 2000 ' used for timeout=2000 mSec=2 Sec

HIGH SERIALOUTTOPIC16F628 ' For safety sake and avoid to send
' garbage at the first time

start:
pause 2000 ' LCD start-up delay AND future LCD message duration
lcdout $fe,1 ' Clear LCD screen

serout2 serialouttopic16f628 ,T2400,_ ' send command byte to
[sendmebeer] ' the external PIC16F628

serin2 serialinfrompic16f628,T2400,_ ' waiting for
timeoutdelay, DisplayErrorMessage,_ ' the external
[sentbypic16f628] ' PIC16F628 answer

' jump to different routine
' depending of the
' SentbYPIC16F628 value
'
branch sentBYpic16f628,[Budweiser,_ ' when = 0
MolsonDry,_ ' when = 1
SmirnoffIce]' when = 2
goto start

' Timeout occur, display
' the error message
'
DisplayErrorMessage:
lcdout "Looks like my",_
$fe,$c0,"buddy sleep!!"

goto start

BudWeiser:
lcdout "Let's drink a ",$fe,$C0,_
"Budweiser Barrel"

goto start

MolsonDry:
Lcdout "lezzz dwwwwrank",$fe,$c0,_
"a MolsonDry pot"

goto start

SmirnoffIce:
lcdout "ZZZzzzzzzZZ i i",$fe,$c0,_
"loowve you....."

goto start




' This is the code snip for the PIC16F628
'
' This will wait for a PIC16F877 command request
' and return a byte value.
'
SerialOUTToPIC16F877 var PORTB.0
SerialINFromPIC16F877 var PORTB.1

SentByPIC16F877 var byte
SendToPIC16F877 var byte

Budweiser con 0 ' command bytes
MolsonDry CON 1 ' to be
SmirnoffIce CON 2 ' send
'
T2400 con 396 ' used for baudrate=2400

high SERIALOUTTOPIC16F877 ' For safety sake and avoid to send
' garbage at the first time

start:
serin2 serialinfrompic16f877,t2400,_ ' waiting for
[sentbypic16f877] ' the external
' PIC16F877 answer
'
branch sentbypic16f877,[SendMeBeer,_ ' =0
SendMeFruit,_ ' =1
SendMeCash] ' =2

goto start

SendMeBeer:
sendtopic16f877=budweiser ' open the fridge and choose your beer
goto SendData ' send it to master

SendMeFruit:
' do according stuff
goto SendData

SendMeCash:
' do according stuff
goto SendData

SendData:
serout2 serialouttopic16f877,t2400,[sendtopic16f877]
goto start


Above are just rough example. Should be enough to start.

For the PC communication you can use the internal USART module or still use SERIN/SEROUT stuff. As i remind, that part you already know how to play with in PIC amd in VB.

for your keyboard... hard to know wich kind you use but if it's a matrix one, you can find code example almost everywhere... Click here to download the Melabs keyx.bas file (http://www.melabs.com/resources/samples/x1/pbp/keyx.bas)