'******************************************************************************* '* WATKINS JOHNSON QUAD-8 SYNCHRONOUS IO INTERFACE * '* Handling the 25kHz 10% duty cycle clock signals and the TX/RX data * '* Activates the RA and TI signals * '* Communicates with the PC serial port at 9600 BAUD N81 * '* * '* RADIO <======= sync ======> µP <======= async ======> PC * '* (C) Copyright ONL4234 * '*-----------------------------------------------------------------------------* '* REVISION 0.1: DEFINING OF MAIN PROGRAM STRUCTURE * '* REVISION 0.2: DEBUGGING OF ASYNCHRONOUS UART COMMUNICATION * '* REVISION 0.3: CLOCK FALLING EDGE DETECTION ADDED * '* REVISION 0.4: LCD INTERFACE ADDED * '* REVISION 0.5: HEADER & CRC ADDED * '* REVISION 0.6: LCD DUMP INFO ADDED * '* REVISION 0.7: DEBUGGING OF SYNCHRONOUS 25kHz TTL COMMUNICATION * '* REVISION 0.8 REMOTE/LOCAL ADDRESS BIT IMPLEMENTED * '* REVISION 0.9 CLOCK COMMAND CYCLE AND MONITOR CYCLE BUG FIXED * '* REVISION 1.0 FIRST ONLINE TEST PROGRAM '* REVISION 1.1 COMMAND CYCLE FULLY OPERATIONAL '******************************************************************************* '------------------------------------------------------------------------------- ' DEFINING THE USED CHIP $regfile = "8535def.dat" '------------------------------------------------------------------------------- ' CONFIGURING THE LCD Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Porta.3 , Rs = Porta.2 '------------------------------------------------------------------------------- ' SETTING UART BAUDRATE $baud = 9600 ' set to 9600 baud N,8,1 $crystal = 8000000 ' 8MHz frequency '------------------------------------------------------------------------------- ' VARIABLE DECLARATION Dim H1 As Byte ' 1st sync header from PC Dim H2 As Byte ' 2nd sync header from PC Dim Frompc(9) As Byte ' data from PC Dim Control As Byte ' data control from PC Dim Crc_received As Byte ' crc from PC Dim Crc_calc As Byte ' calculated crc Dim Crc_err As Word ' crc error counter Dim Topc(8) As Byte ' data to PC Dim X As Word ' general loop variable Dim Y As Word ' general loop variable Dim Z As Byte ' general loop variable Dim Txcycles As Word ' TX cycle counter Dim Rxcycles As Word ' RX cycle counter Dim Ltcycles As Word ' lamptest counter Dim Mask1 As Byte ' mask byte Dim Mask2 As Byte ' mask byte Dim Mask3 As Byte ' mask byte Dim L As Single ' used for freq calc Dim M As Single ' used fro freq calc Dim R As Single ' used for x power y Config Lcd = 16 * 2 '------------------------------------------------------------------------------- ' DESCRIPTION OF THE IO PINS ' PORTA.2 = LCD RS ' PORTA.3 = LCD ENABLE ' PORTA.4 = LCD DATA DB4 ' PORTA.5 = LCD DATA DB5 ' PortA.6 = LCD DATA DB6 ' PORTA.7 = LCD DATA DB7 ' PINB.0 = COMMAND CYCLE WJ8888 (11+) input for interface ' PINB.1 = MONITOR CYCLE WJ8888 (9+) input for interface ' PINB.4 = DATA OUT WJ8888 (7+) input for interface ' PINB.6 = REMOTE / LOCAL Status (14+) input for interface ' PORTB.7 = NOT USED ' PORTB.2 = REMOTE ADDRESS (1+) output for interface ' PORTB.3 = TRIGGER INPUT (5+) output for interface ' PORTB.5 = REMOTE DATA IN WJ8888 (3+) output for interface ' PORTC.0 = LED SERIAL DATA IS READ ' PORTC.1 = LED WAITING FOR SERIAL DATA INPUT ' PORTC.2 = LED SERIAL DATA IS WRITTEN ' PORTC.3 = LED REMOTE ADDRESS STATUS ' PORTC.4 = LED TRIGGER INPUT STATUS ' PORTC.5 = LED DATALED ' PORTC.6 = LED AVR IN RX MODE THUS RECEIVING FROM PC ' PORTC.7 = LED AVR IN TX MODE THUS SENDING TO PC /OR/ DATALED VALID '------------------------------------------------------------------------------- ' SETTING THE PINS AS INPUT OR OUTPUT Ddra = &B11111111 'setting the DDR port A Config Porta = Output Ddrb = &B10101100 'setting the DDR port B Config Pinb.0 = Input Config Pinb.1 = Input Config Pinb.2 = Output Config Pinb.3 = Output Config Pinb.4 = Input Config Pinb.5 = Output Config Pinb.6 = Input Config Pinb.7 = Output Ddrc = &B11111111 'setting the DDR port A Config Portc = Output Ddrd = &B11111111 'setting the DDR port A Config Portd = Output Waitms 45 'wait for power up LCD Cursor Off Waitms 5 Cls Upperline Lcd " ONL4234" Lowerline Lcd "Have a nice day!" Waitms 1500 '------------------------------------------------------------------------------- ' SETTING THE SERIAL INPUT BUFFER LENGTH Config Serialin = Buffered , Size = 36 ' buffer 6 datapackages Config Serialout = Buffered , Size = 36 ' buffer 6 datapackages Enable Interrupts '------------------------------------------------------------------------------- ' START OF PROGRAM Begin: ' begin of program 'setting the Remote Address en Trigger Input to zero Reset Portb.2 ' reset RA Reset Portb.3 ' reset TI Bitwait Portb.2 , Reset ' be sure Bitwait Portb.3 , Reset ' be sure 'start the power on self test Goto Post '------------------------------------------------------------------------------- ' MAIN PROGRAM LOOP '------------------------------------------------------------------------------- Crc_err = 0 Startloop: Do Portc = 0 ' READ RS232 BYTES Control = 0 Bitwait Portc.0 , Reset While Control = 0 For X = 1 To 8 Frompc(x) = 0 ' erase all prior data Next X Control = 0 Reset Portc.0 ' LED data serial read Set Portc.1 ' LED waiting for data input Bitwait Portc.0 , Reset Bitwait Portc.1 , Set Cls Upperline If Portb.6 = 1 Then Lcd ">WAIT HEADER =L" Else Lcd ">WAIT HEADER =R" End If Lowerline Lcd "C:" ; Crc_calc ; "-R:" ; Crc_received ; "-E:" ; Crc_err Do Do H1 = Waitkey() Loop Until H1 = 123 ' first header value H2 = Waitkey() Loop Until H2 = 242 ' second header value Cls Upperline Lcd ">WAIT HEADER" Lowerline Lcd "? DATA" Inputbin Frompc(1) , 9 ' read 9 bytes Crc_received = Waitkey() ' received crc Control = Frompc(9) ' extract control byte Crc_calc = Crc8(frompc(1) , 9) ' calculated crc If Crc_calc <> Crc_received Then Incr Crc_err Control = 0 ' reject datapackage End If Reset Portc.2 Reset Portc.1 ' wait serial data Set Portc.0 ' serial data read Wend '------------------------------------------------------------------------------- ' PASSING THE REMOTE ADDRESS AND TRIGGER INPUT SIGNALS If Control = 1 Then Set Portb.2 ' set RA Reset Portb.3 'Reset Portb.3 ' reset TI Bitwait Portb.2 , Set ' be sure Bitwait Portb.3 , Reset ' be sure End If If Control = 2 Then Set Portb.2 ' set RA Set Portb.3 ' reset TI Bitwait Portb.2 , Set ' be sure Bitwait Portb.3 , Set ' be sure End If If Control = 3 Then ' reset RA Reset Portb.2 ' reset TI Reset Portb.3 Bitwait Portb.2 , Reset ' be sure Bitwait Portb.3 , Reset ' be sure End If Portc.3 = Portb.2 'LED Remote Address Portc.4 = Portb.3 'LED Trigger Input 'Check control byte on function '------------------------------------------------------------------------------- 'DATA LED TX If Control = 121 Then Goto Ledtxdata ' DATA LED TX End If '------------------------------------------------------------------------------- 'DATA LED RX If Control = 120 Then Goto Ledrxdata ' DATA LED RX End If '------------------------------------------------------------------------------- 'LCD OFF If Control = 111 Then Goto Lcdoff ' LCD TEXT OFF End If '------------------------------------------------------------------------------- 'LCD ON If Control = 110 Then Goto Lcdon ' LCD TEXT ON End If '------------------------------------------------------------------------------- 'Information dump If Control = 100 Then Goto Infodump ' starts a information dump End If '------------------------------------------------------------------------------- 'RX dump If Control = 12 Then Goto Rxdump ' starts a rx dump End If '------------------------------------------------------------------------------- 'TX dump If Control = 11 Then Goto Txdump ' starts a tx dump End If '------------------------------------------------------------------------------- 'LCD dump If Control = 10 Then Goto Lcddump ' starts a lcd dump End If '------------------------------------------------------------------------------- 'LAMPTEST If Control = 3 Then Goto Lamptest ' starts a lamptest End If '------------------------------------------------------------------------------- ' COMMAND CYCLE ---------> DATA FROM WJ8888 TO PC If Control = 1 Then ' check remote address and trigger input Set Portc.7 ' set TX indication led ' FALLING EDGE DETECTION OF COMMAND CYCLE CLOCK 'Incr Txcycles 'Cls 'Lcd ">WJ8888>PC" 'Lowerline 'Lcd "Tx: " ; Txcycles For X = 1 To 8 Shiftin Pinb.4 , Pinb.1 , Topc(x) , 5 , 8 ' read data on falling edge Next X ' Reset Portb.2 ' reset remote address ' Reset Portb.3 ' reset trigger input ' Bitwait Portb.2 , Reset ' be sure ' Bitwait Portb.3 , Reset ' be sure Cls Lowerline Lcd ">DATA>PC" For X = 1 To 8 Print Topc(x) ' write data to PC Next X Set Portc.2 'LED SERIAL DATA IS WRITTEN Reset Portc.7 Waitms 20 Control = 0 ' cycle completed End If '------------------------------------------------------------------------------- ' WJ8888 MONITOR CYCLE ---------> DATA FROM PC TO WJ8888 If Control = 2 Then ' check remote address and trigger input Set Portc.6 ' set RX indiction led For X = 1 To 8 ' byte counter For Y = 7 To 0 Step - 1 ' bitcounter Portb.5 = Frompc(x).y ' fire databit out Bitwait Pinb.0 , Set ' wait rising edge command clock Portb.5 = 0 ' reset databit Bitwait Portb.5 , Reset ' wait low status databit Bitwait Pinb.0 , Reset ' wait falling edge command clock Next Y Next X Reset Portb.2 ' reset remote address Reset Portb.3 ' reset trigger input Bitwait Portb.2 , Reset ' be sure RA reset Bitwait Portb.3 , Reset ' be sure TI reset Reset Portb.5 ' reset data signal Bitwait Portb.5 , Reset ' be sure resetted Waitms 100 ' waiting time ' update lcd Incr Rxcycles Cls Lcd ">PC>WJ8888" Lowerline Lcd "Rx : " ; Rxcycles Control = 0 ' cycle completed End If '------------------------------------------------------------------------------- 'END OF MAIN PROGRAM Loop ' never ending loop '******************************************************************************* 'SUBROUTINES '******************************************************************************* 'LAMPTEST ROUTINE every 500ms 1 shift to the right Lamptest: Incr Ltcycles Cls Lcd ">PC>INTERFACE" Lowerline Lcd "Lt: " ; Ltcycles Portc = 1 For X = 1 To 8 Waitms 500 Portc = Portc * 2 Next X Control = 0 Goto Startloop '------------------------------------------------------------------------------- 'Power On Self Test : 10 x 8 leds scans Post: Cls Upperline Lcd " Version 1.1" Lowerline Lcd " Release" Waitms 1500 Cls Lcd "Power On" Lowerline Lcd " Self Test" ' LED POWER ON SELF TEST: BLINK EACH LED 10ms / 8 LED ARRAY Portc = 255 Waitms 300 Portc = 0 For X = 0 To 7 Portc.x = 1 Waitms 150 Next X Goto Startloop '------------------------------------------------------------------------------- 'DUMP ALL PARAMETERS IN TEXT ON LCD Lcddump: Cls Upperline Lcd ">START>ANALYZE" Waitms 3000 Cls If Frompc(1).6 = 1 Then Lcd " AGC DUMP: YES" Else Lcd " AGC DUMP: NO" End If Waitms 3000 '............................................................................... Cls Upperline Lcd " DETECTION MODE" Mask1 = Frompc(5) Shift Mask1 , Left , 1 Shift Mask1 , Right , 5 Lowerline Select Case Mask1 Case 0 : Lcd " " Case 1 : Lcd " " Case 2 : Lcd " " Case 3 : Lcd " " Case 4 : Lcd " " Case 5 : Lcd " " Case 6 : Lcd " " Case 7 : Lcd " " End Select Waitms 3000 '............................................................................... Cls Upperline Lcd " IF BANDWIDTH" Mask1 = Frompc(5) Shift Mask1 , Right , 7 Mask2 = Frompc(4) Shift Mask2 , Left , 6 Shift Mask2 , Right , 5 Mask3 = Mask1 + Mask2 Lowerline Select Case Mask3 Case 0 : Lcd " -.- kHz" Case 1 : Lcd " -.- kHz" Case 2 : Lcd " 0.5 kHz" Case 3 : Lcd " 2.0 kHz" Case 4 : Lcd " 4.0 kHz" Case 5 : Lcd " 8.0 kHz" End Select Waitms 3000 '............................................................................... Cls Upperline Lcd " GAIN MODE" Mask1 = Frompc(4) Shift Mask1 , Left , 4 Shift Mask1 , Right , 6 Lowerline Select Case Mask1 Case 0 : Lcd " HOLD AGC" Case 1 : Lcd " AGC NOT USED" Case 2 : Lcd " NORM AGC" Case 3 : Lcd " MANUAL AGC" End Select Waitms 3000 '............................................................................... Cls Upperline Lcd " TOTAL FREQUENCY" L = 0 Mask1 = Frompc(4) ' extract nibble Shift Mask1 , Right , 4 R = 10 Gosub Add_tot_freq : '10^1 Mask1 = Frompc(3) ' extract nibble Shift Mask1 , Left , 4 Shift Mask1 , Right , 4 R = 100 Gosub Add_tot_freq: '10^2 Mask1 = Frompc(3) ' extract nibble Shift Mask1 , Right , 4 R = 1000 Gosub Add_tot_freq: '10^3 Mask1 = Frompc(2) ' extract nibble Shift Mask1 , Left , 4 Shift Mask1 , Right , 4 R = 10000 Gosub Add_tot_freq: '10^4 Mask1 = Frompc(2) ' extract nibble Shift Mask1 , Right , 4 R = 100000 Gosub Add_tot_freq: '10^5 Mask1 = Frompc(1) ' extract nibble Shift Mask1 , Left , 4 Shift Mask1 , Right , 4 R = 1000000 Gosub Add_tot_freq : '10^6 Mask1 = Frompc(1) ' extract nibble Shift Mask1 , Left , 2 Shift Mask1 , Right , 6 R = 10000000 Gosub Add_tot_freq: '10^7 Lowerline Lcd " > " ; L ; " Hz" Waitms 3000 '............................................................................... Cls Upperline Lcd "BFO FREQUENCY" M = 0 Mask1 = Frompc(6) ' extract bfo frequency Mask2 = Frompc(5) Shift Mask2 , Left , 6 Shift Mask2 , Right , 6 M = Mask2 Shift M , Left , 8 M = M + Mask1 M = M * 10 Lowerline If Frompc(5).2 = 1 Then ' check sign bit Lcd " > +" ; M ; " Hz" Else Lcd " > -" ; M ; " Hz" End If Waitms 3000 '............................................................................... Cls Lcd " SIGNAL LEVEL" Lowerline Lcd " > " ; Frompc(8) ; " dB" ; Chr(228) ; "V" Waitms 3000 '............................................................................... Cls Lcd " RF GAIN CODE" Lowerline Lcd " > " ; Frompc(7) ; " x TIMES" Waitms 3000 '............................................................................... Cls Upperline Lcd ">END>ANALYZE" Waitms 3000 '............................................................................... Control = 0 Goto Startloop '------------------------------------------------------------------------------- ' DUMP DATA FROM WJ8888 AS A BIT PATTERN ON LCD Txdump: Cls Upperline Lcd ">START>TX DUMP" Waitms 3000 For X = 1 To 8 Lowerline Lcd "Byte: " ; X ; " " ; Bin(topc(x)) Waitms 3000 Next X Cls Upperline Lcd ">END>TX DUMP" Waitms 3000 Control = 0 Goto Startloop '------------------------------------------------------------------------------- ' DUMP DATA FROM PC AS A BIT PATTERN ON LCD Rxdump: Cls Upperline Lcd ">START>RX DUMP" Waitms 3000 For X = 1 To 8 Lowerline Lcd "Byte: " ; X ; " " ; Bin(frompc(x)) Waitms 3000 Next X Cls Upperline Lcd ">END>RX DUMP" Waitms 3000 Control = 0 Goto Startloop '------------------------------------------------------------------------------- ' DUMP SOME INFORMATION OF THE INTERFACE ON LCD Infodump: Cls Upperline Lcd ">START>INFO DUMP" Lowerline Lcd " (C) ONL4234 " Waitms 3000 Lowerline Lcd "WATKINS JOHNSON" Waitms 3000 Lowerline Lcd " SYNCHRONOUS IO " Waitms 3000 Lowerline Lcd " 25kHz 10%DC " Waitms 3000 Lowerline Lcd " TTL BLOCKWAVE " Waitms 3000 Lowerline Lcd " '73 " Waitms 3000 Cls Upperline Lcd ">END>INFO DUMP" Waitms 3000 Control = 0 Goto Startloop '------------------------------------------------------------------------------- ' SWITCH LCD ON Lcdon: Display On ' LCD display ON Goto Startloop '------------------------------------------------------------------------------- ' SWITCH LCD OFF Lcdoff: Display Off ' LCD display OFF Goto Startloop '------------------------------------------------------------------------------- ' LED DATA TX Ledtxdata: Portc = 0 Z = 0 Cls Upperline Lcd ">DL>WJ8888>PC" For X = 8 To 1 Step -1 For Y = 0 To 7 Incr Z Portc.7 = 1 Portc.5 = Topc(x).y ' data led Lowerline Lcd "Bit: " ; Z ; "-" ; Topc(x).y Waitms 500 Portc.7 = 0 Waitms 500 Next Y Next X Goto Startloop '------------------------------------------------------------------------------- ' LED DATA RX Ledrxdata: Portc = 0 Z = 0 Cls Upperline Lcd ">DL>PC>WJ8888" For X = 8 To 1 Step -1 For Y = 0 To 7 Incr Z Portc.7 = 1 Portc.5 = Frompc(x).y ' data led Lowerline Lcd "Bit: " ; Z ; "-" ; Frompc(x).y Waitms 500 Portc.7 = 0 Waitms 500 Portc.7 = 0 Next Y Next X Goto Startloop '------------------------------------------------------------------------------- ' SUBROUTINE CALCULATION OF TOTAL FREQUENCY Add_tot_freq: M = Mask1 ' selected nibble M = M * R ' value of nibble * weight L = L + M ' calc total freq Return ' return total freq