Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Written by Dennis Skinner
- ; Last updated: 2/12/2012
- ; Version: 1.0
- ;
- ; Designed for PICAXE 08M
- ;
- ; Original code written by Jeremy Fright for the Arduino: http://diru.org/wordpress/hacking/xbox-360-rf-module-arduino/
- ; I've done a little bit of tweaking, but lots of the foot work is on his site.
- ;Pins
- symbol syncbtn = pin3 ;connect to pin 5 on xbox board (switch 1)
- symbol datapin = 4 ;serial data on xbox board
- symbol clockpin = pin1 ;serial clock on xbox board
- ;Vars
- symbol writethis = w5 ;set this to binary that you want writedata to write
- symbol counter = b2
- symbol prev = b3
- symbol shift = w6
- ;Commands
- symbol ledcmd = %0010000100 ;132
- symbol animcmd = %0010000101 ;133
- symbol synccmd = %0000000100 ;4
- symbol ctrloff = %0000001001 ;9
- symbol redblnk = %0011000001 ;193
- symbol blnkoff = %0011000000 ;192
- symbol startshift = %10000000000 ;1024
- setup:
- ; don't let that clock start
- high datapin
- ;wait for startup (I had inconsistencies with 2 seconds)
- pause 3000
- gosub init_led
- goto main
- main:
- pause 200
- ;Button press
- if syncbtn = 0 then
- ;cheap debounce
- pause 100
- if syncbtn = 0 then
- ;after the button is pushed, wait (about) half a second
- ; to see if it's still being pressed
- pause 600
- ;if it's still pressed, turn off controllers
- if syncbtn = 0 then
- ;blink red
- writethis = redblnk
- gosub writedata
- ;wait so we see the lights
- pause 2000
- ;turn off controlers
- writethis = ctrloff
- gosub writedata
- pause 50
- ;turn off blink
- writethis = blnkoff
- gosub writedata
- ;else sync
- else
- writethis = synccmd
- gosub writedata
- EndIf
- ;let the user get their finger off the button
- pause 3000
- EndIf
- EndIf
- goto main
- ;****************************
- ;**** SUBS ****
- ;****************************
- ; we use this to write the data
- ; set what you want to write in
- ; writethis
- writedata:
- ; change frequency
- setfreq m8
- ; start sending data
- low datapin
- prev = 1
- ; start the shift var at 1024
- ; We could start at 512 but we have the first shift we need to deal with
- shift = startshift
- ;loop over whatever is in writethis
- ; and write it to the data pin
- for counter = 0 to 9
- ; do all the shifting while we wait
- ; shift the bit
- shift = shift / 2
- w4 = writethis & shift
- do while prev = clockpin:loop ;waits for a change in clock
- prev = clockpin
- ; should be after downward edge of clock,
- ; so send bit of data now
- if w4 != 0 then
- high datapin
- else
- low datapin
- EndIf
- do while prev = clockpin:loop ;detects upward edge of clock
- prev = clockpin
- next counter
- ; stop data
- high datapin
- ;set frequency back to 4MHz
- setfreq m4
- return
- ;sends the initalization of the leds
- init_led:
- writethis = ledcmd
- gosub writedata
- pause 50
- writethis = animcmd
- gosub writedata
- pause 50
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement