Changing from PORTC to PORTA Problems


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default Changing from PORTC to PORTA Problems

    I was using PORTC as inputs for switches, but as it appears that the PIC18F2550 has no PORTC.3, i've to to move all to PORTA. However, after changing all the PORTC in code to PORTA, the PIC doesn't perform correctly.

    Am i missing something?

    This is what i had.

    Code:
    ' ---------- [ I/O Definition ] ----------
    TRISA = %11111111       ' Set PORTA to all input
    TRISB = %10000001       ' Set PORTB (0)INPUT (1-5)OUTPUTS
    TRISC = %00000111       ' Set PORTC (0-2 input) rest Outputs
    
    ' ---------- [ System Inputs ] ----------
    Circle      Var PORTC.0         ' 1 - Circle Switch
    
        MaskSwitch=PORTC & $07
            Select Case MaskSwitch
              Case 1 '%00000001 or Circle Switch
                If Circle = 1 Then Gosub Procedure_Circle
                If Circle = 0 THEN
                EndIf
    ..........
    Which i thought i'd simply changed to-
    Code:
    ' ---------- [ System Inputs ] ----------
    Circle      Var PORTA.0         ' 1 - Circle Switch
    
        MaskSwitch=PORTA & $07
            Select Case MaskSwitch
              Case 1 '%00000001 or Circle Switch
                If Circle = 1 Then Gosub Procedure_Circle
                If Circle = 0 THEN
                EndIf 
    ..........
    Thank you,

    Steve

  2. #2
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Second thoughts.....is there a way to use the Case Select option as above for PORTC.0-2 (as it currently is) for the first 3 switched inputs, but then use PORTB.0-2 for the remainding 3 swtched inputs?

    I am still new to using Case Selects so it is a bit confusing.

    Many thanks.

  3. #3
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    You must switch PortA to digital-I/O, after a Reset it will be only analog-in !
    Just see the docs !
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thanks BigWumpus, i tried this, but still no luck.

    Ideally i want to monitor lines RC0, RC1, RC2, RC6, RC7 and RA0 (can't use RC3 as there isn't one and RC4 & 5 are used for USB. When a switch is depressed on one of theses lines it jumps to a corresponding sub routine.

    I've got the Case Select routine working for RC0-2 but am struggling with the rest, particulalry as it loks at a different PORT.

    Can anyone help please?

    Thanks,

  5. #5
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    Check the documentation around ADCON1 to switch PortA from analog to digital.

    Your Case-statement looks fine, but is very very big in code !
    (You have to calculate the MaskSwitch out of 2 numbers!)

    Whats about this:

    -----
    Button1 Var PortC.0
    Button2 Var PortC.1
    ...
    Button7 Var PortA.0

    ADCON1=%00001111

    If Button1 Then
    If Circle = 1 Then Gosub Procedure_Circle
    Endif
    If Button2 Then
    If ...
    Endif
    -----
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  6. #6
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thanks for you help BigWumpus. I wanted to avoid using multiple IF..THEN statements as the 'cleaner' way is supposed to be using a CASE SELECT.

    However, this is where i fall down. I am having difficulty using the CASE SELECT with multiple PORTS.

    Obvioulsy if it can't be done then i have the multiple IF...THENS but i think with 5 or 6 buttons (or HIGH inputs as they will be), the code will be much bigger then using a structured CASE SELECT.

    Cheers,

    Steve

  7. #7
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    Hello,

    the complicated way:

    MaskSwitch=(PortC & %00000111) | ((PortC & %11000000) >> 3) | ((PortA.0 & %00000001) << 5)


    The better way (using the bit-operators of PICs):

    MaskSwitch=0
    If PortC.0 Then MaskSwitch.0=1
    If PortC.1 Then MaskSwitch.1=1
    If PortC.2 Then MaskSwitch.2=1
    If PortC.6 Then MaskSwitch.3=1
    If PortC.7 Then MaskSwitch.4=1
    If PortA.0 Then MaskSwitch.5=1


    Check out the size !!!

    But be aware to press more then ONE key !!!
    Then you have to write multiple case-lines !!! ;-)
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  8. #8
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    OK, So the second options is still using the CASE SELECT method is it?

    Does this mean that the statement will look as follows:
    Code:
    Button1      Var PORTC.0
    Button2      Var PORTC.1
    Button3      Var PORTC.2
    Button4      Var PORTC.6
    
    Main:
        MaskSwitch=0
        If PORTC.0 Then MaskSwitch.0=1
        If PORTC.1 Then MaskSwitch.1=1
        If PORTC.2 Then MaskSwitch.2=1
        If PORTC.6 Then MaskSwitch.3=1
            Select Case MaskSwitch
              Case 0
                If Button1 = 1 Then Gosub Procedure_Button1
                If Button1 = 0 THEN
                EndIf 
    
              Case 1
                If Button2 = 1 Then Gosub Procedure_Button2
                If Button2 = 0 THEN 
                EndIf 
    
              Case 2
                If Button3 = 1 Then Gosub Procedure_Button3
                If Button3 = 0 THEN
                EndIf 
    .......
    ie, does the MaskSwitch.1 represent Case 1 value, MaskSwitch.2 represent Case 2 etc etc?

    Many thanks again,

    Steve

  9. #9
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    No,

    like your first posting, the maskswitch is:

    1, 2, 4, 8, 16, 32 ....

    or binary:

    %00000001, %00000010, %00000100, %00001000, ...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  10. #10
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    ...and:

    why are you checking the buttons inside the case-staments, when the case-statements are only executed, if the Buttons are pressed ?

    Do you think, this will be the optimal way ?

    After programming several decades in assembler, i think it is better, to check the Port-Bits and call the subroutines...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Similar Threads

  1. MY FIRST scrolling 8X8 LED
    By earltyso in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th August 2008, 16:23
  2. How do I configure the PIC16F737?
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th November 2007, 23:05
  3. A little DTMF help
    By Travin77 in forum mel PIC BASIC Pro
    Replies: 48
    Last Post: - 30th May 2006, 01:31
  4. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29
  5. PORTA problems 18LF252
    By iphillips in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th February 2005, 13:56

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts