News:

Let's find out together what makes a PIC Tick!

Main Menu

Holybro 915MHz

Started by Aries_Ryan, Jul 22, 2026, 11:38 PM

Previous topic - Next topic

Aries_Ryan

I'm so excited to finally share my project with everyone here! It's been an amazing experience building this, and I can't wait to hear your thoughts
'======================================================================='
'-------------Name Developer   : A_Ryan --------------------------------'
'-------------Compiler         : Proton Basic Version 3623 -------------'
'-------------Project Category : RF Transceiver ------------------------'
'-------------Name Project     : Holybro 915 MHz -----------------------'
'======================================================================='

Device = 18F46K22
Declare Xtal = 16

' === HARDWARE FUSES ===
Config_Start
    FOSC = INTIO67     
    WDTEN = OFF         
    LVP = OFF           
    PBADEN = OFF       
    XINST = OFF         
    MCLRE = EXTMCLR     
Config_End

' --- UART Configuration ---
Declare Hserial_Baud = 57600
Declare Hserial_RCSTA = %10010000
Declare Hserial_TXSTA = %00100100
Declare Hserial_Clear = On

' --- 16x2 LCD Configuration ---
Declare LCD_Type = Alpha
Declare LCD_DTPin = PORTC.0       
Declare LCD_ENPin = PORTA.3       
Declare LCD_RSPin = PORTA.2       
Declare LCD_Interface = 4         
Declare LCD_Lines = 2             

OSCCON = %01110000                 
ANSELA = 0 : ANSELB = 0 : ANSELC = 0 : ANSELD = 0 : ANSELE = 0

Symbol LED_RED = LATA.0           
Symbol LED_GRN = LATA.1
Symbol BTN_CH1 = PORTB.0
Symbol BTN_CH2 = PORTB.1
Symbol BTN_CH3 = PORTB.2

Dim MyChannel As Byte
Dim RxChan As Byte
Dim RxDataLow As Byte
Dim RxDataHigh As Byte
Dim RxCheck As Byte
Dim CalcCheck As Byte
Dim LedWord As Word               
Dim LastSavedWord As Word            ' EEPROM Change Tracker
Dim i As Byte                     

TRISA = %00000000                 
TRISB = %11111111                 
TRISC = %10000000                 
TRISD = %00000000                 
TRISE = %00000000                 

LATA = 0 : LATD = 0 : LATE = 0

WPUB = %11111111                   
INTCON2.7 = 0                                   

 ' --- EEPROM SAVE (Only if data changed) ---
If LedWord <> LastSavedWord Then
    EWrite 0, [LedWord]    ' Just use the Word variable directly!
    LastSavedWord = LedWord
EndIf

' Immediately turn on the LEDs based on memory before waiting for Transmitter!
If GetBit LedWord, 0 = 1 Then LATD.1 = 1   
If GetBit LedWord, 1 = 1 Then LATD.2 = 1   
If GetBit LedWord, 2 = 1 Then LATD.3 = 1   
If GetBit LedWord, 3 = 1 Then LATD.4 = 1   
If GetBit LedWord, 4 = 1 Then LATD.5 = 1   
If GetBit LedWord, 5 = 1 Then LATD.6 = 1   
If GetBit LedWord, 6 = 1 Then LATE.0 = 1   
If GetBit LedWord, 7 = 1 Then LATE.1 = 1   

MyChannel = 99                       
LED_RED = 1 : LED_GRN = 0

DelayMS 200                       
Cls                               
Print At 1, 1, " INDUSTRIAL TRX "
Print At 2, 1, " WAITING TX ON.."
DelayMS 3500        '3000                 
Cls                               

While 1=1
    If RCSTA.1 = 1 Then
        RCSTA.4 = 0 : RCSTA.4 = 1
    EndIf

    If BTN_CH1 = 0 Then
        MyChannel = 1
    ElseIf BTN_CH2 = 0 Then
        MyChannel = 2
    ElseIf BTN_CH3 = 0 Then
        MyChannel = 3
    Else
        MyChannel = 99               
    EndIf
   
    HSerIn 1000, LostLink, [Wait(0xAA, 0x55), RxChan, RxDataLow, RxDataHigh, RxCheck]
   
    CalcCheck = RxChan ^ RxDataLow ^ RxDataHigh
    If CalcCheck = RxCheck And RxChan = MyChannel And MyChannel < 4 Then
       
        LED_RED = 0 : LED_GRN = 1 
       
        LedWord.LowByte = RxDataLow
        LedWord.HighByte = RxDataHigh
       
        ' --- EEPROM SAVE (Only if data changed) ---
        If LedWord <> LastSavedWord Then
            EWrite 0, [LedWord.LowByte, LedWord.HighByte]
            LastSavedWord = LedWord
        EndIf
       
        LATD = 0 : LATE = 0
        If GetBit LedWord, 0 = 1 Then LATD.1 = 1   
        If GetBit LedWord, 1 = 1 Then LATD.2 = 1   
        If GetBit LedWord, 2 = 1 Then LATD.3 = 1   
        If GetBit LedWord, 3 = 1 Then LATD.4 = 1   
        If GetBit LedWord, 4 = 1 Then LATD.5 = 1   
        If GetBit LedWord, 5 = 1 Then LATD.6 = 1   
        If GetBit LedWord, 6 = 1 Then LATE.0 = 1   
        If GetBit LedWord, 7 = 1 Then LATE.1 = 1   
       
        HSerOut [0xAA, 0x55, MyChannel]
       
        Print At 1, 1, "CH:", Dec MyChannel, " STATUS:LOCK "
        Print At 2, 1, "PORT:"
       
        For i = 0 To 7
            If GetBit LedWord, i = 1 Then
                Print "1"
            Else
                Print "0"
            EndIf
        Next
        Print "        "                 
       
    Else
LostLink:
        LED_RED = 1 : LED_GRN = 0 
       
        ' Notice LATD = 0 and LATE = 0 are REMOVED here.
        ' If link drops, the pins stay exactly where they were!
       
        If MyChannel = 99 Then
            Print At 1, 1, "CH:- STATUS:DROP"
        Else
            Print At 1, 1, "CH:", Dec MyChannel, " STATUS:DROP"
        EndIf
        DelayMS 500 'No DelayTime On Original here
        Print At 2, 1, "     A_RYAN     "
    EndIf
Wend

A_Ryan