Ok, so if I used all the pins on my 08 chip and wanted to flash an LED on the GPIO pin, how do you do it? Do you disconnect the download cable with a line of code and then take command of the pin in the normal way?Flashing a LED does not need a protocol or the use of a specific peripheral, except from the GPIO pin.
You don't even need to disconnect the download cable. You can just add a LED+R to the Download SEROUT pin, pin 0, leg 7 ....Ok, so if I used all the pins on my 08 chip and wanted to flash an LED on the GPIO pin, how do you do it? Do you disconnect the download cable with a line of code and then take command of the pin in the normal way?
TX <-----------------------------.
.--._.--. |
___ -|V+ 0V|--. | LED
RX >---.---|___|-->|SI SO|--|--^--|>|--.
.|. -| |- | .|.
| | -| |- | | |
|_| `-------' | |_|
| | |
0V ----^----------------------^----------^--
AFAIK PICaxe doesn't have one GPIO (General Purpose Input Output) pin, although most pins can be considered as such. However, if you mean the "Programming" (Serial I/O) pins, then the two of these are quite specifically defined as "Input Only" and "Output Only" respectively. The Serial/Programming Output pin can indeed be used for other purposes, provided that you remember that it always starts at an output zero level (not tri-state like most other PICaxe pins) and will indeed carry spurious "0/1 data" levels during programming. In practice it is also possible to use that pin as an Input, but not really recommended except for very special (advanced) purposes.... wanted to flash an LED on the GPIO pin, how do you do it? Do you disconnect the download cable with a line of code and then take command of the pin in the normal way?
Are those blinking LEDs really "hardware?" Every manufacturer seems to have their own secret way to blink them but some even have a micro inside!Hardware: buy a blinking LED
You are right about the overhead of a full protocol being too much for a PICAXE but, when it comes to transmitting, throwing a single byte out at higher speed, baud rates aren't quite as low as one might anticipate. You have to choose the appropriate PICAXE and craft the right code but results can be impressive.Bit-banging software serial using Picaxe Basic commands would be impractical if not impossible except possibly at the slowest of baud rates due to the command latency (overhead) of the Picaxe. I am guessing that bit-banging any modern protocol with user generated Picaxe Basic would be impractical.
#Picaxe 20X2
#No_Data
#No_Table
Symbol TX = C.0 : Symbol TX_PIN = pinC.0
PowerOnReset:
Low TX
SetFreq M32
MainLoop:
Do
; _ ___ _ _
; ___| |_| |_| |___| |___ lsb sent first, msb last
; S 0 1 1 0 1 0 0 1 P
b0 = %10010110 : Gosub SendB0
b0 = %10010110 : Gosub SendB0Faster
b0 = %10010110 : Gosub SendB0Fastest
Pause 1000
Loop
SendB0:
w0 = b0 << 1 | 0x401
Do
TX_PIN = bit0
w0 = w0 >> 1
Loop Until w0 = 1
Return
SendB0Faster:
w0 = b0 << 1 | 1
ptr = 10
Do
@ptrDec = bit0
w0 = w0 >> 1
Loop Until ptr = 0
ptr = 10
Do
TX_PIN = @ptrDec
Loop Until ptr = 0
Return
SendB0Fastest:
TX_PIN = 1
TX_PIN = bit0
TX_PIN = bit1
TX_PIN = bit2
TX_PIN = bit3
TX_PIN = bit4
TX_PIN = bit5
TX_PIN = bit6
TX_PIN = bit7
TX_PIN = 0
Return
More like slogging!wading through the Wikipedia results relating to 'bitbanging'...
True! One of the many features that make working with Picaxe so easy.on the PICAXE, you just issue a command and the hardware/firmware does the decoding for you.
Well done. This is the same result I got when using "fastest" with a 14M2 as I did not have the luxury of "<<" or ">>" with this chip. I only tested with the fastest method , but added delays to get to 4800 baud. (9600 not doable) due to command latency. This code prints Hello World to a terminal using True RS232/TTL via a CP2102 Adapter connected to PinB.3The attached code for a 20X2 at 32MHz outputs UART-style serial with a bit time just below 300us, 3,333 baud from 'SendB0'. The 'SendB0Faster' pushes that to just below 200us bit time, 5,000 baud. The 'SendB0Fastest' unrolled loop has a bit time just short of 80us, 12,500 baud. Using a 28X2 at 64MHz would halve the bit times, double the baud rates, 25,000 baud.
;*******************************************
;Example - Bit-banged Serial Out @ 4800 baud
;True Level (non-inverted)
;*******************************************
#picaxe 14M2
#no_data
Output B.3
Symbol SerOutPin = PINB.3
SerOutPin = 1 'True RS232/TTL Idle High
Symbol serdata = B0 ' Bit0 to Bit7
SetFreq M32
Pause 1000 'Stabilize
'Clear Terminal (Using Cool Term)
SerData = 12 : Gosub Send_Serial
Pause 400
Main:
Serdata = "H" : Gosub Send_serial
Serdata = "E" : Gosub Send_serial
Serdata = "L" : Gosub Send_serial
Serdata = "L" : Gosub Send_serial
Serdata = "O" : Gosub Send_serial
Serdata = " " : Gosub Send_serial
Serdata = "W" : Gosub Send_serial
Serdata = "O" : Gosub Send_serial
Serdata = "R" : Gosub Send_serial
Serdata = "L" : Gosub Send_serial
Serdata = "D" : Gosub Send_serial
Serdata = 13 : Gosub Send_serial
SerData = 10 : Gosub Send_serial
Pause 8000
Goto Main
Send_Serial:
'Provides 208us Bit time for 4800 baud
SerOutPin = 0 : Pauseus 48 'Start Bit
SerOutPin = bit0 : Pauseus 48
SerOutPin = bit1 : Pauseus 48
SerOutPin = bit2 : Pauseus 48
SerOutPin = bit3 : Pauseus 48
SerOutPin = bit4 : Pauseus 48
SerOutPin = bit5 : Pauseus 48
SerOutPin = bit6 : Pauseus 48
SerOutPin = bit7 : Pauseus 48
SerOutPin = 1 : Pause 2 'Stop Bit
Return
Excellent work.This code prints Hello World to a terminal using True RS232/TTL via a CP2102 Adapter connected to PinB.3
#Picaxe ...
PowerOnReset:
Goto Init
Send_Serial:
...
Return
Init:
...
Main:
...
Goto Main