PDA

View Full Version : Pic16f84 and wait byte



irmus
- 3rd November 2004, 09:42
Hello. Mayby yuo can say how i have to do that:
Me need that portb.0 wait when i in thim send from lpt high level

I have code

input portb.0
low portb.0

Thanks

Dwayne
- 3rd November 2004, 14:31
Hello Irmus,

Irmus>>Hello. Mayby yuo can say how i have to do that:
Me need that portb.0 wait when i in thim send from lpt high level

I have code

input portb.0
low portb.0
<<

Ok, I am trying to understand what you are saying. I hope that I am correct.

You want Portb.0 to make the PIC chip wait until a signal comes?

SleepPin var Portb.0
while SleepPin=High
Wend

This will cause the chip to wait until PortB.0 goes low... then the
chip will continue on. Sorry if this is not what you want.


Dwayne

irmus
- 3rd November 2004, 17:27
Thanks! It work! How me this do:
I have 8 bits from lpt (impuls) 10011010 how me get hex from impuls , mayby use pulsein command?

mister_e
- 3rd November 2004, 17:47
you want receiuve them serial or parrallel ???

if it's parrallel.

this example use all the 8 pins from PORTB. PORTA.0 is the receive acknoledge pin

SleepPin VAR PORTA.0
RParrallel VAR BYTE


while SleepPin=High
Wend
RParrallel=PORTB

vallue is store into RParrallel.

if you want to receive in serial use SERIN statement. The following will receive data from PORTB.0 pin. I assume you have an MAX232 between PC and PIC

Rserial VAR BYTE

SERIN PORTB.0,4,Rserial

in case you don't have any MAX232 between PIC and PC use

SERIN PORTB.0,0,Rserial

the above assume that you use 2400 baud. In case baudrate is different be sure to have the right crystal to be able handle your specific baudrate. 20MHZ crystal is suitable for 9600 serial comms.

regards

Dwayne
- 3rd November 2004, 17:51
Hello Irmus,

Irmus>>Thanks! It work!<<

Great! I am happy that it work for you.

Irmus>> How me this do:
I have 8 bits from lpt (impuls) 10011010 how me get hex from impuls , mayby use pulsein command?<<

Your LPT port... Is it a Serial Port? or Parallel Port?

If it is Serial, you may want to use SERIN or use a built in USART. If It is a parallel, YOu will need a chip with a 8 pin Port (like portb of most chips). you will wire up your data pins directly to the portb. and send/receive 8 bits at a time.

Dwayne

irmus
- 3rd November 2004, 18:11
I using LPT port SPP mode

mister_e
- 3rd November 2004, 18:16
http://www.hw-server.com/docs/scp_ecp.html

irmus
- 3rd November 2004, 18:33
I now how work lpt but i dont now how from 10011001 make hex in the pic

mister_e
- 3rd November 2004, 18:41
see my post few lines above...

Dwayne
- 3rd November 2004, 18:54
Hello Irmus,

Irmus>>>I now how work lpt but i dont now how from 10011001 make hex in the pic<<

Mister_e gave you some excellent code for doing this.

what happens with Mister_e's code, when data is sent via Parallel port to PortB, it is *already* in Hex format!...

Mister_e's code:

RParrallel VAR BYTE

while SleepPin=High
Wend
RParrallel=PORTB

RParallel will have your 10011001 value...
the hex value is 99. (split your data into 2 groups of 4)
MSB LSB
10011001 = 1001 1001
= 9 9

Hex=99

Dwayne

irmus
- 3rd November 2004, 19:03
I dont now how to say!!!!
I read one bit from lpt after next - until 8 . How this bits conect to one , in one variable?

mister_e
- 3rd November 2004, 19:14
with my code you'll read 8 bit in one operation


you must connect DB25 b0-b7 to input PORTB b0-b7

Dwayne
- 3rd November 2004, 19:15
Hello Irmus,

Irmus>>I dont now how to say!!!!
I read one bit from lpt after next - until 8 . How this bits conect to one , in one variable?<<

Ok...SPP is using a Parallel connection... You read all 8 bits at once. You can do this with Portb of most PIC chips. This is the Code the Mister_e gave you, and I have been trying to explain. You told us that you are using SPP (standard Parallel Port). In SPP, you read *all* 8 bits at a time.

Now, you are telling us you are reading 1 "bit" at a time. this is not SPP. This is serial communication.

Mister_e gave you some code on Serial communication too. Using SERIN.

Mister_e's code.

SERIN PORTB.0,0,Rserial

this command will automatically take your eight bits and put them into Hex format. that format will be the variable Rserial.

So Rserial will have the value "10011001" or hex 99.

Dwayne

irmus
- 3rd November 2004, 19:17
But this EPP mode , i using SPP

Dwayne
- 3rd November 2004, 19:37
Hello Irmus,

But this EPP mode , i using SPP


Ok, lets add another variable then...

Bit14 Var byte (bits1-4)
Bit58 Var Byte (bits 5-8)
RParrallel VAR BYTE

while SleepPin=High
Wend

Bit58=PORTB '(receive MSB)
while SleepPin=Low 'wait until pin goes high
Wend
while SleepPin=High 'wait until pin goes low to transmit new data
Wend
Bit14=PORTB

RParrallel=Bit58
RParrallel=RParralel<<4 'shifts the bits over
RParrallel=RParrallel +Bit14
LCDout RParrallel

What this does, is read the 1st 4 bits, stores it in a variable
reads the next 4 bits and stores it in another variable.
then adds them together to the final result. a couple of problems here...

1. I don't know if they transmit the MSB first or the LSB first.

I am not sure if the above code will work for you. I have no way of testing it out.

Dwayne

irmus
- 3rd November 2004, 20:33
Yuo mayby dont understand what i want to say.
I read bit 1 in the pic from lpt , i wait next bit i get him and until 8,
how all bits conect to one byte, example in hex $D5 and store in Eprom. How store in Eprom i now but how with bits? Help
Thanks

Dwayne
- 3rd November 2004, 23:03
Hello Irmus,

Sorry about misunderstanding you...

Irmus>>Yuo mayby dont understand what i want to say.
I read bit 1 in the pic from lpt , i wait next bit i get him and until 8,
how all bits conect to one byte, example in hex $D5 and store in Eprom. How store in Eprom i now but how with bits? Help
Thanks<<

Reading one bit at a time through 1 pin, you use Serin, or Serin2 with the correct baudrate. These commands will automatically read 8 bits for you and put them in hex format.
Reading 8 bits at a time works teh same way...just read the entire port.

Reading 4 bits at once, and combining two 4 bits has been given to you. The only thing I can think of that has not been given to you is a non-compatible serial type of communication. so I am sending you this kind of serial communication.

Ok, I am going to try again... a different way....I am sorry if the code we have given you is not the correct code, or what you are looking for. We are trying our best.

SleepPin VAR PORTA.0
HexVal var byte

counter var byte

Loop:
HexVal=0; 'initialize to zero
for counter=0 to 7
while SleepPin=High
Wend
HexVal=PORTB.1 'or whatever pin you receive data.
HexVal=HexVal<<1
while SleepPin=Low 'allows time to reset sending pin.
Wend
next counter

LCDout HexVal
goto Loop:

mister_e
- 4th November 2004, 00:21
Yuo mayby dont understand what i want to say.
I read bit 1 in the pic from lpt , i wait next bit i get him and until 8,
how all bits conect to one byte, example in hex $D5 and store in Eprom. How store in Eprom i now but how with bits? Help
Thanks


maybe i'm dumb to write it but...

1 bit : 1 element
1 BYTE = 8 bits = 8 element
1 WORD = 2 BYTE = 16 Bits = 16 elements.


D5 hexadecimal = 1 byte = 8 bits = 213 in decimal value = 11010101 in Binary value

you're using SPP=Standard Parrallel Port.

so if you send to LPT port D5 = 213 decimal = 11010101 binary you will send the 8 bits, 1 byte , D5 in one task to LPT port.

this is why you must use:

DataFromLPT VAR BYTE ; 8 bits
PICPortPinsToReceiveFromLPT VAR PORTB

start:
DataFromLPT=PICPortPinsToReceiveFromLPT


After receiving D5 from your PC DataFromLPT variable = D5 = 11010101 bin =213 decimal

But maybe you want to receive 8 BYTES and to store them into one variable, in this case you must use ARRAY.

the following will receive 8 BYTES from LPT and store it into My8BYTES array

SleepPin VAR PORTA.0

RParrallel VAR BYTE
My8BYTES VAR BYTE[8]
Loop VAR BYTE

for loop=1 to 8
while SleepPin=High
Wend
RParrallel=PORTB
My8BYTES[loop]=RParrallel
next


Maybe i'm totally out of what you're asking but... TELL ME what i'm missing. i really want to help but sometime i may be wrong in the way i understand your question... maybe caused by my french native language :)

Don't be afraid to reply

regards

Dwayne
- 4th November 2004, 14:53
Hello Steve,

Steve>>Maybe i'm totally out of what you're asking but... TELL ME what i'm missing. i really want to help but sometime i may be wrong in the way i understand your question... maybe caused by my french native language <<

Yes, sometimes language barriers are a problem. But IMO that is what makes this site so special. Melanie, Ralph, You and everyone else have been so patient to help me and others... On some of the simplistic things, to the difficult. But at least everyone tries their best to help out and support each other to the best of their ability..even when the answers were not quite the correct answer to the question because of langauge barriers.

Dwayne

irmus
- 4th November 2004, 20:10
Hello!
I have code

baitas var byte

baitas = $80
baitas = baitas or $20
write 0,baitas

Why in the eprom FF, must be $A0
Thanks

mister_e
- 4th November 2004, 23:49
must you this line instead

baitas = baitas | $20

OR is logical operation..(IF THEN ELSE)

| is a bitwise operation