Where I can find I cosay in mBasic to receive code RC5?
I have already seen the pascal codification but not to become it, they can help me?
My converted code is:
program Rc
const RCV_PIN as byte = 7 '** receiving pin
dim HalfBitTime as byte
dim HasError as byte
dim FullBitTime as byte
dim RC5Code as word
'** This function returns 16 bits extracted from RC5 signal and sets
'** the error indicator to true if an error occurs
Sub function Get_RC5(dim Erro as byte)as word
dim tmp as byte
dim INDF1 as byte
dim RC5Receiver_Get_Rc5_result_2 as byte
dim FSR0L as byte
dim FSR0H as byte
dim FSR1L as byte
dim FSR1H as byte
erro = true '** Initialize error flag
'** It is better to use indirect addressing. In this way we can store
'** results longer than a word, by using less code.
'** Moreover, by using indirect addressing we do not have to worry about
'** memory banking in assembly.
'** We will move the address of the result variable into FSR0 register.
'** All the same, we will use FSR1 register for accessing PORTD.
'** Take the address of the upper byte of the result
asm
movlw RC5Receiver_Get_Rc5_result_2
movwf FSR0L
movlw @RC5Receiver_Get_Rc5_result_2
movwf FSR0H
end asm
'** Take the address of PORTD
asm
movlw PORTD
movwf FSR1L
movlw 255
movwf FSR1H
end asm
'** We wil try to decode the sequence "1-1-0"
'** Wait for the first rising edge
'** Note that this is a dead loop if there is no signal on input pin
while TestBit(INDF1, RCV_PIN) = 0
'** The rising edge has occured, now we will try to decode "1-1-0" sequence
'** The first "1" in "1-1-0"
'** Start sampling at the middle of the active high
tmp = HalfBitTime >> 1 '** Wait for the quarter of a bit- just after the rising edge
Delay_us(10)
'** It is much faster to use the assembly for iterration.
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
'** At this point, we are at the middle of the first half of the pulse.
'** We should see a logic "1", otherwise there are two possibilities:
'** 1. Synchronization did not measure HalfBitTime well due to noise
'** 2. Trasmitter is sending non-symetrical pulses
'** The resolution is to exit and to try to syncronize again:
Delay_us(10) '** The practice shows we need to compensate errors in
Delay_us(10) '** measuring the HalfBitTime.
asm
btfss INDF1, RCV_PIN
return
end asm
'** The second "1" in "1-1-0"
tmp = FullBitTime '** We will wait full bit time in order to intercept
Delay_us(10) '** the second "1"
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
Delay_us(10)
Delay_us(10) '** We should meet logic "1" at this point, otherwise an error occured
asm
btfss INDF1, RCV_PIN
return
end asm
'** The last zero in "1-1-0" sequence
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
Delay_us(10)
Delay_us(10) '** We should meet logic "0" at this point, otherwise an error occured
asm
btfsc INDF1, RCV_PIN
return
end asm
'** So far so good, we have successfully detected "1-1-0" sequence
'** Now, we will sample the imcoming 16 bits of the message and set
'** the result appropriately
result = 0 '** Initialize result
'** It is the time to start sampling the incoming bits
'** Wait for the whole bit interval
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
'** sample the current bit
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 7
end asm
'** repeat the sequence 15 more times, once for each bit
'** wait for the whole interval
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 6
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp,F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 5
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp,F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 4
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 3
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 2
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 1
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, MANRXPIN
bsf INDF0, 0
end asm
'** Now process the lower byte of the result
asm
movlw RC5Receiver_Get_Rc5_result_1
movwf FSR0L
movlw @RC5Receiver_Get_Rc5_result_1
movwf FSR0H
end asm
'** Wait for the whole bit interval
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
' sample the current bit
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 7
end asm
' wait for the whole interval
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 6
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 5
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 4
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 3
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 2
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, RCV_PIN
bsf INDF0, 1
end asm
tmp = FullBitTime
Delay_us(10)
asm
decfsz RC5Receiver_Get_Rc5_local_tmp, F
goto $-2
end asm
asm
btfsc INDF1, MANRXPIN
bsf INDF0, 0
end asm
'** Indicate success
erro = false
wend
end sub
main:
TRISB = 0 '** PORTB and PORTC as outputs
TRISC = 0
Man_Receive_Config(PORTD,7) '** Configure and synchronize receiver
HalfBitTime = Man_Synchro '** This function returns the length of
'** a half of the manchester bit length.
'** The length is given in multiples of 10us.
'** It is assumed that one bit lasts
'** no more than 255*10us = 2550 ms
FullBitTime = HalfBitTime << 1 '** Duration of a manchester bit
while true
RC5Code = Get_RC5(HasError) '** Try to get 16 bits of data
if HasError then
HalfBitTime = Man_Synchro '** Try to synchronize again
else
PORTB = Lo(RC5Code) '** Write the received word on
PORTC = Hi(RC5Code) '** PORTB and PORTC
End if
wend
end.
Thanks
RC5 code
General discussion on mikroBasic.
Author
Message
#3 Post by juliovmd » 10 Feb 2006 10:48
If, thanks, already I know it and I have proven it despite the instruction to set bits is individually not accepted by mBasic? example:
PROTON:
Command.1=0
MBASIC:
SetBit(Command,1)
mBasic accepts but of a condition in the curls? example:
While (a=1) AND (b=2) ' is possible?
... Expresions
Wend
Thanks
PROTON:
Command.1=0
MBASIC:
SetBit(Command,1)
mBasic accepts but of a condition in the curls? example:
While (a=1) AND (b=2) ' is possible?
... Expresions
Wend
Thanks
Return to “mikroBasic General”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects