News:

;) This forum is the property of Proton software developers

Main Menu

rf433

Started by Pepe, Oct 07, 2025, 03:51 AM

Previous topic - Next topic

Pepe

proteus library for rf module and demo

'----------------------------------------------------
' PIC18F2550 + Transmisor
' POSITRON BASIC - Fosc = 48 MHz
'----------------------------------------------------
Device = 18F2550
Declare Xtal = 48
Declare Optimiser_Level = 3
Declare Bootloader off
Declare Onboard_USB Off
Declare Watchdog off
'Declare Float_Display_Type = Fast
Declare Dead_Code_Remove = 1        ' Remove dead code
Declare Show_system_variables On
Declare Auto_Variable_Bank_Cross = On
Declare Auto_Heap_Arrays = On
Declare Auto_Heap_Strings = On
'Declare Label_Bank_Resets = On
Declare Reminders Off
Declare Hints Off
Declare Create_Coff On
Symbol USBEN = UCON.3    ' USB Module Enable bit
Symbol UTRDIS = UCFG.3   ' On-Chip Transceiver Disable bit

'----------------- Pin de transmisión -----------------
Symbol RF_TX = PORTB.0
TRISC= $7
TRISB = $fe

ADCON1= $f
USBEN = 0
UTRDIS = 1
INTCON2.7 = 0

'----------------- CONFIGURACIÓN -----------------
' Número a transmitir
Dim CodeToSend As Dword    '$ffffff
Dim CodeToSenda As Dword   

' Temporización de PT2262 (aprox. microsegundos)
Symbol PT_ZeroHigh = 350
Symbol PT_ZeroLow  = 1050
Symbol PT_OneHigh  = 1050
Symbol PT_OneLow   = 350
Symbol PT_SyncHigh = 350
Symbol PT_SyncLow  = 10850
Symbol rept 4                   'repeticiones
'----------------- VECTORES DE BITS -----------------
Dim AddressBits[20] As Byte
Dim DataBits[4] As Byte
Dim i As Byte
Dim temp As Word
Dim pul As Byte
'----------------------------------------------------
' LOOP PRINCIPAL
   pul =(PORTC & $f)|(PORTE.3 << 3)
   CodeToSenda = $A5A000 | ((PORTB & $fe) << 4) | pul
Do
   pul =(PORTC & $f)|(PORTE.3 << 3)
   CodeToSend = $A5A000
   CodeToSend = CodeToSend | ((PORTB & $fe) << 4 )| pul
   
    If pul = 0 Then
                    If  CodeToSenda <> CodeToSend Then
                                                       CodeToSenda = CodeToSend
                                                       transmit(2)
                    EndIf                 
               Else
                    transmit(rept)
                    CodeToSenda=0                 
                    DelayMS 100                                       
   EndIf
   
Loop
Proc transmit(cant As Byte)
' Convertir código a bits
ConvertToBits(CodeToSend)
                                     '
' Enviar n repeticiones para seguridad
   
    For i = 0 To cant - 1
     SendPTWord()
    Next i
EndProc

'----------------------------------------------------
' Convierte número a bits
Proc ConvertToBits(NumberToConvert As Dword)
    Dim idx As Byte
    Dim masc As Dword
   
    ' Dirección 20 bits
    For idx = 0 To 19
        masc = 1 << (23 - idx)
        If NumberToConvert & masc <> 0 Then
                                             AddressBits[idx] = 1
                                       Else
                                             AddressBits[idx] = 0
        EndIf                                               
    Next idx
   
    ' Datos 4 bits ( últimos 4 bits)
    For idx = 0 To 3
         masc = 1 << (3 - idx)
        If NumberToConvert & masc <> 0 Then
                                            DataBits[idx] = 1                                   
                                       Else
                                            DataBits[idx] = 0
        EndIf                                               
    Next idx
EndProc

'----------------------------------------------------
' Envía un bit 0
Proc SendBitZero()
    RF_TX = 1
    DelayUS PT_ZeroHigh
    RF_TX = 0
    DelayUS PT_ZeroLow
EndProc

' Envía un bit 1
Proc SendBitOne()
    RF_TX = 1
    DelayUS PT_OneHigh
    RF_TX = 0
    DelayUS PT_OneLow
EndProc

' Envía un bit  tristate
Proc SendBitF()
    RF_TX = 1
    DelayUS PT_ZeroHigh
    RF_TX = 0
    DelayUS PT_ZeroHigh
EndProc

' Envía bit de sincronización
Proc SendSync()
    RF_TX = 1
    DelayUS PT_SyncHigh
    RF_TX = 0
    DelayUS PT_SyncLow
EndProc

'----------------------------------------------------
' Envía palabra PT2262 (dirección + datos + sync)
Proc SendPTWord()
    Dim idx As Byte
   
    ' Dirección 20 bits
    For idx = 0 To 19
        If AddressBits[idx] = 0 Then
                                       SendBitZero()
                                ElseIf AddressBits[idx] = 1 Then
                                       SendBitOne()
                                    Else
                                       SendBitF()
        EndIf                         
    Next idx
    ' Datos 4 bits
    For idx = 0 To 3
        If DataBits[idx] = 0 Then
                                     SendBitZero()
                              ElseIf DataBits[idx] = 1 Then
                                     SendBitOne()
                                  Else
                                     SendBitF()
        EndIf                   
    Next idx
    SendSync()
EndProc


Include "18F2550_Fuses20.inc"

Dolci

Can you please upload Proteus 8.15

Thanks,
Dolci

Teo

#2
Hi Pepe,
You did an excellent project!
Please be kind and give us the .bas files.
This way we can better understand how the project works.
Thanks in advance,
Teo