SX SIRC_ISR program
Rsadeika
Posts: 3,837
Listed below is an updated program. I tried to add in a device code capture in the asm code within the interrupt. The program does not crash, but it is not capturing the device code portion. My logic says that it should work, but· it does not. I was wondering if one of you asm experts would show me the error of my ways.
I figured that after the first 8 bits were captured, that instead of exiting the ISR, it would have to jump to another procedure to get the last 4 bits, which it would put into devCode, and then exit after the program was satisfied that it had dealt with all 12 bits.
I added a Test2_DBit, and a Next_Bit2 procedure, in the Next_Bit procedure I modified the line to·IF bitCount < 8 then Test2_DBit.
Thanks
Ray
*******CODE*********
' =========================================================================
'
'·· File...... XGbot.SXB
'·· Purpose...
'·· Author.... R Sadeika
'·· E-mail....·
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSCHS1, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
'
' IO Pins
'
·IR· var rc.0
'
' Constants
'
· Power con 21
· ChUp· con 16
· ChDn· con 17
· VolUp con 18
· VolDn con 19
'
' Variables
'
cmdCode··VAR·Byte···' IR command code (7 bits)
cmdWork··VAR·Byte···' work space for cmd byte
bitCount·VAR·Byte···' track bits received
bitWidth·VAR·Byte···' measure bit width
flags··VAR·Byte
rxCmd··VAR·flags.0···' receiving command
rxBit··VAR·flags.1···' measuring bit width?
hasCmd··VAR·flags.2···' command code available
devWork········ var···· byte
devCode········ var···· byte
temp1··VAR·Byte···' subroutine work vars
temp2··VAR·Byte
temp3··VAR·Byte
'
· INTERRUPT
'
ISR_Start:
''''''''''
'' SIRC VP
''''''''''
· ASM
··· JB··· hasCmd, ISR_Exit···' exit if holding command
··· JB··· rxCmd, Check_Bit···' receiving now?
··· JB··· IR, ISR_Exit····' exit if IR line idle
Start_Packet:
··· SETB· rxCmd·····' set rx flags
··· SETB· rxBit
··· CLR·· cmdWork····' clear work vars
··· clr·· devWork
··· CLR·· bitWidth
··· CLR·· bitCount
··· JMP·· ISR_Exit
Check_Bit:
··· JNB·· IR, Update_BitWidth···' still in bit?
··· JNB·· rxBit, ISR_Exit···' in idle period?
··· CLRB· rxBit·····' no, clear bit flag
··· CJA·· bitCount, #0, Test_DBit··' start or data bit?
Test_SBit:
··· CJA·· bitWidth, #74, Next_Bit··' proper start bit?
··· CLR·· rxCmd·····' no, reset
··· JMP·· ISR_Exit
Test_DBit:
··· CLC
··· RR··· cmdWork····' prep for next bit
··· CJB·· bitWidth, #34, Next_Bit··' "1" bit?
··· SETB· cmdWork.6····' yes, set it
Next_Bit:
··· CLR·· bitWidth····' clear for next bit
··· INC·· bitCount····' update count
··· CJB·· bitCount, #8, Test2_DBit··' done?
··· SETB· hasCmd····' set available flag
··· MOV·· cmdCode, cmdWork···' copy work to output
··· CLRB· rxCmd·····' clear rx flag
··· JMP·· ISR_Exit
Test2_DBit:
··· clc
··· rr devWork
··· cjb bitWidth, #34, Next_Bit2
··· setb devWork.4
Next_Bit2:
··· clr bitWidth
··· inc bitCount
··· cjb bitCount, #12, ISR_Exit
··· setb hasCmd
··· mov devCode, devWork
'··· mov cmdCode, cmdWork
··· clrb rxCmd
··· jmp ISR_Exit
Update_BitWidth:
··· INC·· bitWidth····' else inc width
··· SETB· rxBit
'''''''''''''''''
'' End of Sirc VP
'''''''''''''''''····' refresh in bit flag
· ENDASM
ISR_Exit:
· RETURNINT 163·········· 'Now setup for 50Mhz································
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
· LED1 sub
· ProcessCode sub
· Process2 sub
· Stop sub
· GoFore sub
· GoBack sub
· LF sub
· LB sub
· RF sub
· RB1 sub
'
' Program Code
'
Start:
· ' initialization code here
· PLP_A = %0000·····' pull-up unused pins
· PLP_B = %00000000
· PLP_C = %00000000····' make LED pins outputs
· OPTION = $82·····' interrupt, uses prescaler
Main:
· IF hasCmd = 0 THEN Main···' wait for new code
· ProcessCode
· hasCmd = 0
·
· GOTO Main
end
'
' Subroutine Code
'
ProcessCode:
· If devCode = 1 then Process2
return
Process2:
· IF cmdCode = Power then Stop···· 'Power = Stop
· IF cmdCode = ChUp then GoFore
· IF cmdCode = ChDn then GoBack
· IF cmdCode = VolUp then LED1
· IF cmdCode = VolDn then LED1
· IF cmdCode = 0 then LF
· IF cmdCode = 3 then LB
· IF cmdCode = 1 then RF
· IF cmdCode = 4 then RB1
return
Stop:
· HIGH rc.3··· 'Wire 5 Red···· LS M1
· HIGH rc.2··· 'Wire 6 Yellow· LS M1
· HIGH rc.1··· 'Wire 7 Black·· RS M2
· HIGH rc.0··· 'Wire 8 White·· RS M2
return
GoFore:
· LOW rc.3···· 'Wire 5· LS· LOW = 0
· HIGH rc.2··· 'Wire 6· LS· HIGH = 1
· HIGH rc.1··· 'Wire 7· RS
· LOW rc.0···· 'Wire 8· RS
return
GoBack:
· HIGH rc.3··· 'Wire 5· LS
· LOW rc.2···· 'Wire 6· LS
· LOW rc.1···· 'Wire 7· RS
· HIGH rc.0··· 'Wire 8· RS
return
LF:
· LOW rc.3
· HIGH rc.2
return
LB:
· HIGH rc.3
· LOW rc.2
return
RF:
· HIGH rc.1
· LOW rc.0
return
RB1:
· LOW rc.1
· HIGH rc.0
return
LED1:
· HIGH rc.1
· pause 2000
· LOW rc.1
return
I figured that after the first 8 bits were captured, that instead of exiting the ISR, it would have to jump to another procedure to get the last 4 bits, which it would put into devCode, and then exit after the program was satisfied that it had dealt with all 12 bits.
I added a Test2_DBit, and a Next_Bit2 procedure, in the Next_Bit procedure I modified the line to·IF bitCount < 8 then Test2_DBit.
Thanks
Ray
*******CODE*********
' =========================================================================
'
'·· File...... XGbot.SXB
'·· Purpose...
'·· Author.... R Sadeika
'·· E-mail....·
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSCHS1, TURBO, STACKX, OPTIONX
FREQ··········· 50_000_000
'
' IO Pins
'
·IR· var rc.0
'
' Constants
'
· Power con 21
· ChUp· con 16
· ChDn· con 17
· VolUp con 18
· VolDn con 19
'
' Variables
'
cmdCode··VAR·Byte···' IR command code (7 bits)
cmdWork··VAR·Byte···' work space for cmd byte
bitCount·VAR·Byte···' track bits received
bitWidth·VAR·Byte···' measure bit width
flags··VAR·Byte
rxCmd··VAR·flags.0···' receiving command
rxBit··VAR·flags.1···' measuring bit width?
hasCmd··VAR·flags.2···' command code available
devWork········ var···· byte
devCode········ var···· byte
temp1··VAR·Byte···' subroutine work vars
temp2··VAR·Byte
temp3··VAR·Byte
'
· INTERRUPT
'
ISR_Start:
''''''''''
'' SIRC VP
''''''''''
· ASM
··· JB··· hasCmd, ISR_Exit···' exit if holding command
··· JB··· rxCmd, Check_Bit···' receiving now?
··· JB··· IR, ISR_Exit····' exit if IR line idle
Start_Packet:
··· SETB· rxCmd·····' set rx flags
··· SETB· rxBit
··· CLR·· cmdWork····' clear work vars
··· clr·· devWork
··· CLR·· bitWidth
··· CLR·· bitCount
··· JMP·· ISR_Exit
Check_Bit:
··· JNB·· IR, Update_BitWidth···' still in bit?
··· JNB·· rxBit, ISR_Exit···' in idle period?
··· CLRB· rxBit·····' no, clear bit flag
··· CJA·· bitCount, #0, Test_DBit··' start or data bit?
Test_SBit:
··· CJA·· bitWidth, #74, Next_Bit··' proper start bit?
··· CLR·· rxCmd·····' no, reset
··· JMP·· ISR_Exit
Test_DBit:
··· CLC
··· RR··· cmdWork····' prep for next bit
··· CJB·· bitWidth, #34, Next_Bit··' "1" bit?
··· SETB· cmdWork.6····' yes, set it
Next_Bit:
··· CLR·· bitWidth····' clear for next bit
··· INC·· bitCount····' update count
··· CJB·· bitCount, #8, Test2_DBit··' done?
··· SETB· hasCmd····' set available flag
··· MOV·· cmdCode, cmdWork···' copy work to output
··· CLRB· rxCmd·····' clear rx flag
··· JMP·· ISR_Exit
Test2_DBit:
··· clc
··· rr devWork
··· cjb bitWidth, #34, Next_Bit2
··· setb devWork.4
Next_Bit2:
··· clr bitWidth
··· inc bitCount
··· cjb bitCount, #12, ISR_Exit
··· setb hasCmd
··· mov devCode, devWork
'··· mov cmdCode, cmdWork
··· clrb rxCmd
··· jmp ISR_Exit
Update_BitWidth:
··· INC·· bitWidth····' else inc width
··· SETB· rxBit
'''''''''''''''''
'' End of Sirc VP
'''''''''''''''''····' refresh in bit flag
· ENDASM
ISR_Exit:
· RETURNINT 163·········· 'Now setup for 50Mhz································
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
· LED1 sub
· ProcessCode sub
· Process2 sub
· Stop sub
· GoFore sub
· GoBack sub
· LF sub
· LB sub
· RF sub
· RB1 sub
'
' Program Code
'
Start:
· ' initialization code here
· PLP_A = %0000·····' pull-up unused pins
· PLP_B = %00000000
· PLP_C = %00000000····' make LED pins outputs
· OPTION = $82·····' interrupt, uses prescaler
Main:
· IF hasCmd = 0 THEN Main···' wait for new code
· ProcessCode
· hasCmd = 0
·
· GOTO Main
end
'
' Subroutine Code
'
ProcessCode:
· If devCode = 1 then Process2
return
Process2:
· IF cmdCode = Power then Stop···· 'Power = Stop
· IF cmdCode = ChUp then GoFore
· IF cmdCode = ChDn then GoBack
· IF cmdCode = VolUp then LED1
· IF cmdCode = VolDn then LED1
· IF cmdCode = 0 then LF
· IF cmdCode = 3 then LB
· IF cmdCode = 1 then RF
· IF cmdCode = 4 then RB1
return
Stop:
· HIGH rc.3··· 'Wire 5 Red···· LS M1
· HIGH rc.2··· 'Wire 6 Yellow· LS M1
· HIGH rc.1··· 'Wire 7 Black·· RS M2
· HIGH rc.0··· 'Wire 8 White·· RS M2
return
GoFore:
· LOW rc.3···· 'Wire 5· LS· LOW = 0
· HIGH rc.2··· 'Wire 6· LS· HIGH = 1
· HIGH rc.1··· 'Wire 7· RS
· LOW rc.0···· 'Wire 8· RS
return
GoBack:
· HIGH rc.3··· 'Wire 5· LS
· LOW rc.2···· 'Wire 6· LS
· LOW rc.1···· 'Wire 7· RS
· HIGH rc.0··· 'Wire 8· RS
return
LF:
· LOW rc.3
· HIGH rc.2
return
LB:
· HIGH rc.3
· LOW rc.2
return
RF:
· HIGH rc.1
· LOW rc.0
return
RB1:
· LOW rc.1
· HIGH rc.0
return
LED1:
· HIGH rc.1
· pause 2000
· LOW rc.1
return
Comments
This is the original code, and it works.
Next_Bit:
··· CLR·· bitWidth····' clear for next bit
··· INC·· bitCount····' update count
··· CJB·· bitCount, #8, ISR_Exit··' done? ***** This point here *****
··· SETB· hasCmd····' set available flag
··· MOV·· cmdCode, cmdWork···' copy work to output
··· CLRB· rxCmd·····' clear rx flag
··· JMP·· ISR_Exit
I guess I need an explanation as to how the CJB instruction works. "CJB Compare op1 to op2 and jump if below", can anybody explain what exactly is occuring in CJB·· bitCount, #8, Test2_DBit. The way I see it is, if the BitCount starts at zero, then the CJB instruction would see this as LESS than #8 and jmp to ISR_Exit, and it would·never get the full eight bits, evidently·that is not what is occuring for whatever reason it jmps when bitCount is #8, I think.
How do I get the procedure to transition to capture the next four bits and put them into devWork and then devCode. For me this seems to be an interesting puzzle. Any ideas?
Thanks
Ray
CJB actual compiles to 4 instructions and if you look at what those do, CJB command should make sense.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
Double check your source code. You are saying that if bitCount is less than 8, then it goes to ISR_Exit. The source says something different. The source says that if bitcount is less than 8, then it will jump to Test2_Dbit. Further, if you look at the code, you'll see that the line after the one in questions says
. This means that after 8 bits are accumulated, all the bits for the command have received.
I think that what is going on in the section you are concerned about is that the code needs to loop though this interrupt handler multiple times, accumulating the various incoming bits. Eight of those bits make up the command itself, and the handler uses "bitCount" to keep track of how many of those bits it has received before going on to the next stage of handling the incoming bit stream.
Thanks, PeterM
PeterM, once you reminded me that it is all about interrupt cycles, then it started to make sense as to how CJB instruction is being used here. Just when I was getting ready throw in the towel ...
Thanks
Ray
PS Reminder to myself, INTERRUPT CYCLES.