Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2024 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 11/16/2024 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
#config
CONFIG RETEN=OFF
CONFIG XINST = OFF ;Extended Instruction Set
CONFIG FOSC = INTIO2 ;internal RC oscillator
;CONFIG FOSC = EC3 ; HS oscillator (high power > 16 MHz)
CONFIG SOSCSEL=DIG
;CONFIG SOSCSEL=HIGH
CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor ****
CONFIG IESO = OFF ;Two-Speed Start-up is disabled
CONFIG PLLCFG = OFF ;4x xtal PLL
CONFIG PWRTEN = ON ;Power-up Timer
CONFIG BOREN = SBORDIS ; Brown-out Reset Enabled in hardware, SBOREN disabled
CONFIG BORPWR = HIGH ;BOR MV set to high power level
CONFIG BORV = 2 ; Brown-out Reset 0=3v, 1=2.7v, 2=2v, 3=1.8v
CONFIG WDTEN = SWDTDIS ;ON ;OFF ;WDT enabled in hardware; SWDTEN bit disabled
CONFIG WDTPS = 64;512 ;WDT
CONFIG RTCOSC = INTOSCREF ; RTCC uses INTRC
;CONFIG ECCPMX = PORTH ; Enhanced CCP1/3 [P1B/P1C/P3B/P3C] muxed with RH7/RH6/RH5/RH4 (pwm)
;CONFIG CCP2MX = PORTBE ;PORTC
CONFIG MCLRE = ON
CONFIG STVREN = ON ;Stack Full/Underflow Reset
; CONFIG BBSIZ = BB1KL ; 1K word Boot Block size
; CONFIG BBSIZ = BB2K ; 2K word Boot Block size
CONFIG DEBUG = OFF ;Background Debugger
CONFIG CP0 = ON ;code-protected
CONFIG CP1 = ON
CONFIG CP2 = ON
CONFIG CP3 = ON
CONFIG CP4 = ON
CONFIG CP5 = ON
CONFIG CP6 = ON
CONFIG CP7 = ON
CONFIG CPB = ON ;Boot Block Code Protection
CONFIG CPD = ON ;Data EEPROM Code Protection
; CONFIG CP0 = OFF ;code-protected
; CONFIG CP1 = OFF
; CONFIG CP2 = OFF
; CONFIG CP3 = OFF
; CONFIG CP4 = OFF
; CONFIG CP5 = OFF
; CONFIG CP6 = OFF
; CONFIG CP7 = OFF
; CONFIG CPB = OFF ;Boot Block Code Protection
; CONFIG CPD = OFF ;Data EEPROM Code Protection
#endconfig
'DEFINE RESET_ORG 4000h'4000h HID bootloader must org the program at 2000 HEX
include "fp1832L.bas"
'include "FLASH.bas"
'*** At 64MHz each instruction cycle is 62.5ns
OSCCON=%11110100 'OSCILLATOR CONTROL & Frequency (16M RC)
OSCTUNE.6=1 'Frequency Multiplier PLL Enable bit FOR INIT RC
DEFINE OSC 64
INTCON2.7=1 'PORTB Pull-up Disable
PADCFG1.7=0 'PORTD Pull-up Disable
PADCFG1.6=0 'PORTE Pull-up Disable
PADCFG1.5=0 'PORTJ Pull-up Disable
ANCON0=0 'AN0-AN7 digital port
ANCON1=0 'AN8-AN15 digital port
ANCON2=0 'AN16-AN23 dig
CM1CON.7=0 'COMPERATOR1 OFF
CM2CON.7=0 'COMPERATOR2 OFF
CM3CON.7=0 'COMPERATOR3 OFF
PSPCON.4=0 'General Purpose I/O mode 'PSPMODE: Parallel Slave Port Mode Select bit
Restart:
TRISA=$FF
TRISB=$FF
TRISC=$FF
TRISD=$FF
TRISE=$FF
TRISF=$FF
TRISG=%11111
'*************
TRISC=%10111110
LATC.0=1 'HOST RTS 1=STOP SEND 0=ALOW TO SEND
'*C.1=MODULE RTS
'*C.2=1 Pump Sence
'*C.3=SCL RTC
'*C.4=SDA RTC
'*C.5=MFP RTC
LATC.6=1 'Tx1 WiFi
'*C7=RX1 WiFi
TRISA=%11101110 '
LATA.0=1 'PD_SCK HX711 low power mode
'*A0=PD_SCK HX711
'*A1=DOUT HX711
'*A2= HX711 TEMP SENSOR '02-09-2024
'*A3= INT IC PCAL6524HEAZ '02-09-2024
'*A5= general I/O connected to Test Point X16 '02-09-2024
latA.4=1 'wifi BW16 Reset/Disable 1=Reset/Disable
TRISB=%11111111
'B0-B4 not connected
'*B5= GENERAL I/O
'*B6=PROGRAMMING
'*B7=PROGRAMMING
TRISD=%00100011
' RD0 = scl2 AT24C16
' RD1 = sda2 AT24C16
LATD.2=0 'Buzzer
LATD.3=0 'External Unit Power on/off 1=on
LATD.4=0 'SDO2 FLASH
'D5=SDI2 FLASH
LATD.6=0 'SCK2 FLASH
LATD.7=1 'SS2 FLASH WP WRITE PROTECTION (0=PROTECT 1=ENABLE)
TRISE=%10011100
LATE.0=0 'HOLD FLASH 1=ACTIVE 0=HOLD
LATE.1=1 'CE FLASH 0=ENABLE 1=DISABLE
'*E2-E3= n.c
'*E4= Extension i/o
LATE.5=0 '1= Reset IC PCAL6524HEAZ
LATE.6=0 'AO3400A PWM6
'*E7= n.c
TRISF=%11111111
'*F0= n.c
'*F1= Power Fail input
'*F2= n.c
'*F3=Current Sense
TRISF.4=0 : LATF.4=1 ' Software Tx
'*F5= Software Rx
'*F6= Extension GENERAL I/O
'*F7= Extension GENERAL I/O
TRISG=%11101
'*G0= Busy
LATG.1=1 'TX2
'*G2= RX2
'*G3= Extension GENERAL I/O
'*G4= Extension GENERAL I/O
'**************
'**** WIFI ****
'**************
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 34 ' 115200 Baud @ 64MHz, -0.79%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'****************
'**** Uart 2 ****
'****************
DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive for RAFID
DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER2_SPBRG 34 ' 115200 Baud @ 64MHz, -0.79%
DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
'********************************
'****************
'**** Debug ****
'****************
DEFINE DEBUG_REG PORTF
DEFINE DEBUG_BIT 4
DEFINE DEBUG_BAUD 115200
DEFINE DEBUG_MODE 0 '0=TRUE 1=INVERTER
'*************************************************************************************
A VAR BYTE 'general use
RE VAR BYTE[999]' wifi Rx buffer
'SSID_N VAR BYTE[32] 'SSID NAME buffer
'SSID_nC VAR BYTE 'SSID NAME BYTE COUNTER
'SSID_P VAR BYTE[128] 'SSID PASWORD buffer
'SSID_pC VAR BYTE 'SSID PASSWORD BYTE COUNTER
A1 VAR WORD
A2 VAR WORD
A3 VAR WORD
CHECK VAR WORD
COUNT_A VAR BYTE[50]
T VAR BYTE[50]
T1 VAR BYTE
T2 VAR WORD
T3 VAR BYTE
T4 VAR BYTE
Tlong VAR long '
AX1 VAR WORD 'WIFI
AX2 VAR WORD 'WIFI
Message var byte[500] ' for APP
MessageL VAR WORD 'Message Length
RSSI var LONG 'SSID signal
RxEvent var LONG 'wifi
ReplyEvent VAR LONG 'WIFI
Symb VAR BYTE
CLEAR
pause 100
'Note: at GET_SSID_list1 loop, remove " if CHECK=>AX1 THEN GOTO break33 ' ***** to runout MCU *****
Main:
Gosub DEMO_RECEIVE 'Simulation of receiving DATA from wifi module
gosub Decoding 'Decoding the received data
debug "SSID LIST:<ssid>,<rssi>",$D,$A,STR Message\MessageL
End
Decoding: 'Decoding the received data
''*** 128 Indicates end of array ****
arraywrite T,["+WSCAN:",128] 'COUNT_A[15] 'search '+WSCAN:
T3=18 'COUNT_A[] number
GOSUB ConfirmMessage
if COUNT_A[18]=$FF THEN 'found?
RxEvent.18=1
COUNT_A[18]=0
GOSUB GET_SSID_list 'load the SSID list to the Message array
endif
return
'******************************************
'**** SEARCH MESSAGE AT RECEIVED ARRAY ****
'******************************************
ConfirmMessage:
for T4 = 0 to 49 'GET T array Length
if T[T4]=128 THEN GOTO break5
NEXT T4
break5:
FOR CHECK = 0 TO AX1
IF RE[CHECK]=T[0] THEN 'confirm the first charter at T array
COUNT_A[T3]=COUNT_A[T3]+1
FOR T1= 1 TO T4-1 'the number of charter need to confirm
IF RE[CHECK+T1]=T[T1] THEN
COUNT_A[T3]=COUNT_A[T3]+1 'if charter true then count
ELSE
COUNT_A[T3]=0 'if one of charter not the same, clear counter
goto break24
ENDIF
next T1
break24:
if COUNT_A[T3]=T4 THEN
COUNT_A[T3]=$FF 'True
' if T3=7 then ReplyEvent.14=1 '+WSCANACTIVE Confirm found the ssid 'RxEvent.14
' if T3=19 THEN ReplyEvent.19=1 '+WSCAN Confirm found the ssid 'RxEvent.19
GOTO break7
endif
ENDIF
'IF pir1.0 THEN gosub CLEAR_TIMER1'TIMER1 OVER FLOW 20ms
next CHECK
break7:
T[T4]=0 'clear T
return
'******************************************
DEMO_RECEIVE:
arraywrite RE,[$d,$a,_
"+WSCAN:index SSID,CH,RSSI",$d,$a,_
"1 TP-Link_Guest_ABD6_5G,48,-42",$d,$a,_
"2 TP-Link_ABD6,48,-42",$d,$a,_
"3 ,48,-42",$d,$a,_
"4 TP-Link_ABD6,1,-45",$d,$a,_
"5 TP-Link_Guest_ABD6,1,-45",$d,$a,_
"6 ,1,-45",$d,$a,_
"7 Mamad_EXT2,4,-46",$d,$a,_
"8 Mamad_EXT5g 2,48,-48",$d,$a,_
"9 ,10,-57",$d,$a,_
"10 HOME,11,-68",$d,$a,_
"11 HOME_EXT,11,-74",$d,$a,_
"12 ,52,-80",$d,$a,_
"13 HOME_5G,52,-80",$d,$a,_
"14 HOTWiFi-D7D,6,-85",$d,$a,_
"15 HOME_5G_EXT,52,-85",$d,$a,_
"16 Mali,6,-89",$d,$a,_
"17 lior,11,-92",$d,$a,_
$d,$a,"OK",$d,$a]
'Rx Byte:360
AX1=360 'received byte
return
'******************************
SearchSymbol: 'search "," Symbol
'*** Must set T4 before send to this loop
T1=0
FOR A3 = CHECK TO AX1'
IF RE[A3]=Symb THEN T1=T1+1
IF T1=T4 THEN break9
NEXT A3
break9:
CHECK=A3
return
'*********************************************
'*** load all +SCAN SSID,RSSI list to Message array ***
'*********************************************
GET_SSID_list:
MessageL=0
T4=2 'multiple of the symbol x time "space"
GET_SSID_list1:
Symb=" " '"Space"
GOSUB SearchSymbol 'Search THE SYMBOLE
if CHECK=>AX1 THEN GOTO break33 'END OF LIST ***** REMOVED to runout MCU *****
CHECK=CHECK+1 'to jump on the "space"
if RE[CHECK]="," THEN 'If hidden wifi move to next line
T4=1 'multiple of the symbol
goto GET_SSID_list1
endif
FOR A3 = CHECK TO AX1 'Get SSID name
if RE[A3]="," then break31
Message[MessageL]=RE[A3]
MessageL=MessageL+1
next A3
break31:
T4=2 'multiple of symbol, JUMP on channel
Symb=","
gosub SearchSymbol
CHECK=A3+1 'jump on ","
Message[MessageL]="," 'insert "," Between ssid to rssi (ssid,rssi)
MessageL=MessageL+1
FOR A3 = CHECK TO AX1 'Get RSSI
if RE[A3]=$D then break32 'CR
Message[MessageL]=RE[A3]
MessageL=MessageL+1
NEXT A3
break32:
CHECK=A3
Message[MessageL]=$A 'insert LF
MessageL=MessageL+1
T4=1 'multiple of the symbol
GOTO GET_SSID_list1 'Next line
break33:
RETURN
Bookmarks