;181.818 Khz transmitter with 7 bit Barker Code on-off keying. ;rf7bark061015B Version) ;Copyright 2006 Dick Cappels. http://www.projects.cappels.org ;REFERENCE CIRCUIT: ;AT90S2313 microcontroller with 4 MHz clock. Timer 1 (8 bit) and the comparitor interrupt are used. ;if this code moved to another controller, the parts of this include file code relating to these ;peripherals will most likely have to be modified. A 181.818 kHz carrier, on-off modulated with ; the 7 bit Barker code appears on Port B,0. ;CALLABLE SUBROUTINE: ;One callable routines for RF communications is available. This routine saves all working registers on the ;stack and restores them before returning to the calling routine. The sole exception is, ;RFChar, which is used to transfer the data between the RF routines and calling routines. ;RFchar needs to be assigned to a high register (r16..r31),but CANNOT be r17, r18. or r19. ;RFChar is only modified by the RF routines while one of the callable routine is being executed, and ;may be used freely in other parts of the program. ;Here is a description of the callable routine: ;SendRFByte (subroutine) Sends contents of RFChar ;Sends contents of RFChar via RF. Modifies RFChar. ;Example ; ldi RFChar,$2A ;Send astersik via RF link. ; rcall SendRFByte ;////////////////// START OF INITIALIZATION CODE \\\\\\\\\\\\\\\\\\\\\\\\\ ;Copyright 2006 Richard Cappels, projects@cappels.org ; Orginally from vlfcw2313 initialization code. .include "2313def.inc" ;Include file in same directory as project. ;The statements below establish I/O pins needed for operation. .equ RFSigPort = PORTB ;Port output signal is to appear on. .equ RFSigDDR = DDRB ;Data Direction Register for signal output .equ RFSigPin = 0 ;Pin output signal is to appear on. ;Reload and prescale values .equ TimerReload = 220 ;Timer 0 reload value for chip timing. .equ Timer0Prescale = 0b00000010 ;Timer 0 prescaler selector. .def RFChar = r16 ;RF character I/O buffer (must be a high register) .def flagreg = r17 ;Flag register. Bit 6 is the odd/even field flag. ;flagreg bit assignments ;0 ;1 ;2 ;3 ;4 ;5 ;6 odd/even flag. Toggles between odd and even timer 0 interrupts. ;7 ;definition of I/O ;B0 ;B1 ;B2 ;B3 ;B4 (not assigned - configure as INPUT with weak pullup) ;B5 (not assigned - configure as INPUT with weak pullup) ;B6 (not assigned - configure as INPUT with weak pullup) ;B7 (not assigned - configure as INPUT with weak pullup) ;D0 (not assigned - configure as INPUT with weak pullup) ;D1 (not assigned - configure as INPUT with weak pullup) ;D2 (not assigned - configure as INPUT with weak pullup) ;D3 (not assigned - configure as INPUT with weak pullup) ;D4 (not assigned - configure as INPUT with weak pullup) ;D5 (not assigned - configure as INPUT with weak pullup) ;D6 (not assigned - configure as INPUT with weak pullup) ;D7 (not assigned - configure as INPUT with weak pullup) .cseg .ORG $0000 rjmp start ;Initializaton code .ORG $0006 rjmp timer0service ;Timer/counter compare interrupt start: ldi r16,RAMEND ;Initialize Stack Pointer. Note; AT90S2313 has 8 bit pointer. out spl,r16 ;Set PORTD. ldi RFChar,0b00000000 out DDRD,RFChar ldi RFChar,0b10111111 out PORTD,RFChar ;Set PORTB. ldi RFChar,0b00000000 out DDRB,RFChar ldi RFChar,0b11110100 ;Set PORTD out PORTB,RFChar ldi r18,Timer0Prescale ;Initaize prescaler out TCCR0, r18 ldi r18,TimerReload ;Initialize counter out TCNT0,r18 ldi r18, $02 ;Enable interrupts TIMSK out TIMSK,r18 sei ;ENABLE THE INTERRUPTS ;////////////////// END OF INITIALIZATION CODE \\\\\\\\\\\\\\\\\\\\\\\\\ main: ;Note: Do not do much in main as it throws off chip timing. ldi RFChar,0b10100011 ;Send Barker Code via RF link. Only 7 MSB will be sent. Zero at end is superfluous. rcall SendRFByte rjmp main ;Do this forever. ;//////////////BEGIN BASIC RF COUPLER ROUTINES\\\\\\\\\\\\\\\ .macro pushall push r2 ;Save these registers before using push r18 ;in the VLF communications routines. push r17 push r19; .endmacro .macro popall ;Restore these registers before returning. pop r19; ;Temporaty storage of status register. pop r17 ;General purpose scratch register. pop r18 ;General purpose scratch register. pop r2 ;Comparitor interrupt counters. .endmacro SendRFByte: ;Shift byte in RFChar out through RF channel. ;RFChar changed by this routine.ob pushall ;Save all working registers except RFChar. ldi r17,7 ;Set number of bits:0,start, 7 data, 0 stop lsl RFChar ;Shift bit7 into carry. nxbtrf1: brcs bitsonerf1 rcall szerorf1 rjmp iwzrf1 bitsonerf1: sbi RFSigDDR,RFSigPin ;Set signal output pin to output. rcall SendOnerf1 cbi RFSigDDR,RFSigPin ;Set signal output pin to input. iwzrf1: lsl RFChar ;Shift next bit into carry. dec r17 ;Decrement bit counter. brne nxbtrf1 ;If not all done, then continue. cbi RFSigPort,RFSigPin ;Set signal output low (no pullup). popall ;Restore all working registes except RFChar. ret szerorf1: ;Send no carrier for for one bit time. WaitNotSend: rjmp WaitNotSend ;Do nothing but wait for interrupt to yank controller out of loop. SendOnerf1: ;Send carrier until interrupted. MakeRF1: ;This is a timing loop, so modify carefully! sbi RFSigPort,RFSigPin ;Output High. Instructions sbi and cbi are 2 clock each. sbi RFSigPort,RFSigPin sbi RFSigPort,RFSigPin sbi RFSigPort,RFSigPin sbi RFSigPort,RFSigPin nop ;(need this nop for timing) cbi RFSigPort,RFSigPin ;Output Low cbi RFSigPort,RFSigPin cbi RFSigPort,RFSigPin cbi RFSigPort,RFSigPin nop ;(need this nop for timing) rjmp MakeRF1 ;Interrupt will yank controller out of loop. timer0service: ;Don't save anything else on the stack - time is critical. ldi r18,TimerReload ;Set number of prescaled clocks until next interrupt. out TCNT0,r18 ;If even field stop carrier generation by dumping the stack, otherwise, continue. ;Else set flag to even field, sbrs flagreg,6 rjmp oddfield andi flagreg,0b10111111 ;Clear odd/even flag and clear barker bit flag. pop r18 pop r18 reti ;Return oddfield: ori flagreg,0b01000000 ;Set odd/even flag. reti ;Return .exit