'************************************************************************ '* Name : RTTY routines for new controller * '* Author : John F Drew * '* Notice : Copyright (c) 2010 [John F Drew] * '* : All Rights Reserved * '* Date : 4/9/2010 * '* Version : 1.0 * '* Notes : RTTY routine for new controller * '* : * '************************************************************************ Device 18F452 Config_Start OSC = HS ; HS OSCS = OFF ; Disabled PWRT = On ; Enabled BOR = OFF ; Disabled BORV = 42 ; 4.2V WDT = OFF ; Disabled WDTPS = 16 ; 1:16 CCP2MUX = OFF ; Disable (RB3) STVR = OFF ; Disabled LVP = OFF ; Disabled Debug = OFF ; Disabled CP0 = OFF ; Disabled CP1 = OFF ; Disabled CP2 = OFF ; Disabled CP3 = OFF ; Disabled CPB = OFF ; Disabled CPD = OFF ; Disabled WRT0 = OFF ; Disabled WRT1 = OFF ; Disabled WRT2 = OFF ; Disabled WRT3 = OFF ; Disabled WRTB = OFF ; Disabled WRTC = OFF ; Disabled WRTD = OFF ; Disabled EBTR0 = OFF ; Disabled EBTR1 = OFF ; Disabled EBTR2 = OFF ; Disabled EBTR3 = OFF ; Disabled EBTRB = OFF ; Disabled Config_End Declare Xtal 20 All_Digital=true Optimiser_Level = 3 'ports Symbol OutputPort = LATB.5 ' toneout 'registers reasonably complete listing, most are unused. Symbol RBIF = INTCON.0 ' RB Port Interrupt Flag - 1 = at least 1 of the RB7-RB4 pins changed state Symbol INT0IF = INTCON.1 ' INT0 External Interrupt Flag - 1 = Int0 occurred Symbol TMR0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag - 1 TMR0 Int Occurred Symbol RBIE = INTCON.3 ' RB Port Change Interrupt Enable - 1 Enable Symbol INT0IE = INTCON.4 ' INT0 External Interrupt Enable - 1 Enable Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable _ 1 Enable Symbol PEIE = INTCON.6 ' Peripheral Interrupt Enable Symbol GIEL = INTCON.6 ' Low priority peripheral interrupt - When IPEN = 0 Enable all unmasked peripheral interrupts, IPEN =1 Enable all low Priority Interrupts - when 0 Disable all peripheral interrupts Symbol GIE = INTCON.7 ' Global Interrupt Enable Symbol GIEH = INTCON.7 ' Enable all high priority interrupts - When IPEN = 0 Enable all unmasked interrupts, IPEN =1 Enable ALL High Priority Interrupts - when 0 disable ALL interruptsSYMBOL RBIP = INTCON2.0 ' RB Port Change Interrupt Priority bit - 1 High, 0 Low Symbol IPEN = RCON.7 ' Interrupt priority enable bit see above ' Bit 1 Unimplemented Symbol TMR0IP = INTCON2.2 ' TMR0 Overflow Interrupt Priority bit - 1 High, 0 Low ' Bit 3 Unimplemented Symbol INTEDG2 = INTCON2.4 ' External Interrupt2 Edge Select bit - 1 High, 0 Low Symbol INTEDG1 = INTCON2.5 ' External Interrupt1 Edge Select bit - 1 High, 0 Low Symbol INTEDG0 = INTCON2.6 ' External Interrupt0 Edge Select bit - 1 High, 0 Low Symbol NOT_RBPU = INTCON2.7 ' PORTB Pull-up Enable bit - 1 disabled, 0 Enabled Symbol INT1IF = INTCON3.0 ' INT1 External Interrupt Flag - 1 it occured - clear in software Symbol INT2IF = INTCON3.1 ' INT2 External Interrupt Flag - 1 it occured - Clear in software ' Bit 2 unimplemented Symbol INT1IE = INTCON3.3 ' INT1 External Interrupt Enable - 1 ON 0 OFF Symbol INT2IE = INTCON3.4 ' INT2 External Interrupt Enable - 1 On 0 OFF Symbol INT3IE = INTCON3.5 ' INT3 External Interrupt Enable - 1 On 0 OFF Symbol INT1IP = INTCON3.6 ' INT1 External Interrupt Priority bit - 1 High, 0 Low Symbol INT2IP = INTCON3.7 ' INT2 External Interrupt Priority bit - 1 High, 0 Low Symbol T0PS0 = T0CON.0 ' Timer0 Prescaler Select bit Symbol T0PS1 = T0CON.1 ' Timer0 Prescaler Select bit Symbol T0PS2 = T0CON.2 ' Timer0 Prescaler Select bit Symbol PSA = T0CON.3 ' Timer0 Prescaler Assignment bit Symbol T0SE = T0CON.4 ' Timer0 Source Edge Select bit Symbol T0CS = T0CON.5 ' Timer0 Clock Source Select bit Symbol T08BIT = T0CON.6 ' Timer0 8-bit/16-bit Control bit Symbol TMR0ON = T0CON.7 ' Timer0 On/Off Control bit TRISA=%00000000 'set ports for output TRISB=%00000000 TRISC=%00000000 TRISD=%00000000 TRISE=%00000000 Symbol Space $8A 'define a space for T1L was $7A Symbol Mark $E5 'define a mark for T1L was $D2 Symbol DelayBaud 19 'delay in the baud counter Dim BaudotChar As Byte 'the baudot char equiv of TempChar Dim HoldBaudot As Byte 'holds the baudot code in ltrs/figs Dim BaudotBit As Bit 'bit to control tone Dim ByteToCode As Byte 'obtained from string being sent Dim AddrStr As Word 'address of string to send Dim Figs As Bit 'flags 1=figs, 0 = ltrs Dim StoreFigs As Bit 'flag if need to change ltrs/figs Dim Count1 As Byte 'loop counters Dim Count2 As Byte Dim Count3 As Byte 'used in main loop Dim CountStr As Byte Dim Temp As Byte 'used as temp within routines Dim T1H As Byte 'store the timings for mark and space high byte Dim T1L As Byte 'store the settings for mark and space low byte 'now follows eedata IntroStr EData "VK5DJ REPEATER CONTROLLER V1.0",0 StringToGo EData "SEND THIS 1234567890:",0 LookUpT EData 22,23,19,1,10,16,21,7,6,24,14 '0,1,2,3,4,5,6,7,8,9,: EData 3,25,14,9,1,13,26,20,6,11,15,18 'A,B,C,D,E,F,G,H,I,J,K,L, EData 28,12,24,22,23,10,5,16,7,30,19 'M,N,O,P,Q,R,S,T,U,V,W EData 29,21,17 'X,Y,Z On_Hardware_Interrupt GoTo ISR ' hardware interrupt GoTo Initialise ***************************************************** 'Interrupt Routine High_Int_Sub_Start ISR: ' Interrupt Service Routine Context Save If TMR0IF=1 Then TMR0IF = 0 ' clear Timer0 interrupt flag ' we must reload the TMR0 registers ! so .... Toggle OutputPort TMR0H= T1H ' reload timer count - high TMR0L= T1L ' reload timer count - low EndIf Context Restore High_Int_Sub_End 'end of hardware interrupt routine **************************************************** Send1: '2295 HZ Mark tone While GIE=1: GIE = 0: Wend TMR0IF=0 T1H=$FB 'load timer variable T1L=Mark 'load timer variable While GIE =0: GIE =1: Wend DelayMS DelayBaud Return Send0: '2125 HZ or start tone equivalent to 1*space While GIE=1: GIE = 0: Wend TMR0IF=0 T1H=$FB T1L=Space While GIE =0: GIE =1: Wend DelayMS DelayBaud Return SendStop: While GIE=1: GIE = 0: Wend TMR0IF=0 T1H=$FB T1L=Mark While GIE =0: GIE =1: Wend DelayMS 2*DelayBaud ' Two of Mark Return SendChar: 'the main send routine for each character Count1 = 0 GoSub Send0 'start bit for 20msec Repeat If BaudotChar.0 = 1 Then GoSub Send1 'if bit is 1 send mark Else GoSub Send0 'else send a space EndIf BaudotChar = BaudotChar >> 1 'rotate the data into bit 0 Inc Count1 Until Count1 = 5 GoSub SendStop 'stop for 40msec Return GetBaudot: 'translates the ASCII to Baudot using lookup in memory Select ByteToCode Case 32:BaudotChar = 4 'space Case 46:BaudotChar = 28 '. Figs = 1 'define as figure Case 10:BaudotChar = 2 'LF Case 13:BaudotChar = 8 'CR Case 48 To 58: Temp = ByteToCode - 48 'the numerals BaudotChar = ERead LookUpT + Temp Figs = 1 Case 65 To 90: Temp = ByteToCode - 54 'the letters BaudotChar = ERead LookUpT + Temp Figs = 0 EndSelect GoSub SendFigsLtrs Return SendFigsLtrs: 'sends the letters/figs carriage shift where necessary If Figs = StoreFigs Then Return HoldBaudot = BaudotChar 'temp save of the baudotchar Count1 = 1 If Figs = 1 Then BaudotChar = 27 'figs shift Else BaudotChar = 31 'letters shift EndIf GoSub SendChar StoreFigs = Figs BaudotChar = HoldBaudot 'restore the save baudotchar Return SendStr: CountStr = 0 Repeat 'get the character from the string, find baudot equivalent then send it ByteToCode = ERead AddrStr + CountStr GoSub GetBaudot 'get the baudot equiv GoSub SendChar 'send the character Inc CountStr Until ByteToCode = 0 Or CountStr = 32 BaudotChar = 2 'LF GoSub SendChar 'send it BaudotChar = 8 'CR GoSub SendChar 'send it Return Initialise: DelayMS 1000 Clear TMR0IP = 1 'timer0 high priority interrupt enable T08BIT = 0 'set timer 0 for 16 bit T0IE = 1 'enable timer0 interrupt T0CON = %10001000 'enabled, 16 bit, internal clock, 1:2 prescaler IPEN = 1 'may or maynot be necessary GIEH = 1 'may or maynot be necessary Figs = 0: StoreFigs = 0 T1H = $FB 'Mark T1L = Mark While GIE=0: GIE = 1: Wend 'Turn on global interrupts DelayMS 2000 For CountStr =1 To 30 'send diddles (letters) BaudotChar = 31 GoSub SendChar Next For Count3 = 1 To 3 '3 rows For CountStr = 1 To 30 'send 30 RY BaudotChar = 10 GoSub SendChar BaudotChar = 21 GoSub SendChar Next BaudotChar = 2 'LF GoSub SendChar 'send it BaudotChar = 8 'CR GoSub SendChar 'send it Next ' Now the main routine Main: AddrStr = IntroStr 'send the introductory string GoSub SendStr Repeat AddrStr = StringToGo GoSub SendStr Until 1=0 End