; ; IRtranceiver.txt ; Tom McGuire 11-29-07 ; the timer is setup to generate the 38KHz carrier ; and is gated on and off by the UART transmit (externally) ; the receiver is a radioshack #276-640 ; ; this program transmits a ascii U ($55) every second ; and prints what ever it receives ; ; portc.6 pin 17 = TX and portc.7 pin 18 = RX constants [ [ccp1con $fbd] [t2con $fca] [ccpr1l $fbe] [pr2 $fcb] [rcreg $fae] [rcsta $fab] [spbrg $faf] [pir1 $f9e] [txsta $fac] [txreg $fad] ] to powerup write t2con 4 ;setup the timer write ccp1con 12 write pr2 50 ;timer period (38KHz) write ccpr1l 25 ;timer duty cycle (50%) clearbit 2 portc-ddr ;turn on the output write txsta $20 ;setup the transmiter write rcsta $90 ;setup the receiver write spbrg 250 ;set baud rate to slow a possible clearbit 7 portb-ddr ;put an LED here for error checking setm read rcreg startup end to startup loop [ if testbit 2 rcsta [ clearbit 4 rcsta ; << on rec error setbit 7 portb mwait 1 ; setbit 4 rcsta] ; << reset the UART uart-send $55 repeat 100[ mwait 10 clearbit 7 portb if (testbit 5 pir1) [ print uart-receive ] ] ] end to uart-send :n waituntil [testbit 1 txsta] write txreg :n end to uart-receive waituntil [testbit 5 pir1] output read rcreg end