PDA

View Full Version : Tx and Rx of Single Pin PIC's



Dwayne
- 26th May 2004, 15:55
Hello Folks!

AFter the 3rd attempt to get this on the board for a couple of folks
who asked for it, I finally put it in a notepad text, and got things edited before uploading to the forum...Whew.

The idea behind this Single pin TR, is quite simple. It is the timing that is the critical part.

I wanted something that could transmit at full speed of the chip, with little to no interference of delays. I also wanted something to control the speed, just in case a person uses a LCD.

The trick, is to have the Transmitter *faster* than the receiver at the initialization of the startup, then have the Receiver *faster* than the transmitter until all data has been sent.

If you decided to change things on these short little programs, Please let me know! I would be curious on what ideas can be implemented along with these programs.

If you like this, or dislike it, please drop me a response.


'************************************************* ***************
'* Name : SinglePinRec.BAS *
'* Author : Dwayne *
'* Notice : Copyright (c) 2004 Dwayne *
'* : All Rights Reserved *
'* Date : 4/12/04 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
TRISa=%00110000
TRISb=%00000000
Counter var byte
Counter2 var byte
WatchDog var word
Result var byte
Togg var byte

'You can skip the following 14 lines, and send this data
'to the LCD, instead of manually doing it in the Chip
*********Start of a LCD Control and/or Verify this are working ********
Pause 500
Porta.0=0
Porta.7=0
Portb=13 'clear lcd
Porta.0=1
Pause 1
Porta.0=0

'Flashes LED
Porta.1=1
Pause 1000
Porta.1=0
Counter=0
**************************End of Verify****************
Loop3
Counter2=0
Result=0
Togg=Porta.4 'Receiving Port for Data
Loop2:
'Wait Until Pin Changes
if Porta.4=Togg then Loop2


'Allow enough time for transmitter to set value
'Eventhough this is 25, it can be set to a much lower value.
Pauseus 25

'Assign Value from pin to result and Left Shift
Result=Result << 1
Result.0=Porta.4


'Assign Pin to Value, so we can tell if it is toggled
Togg=Porta.4

'Do we have 8 transmissions? for a byte?
Counter2=Counter2+1
WatchDog=0
if Counter2 < 8 then Loop2

Counter2=0 'Reset bit counter

' You now have all 8 bits, and ready to do something with it.


***********Following is for LCD ********************
'Porta.7 is a data/Command Toggle bit.
Porta.7=1
Portb=Result
'Toggle Porta.0 'For some reason toggle does not work
'Toggle Porta.0 'For some reason, toggle does not work
'I believe it is because there is way too much code being
'generated, and causes too long of a delay
Porta.0=1
Porta.0=0
************************************************
goto Loop3
end




'************************************************* ***************
'* Name : Tran1pin.BAS *
'* Author : Dwayne *
'* Notice : Copyright (c) 2004 Dwayne *
'* : All Rights Reserved *
'* Date : 4/12/04 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
ANSEL=%00111000
CMCON=%00010111
TRISIO=%00011100
ADCON0=%00001100
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

counter var byte
counter2 var byte
Digloop var byte
Dignum var byte
Number var word
Number=1685 'Hey lets send a test number!
'Following loop just waits for start
Loop:
'Flash a light to make sure Chip is working
***************************************
GPIO.5=1
Pause 300
GPIO.5=0
Pause 300
**************************************
'This pin is just a holding pin, so you can control
'when you want the data to be sent.
'You want to be ready to see it don't you?
if GPIO.2=0 then Loop

'Remove following for AD converter
'ADCIN 3, number
'number = number >> 6

For counter = 7 to 0 step -1
DigNum=number dig counter 'get each individual number
Dignum=Dignum+48 'convert it to a 8 bit Decimal

for counter2= 1 to 8 step 1
'Toggle Pin to force Reciever to work
Toggle GPIO.0
'Allow enought time for Rx to accept value
'this Pause will work on anything less than 26
'But I chose 15 for the average or fun of it.
pauseus 15

'Assign Value and allow time for Rx to read it
GPIO.0=DigNum.7
Pauseus 20

'Get Next Number
DigNum = DigNum << 1
next counter2

'This pause controls how fast each of the data bits
'are transmitted. You can actually remove it, if you like
'but I use it to control what I see on my Display.
'The higher the number, the slower the data transmission
Pause 1
Next counter

Goto Loop

End