Shop OBEX P1 Docs P2 Docs Learn Events
SX port C — Parallax Forums

SX port C

RsadeikaRsadeika Posts: 3,861
edited 2006-03-17 08:11 in General Discussion
Listed below is the JW SIRC program (IR remote control). The problem that I am encountering is that when I hook up the IR detector to any pin on the C port, the program does not behave as expected, IR detector does not respond. If I hook up the IR detector to any pin on port a or b, the program works as expected.

I discovered the ?problem? while working on the I2C/UART dev board, then I·checked it out on the SX28 tech board, same outcome.

So, the question is, why does it not work on port c, but it works on port a and b. Since I am not using an SX48/52, I did not check out port d and e. Basically, is this a software problem or a hardware problem. I tried to decipher the asm part of the program to see if this was the problem, I did not have any luck.·Maybe one of the asm pros can see something that I missed. Or is it simply that port c does not handle that kind of input. I thought that all ports were created equal in the basic configuration.

If somebody makes the discovery, a clear and explicit explanation would be very appreciated.

Thanks
Ray



' =========================================================================
'
'·· File...... XGbot.SXB
'·· Purpose...
'·· Author....· R Sadeika
'·· E-mail....·
'·· Started...
'·· Updated...
'
' =========================================================================

'
' Program Description
'

'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000

'
' IO Pins
'
'IR··VAR·RB.7
·IR· var rb.7
'
' 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
temp1··VAR·Byte···' subroutine work vars
temp2··VAR·Byte
temp3··VAR·Byte

'
· INTERRUPT
'
ISR_Start:
· 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·· 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, ISR_Exit··' done?
··· SETB· hasCmd····' set available flag
··· MOV·· cmdCode, cmdWork···' copy work to output
··· CLRB· rxCmd·····' clear rx flag
··· JMP·· ISR_Exit
Update_BitWidth:
··· INC·· bitWidth····' else inc width
··· SETB· rxBit·····' refresh in bit flag
· ENDASM
ISR_Exit:
· RETURNINT 104································

' =========================================================================
· PROGRAM Start
' =========================================================================


'
' Subroutine Declarations
'
· LED1 sub
· ProcessCode 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
· TRIS_C = %00000000····' make LED pins outputs
· OPTION = $88·····' interrupt, no prescaler

Main:
· IF hasCmd = 0 THEN Main···' wait for new code
· ProcessCode
· hasCmd = 0
·
· GOTO Main
end
'
' Subroutine Code
'
ProcessCode:
· 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 rb.2
· HIGH rb.0
· pause 2000
'· LOW rb.2
· LOW rb.0
return

Comments

  • BeanBean Posts: 8,129
    edited 2006-03-16 18:59
    Probably because port c is setup as all outputs.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    "Wise men know when they're right. The wisest also·know when they're wrong."
    ·
  • RsadeikaRsadeika Posts: 3,861
    edited 2006-03-16 19:47
    Thanks Bean, fixed the problem, works like expected. I guess it's always the most obvious thats sneaks by.

    Ray
  • PJMontyPJMonty Posts: 983
    edited 2006-03-17 08:11
    Ray,

    You just learned (I hope) a valuable lesson. When you have a problem, always look at the simplest possible solutions first, and then work your way up in complexity.

    If a light won't turn on in your house, don't start looking at the fuse panel, or the powerlines entering the house, or start ripping open the walls to check the house wiring. Try a new bulb first and see if that fixes the problem.

    If you have are having problems trying to get input from a port, don't try reading the assembly code that the compiler generates looking for a compiler bug, look at your own source code and see if you have set the bit to be an input first. Remember this lesson and your life will get easier and easier.
      Thanks, PeterM
Sign In or Register to comment.