Menu

Struggling to run two separate routines

Phil D
2020-05-28
2020-05-28
  • Phil D

    Phil D - 2020-05-28

    Hi all,

    I have written a GCB script to run two separate routines on my breadboard, I am not sure if GCB is able to do this, but essentially I have a Red, Green, Yellow & Blue LED's. I would like the Red, Green and Yellow to run as input to output (i.e. SetWith). The Yellow is shared between the two routines. The Yellow and Blue are to run as 'Select Case' based upon the ADCValue. The code doesn't seem to work and I suspect I am missing a small (yet VERY essential) link between trying to run the to commands/routines. I have pasted my code below and would appreciate any feedback. Thanks in advance guys.

    chip 16f1823

    option Explicit

    #define RIN RA2
    #define GIN RA0
    #define YIN RA4
    #define BIN RA1
    #define ROU RC4
    #define GOU RC1
    #define YOU RC3
    #define BOU RC2

    Dir ROU out
    Dir GOU out
    Dir YOU out
    Dir BOU out
    Dir RIN in
    Dir GIN in
    Dir YIN in
    Dir BIN in

    '-----MAIN BODY OF PROGRAM COMMENCES HERE.,
    Do Forever

    SetWith ( ROU, RIN )
    SetWith ( GOU, GIN )
    SetWith ( YOU, YIN )

    Loop

    Dim ADCValue as Byte

    Do Forever

    ADCValue = ReadAD( AN1 )
    
    Select Case ADCValue
      case 0 to 34
        YOU = 0
        BOU = 0
    
      case 35 to 178
        YOU = 1
        BOU = 0
    
      case 179 to 255
        YOU = 0
        BOU = 1
    
    end select
    
    wait 100 ms
    
    Loop
    
     
  • Chris Roper

    Chris Roper - 2020-05-28

    Your first loop is do Forever so the second loop will never run.
    Combine them both into one loop and see if that helps.

    chip 16f1823
    option Explicit
    #define RIN RA2
    #define GIN RA0
    #define YIN RA4
    #define BIN RA1
    #define ROU RC4
    #define GOU RC1
    #define YOU RC3
    #define BOU RC2
    
    Dir ROU out
    Dir GOU out
    Dir YOU out
    Dir BOU out
    Dir RIN in
    Dir GIN in
    Dir YIN in
    Dir BIN in
    
    '-----MAIN BODY OF PROGRAM COMMENCES HERE.,
    Dim ADCValue as Byte
    
    Do Forever
    
    ADCValue = ReadAD( AN1 )
    
    Select Case ADCValue
      case 0 to 34
        YOU = 0
        BOU = 0
    
      case 35 to 178
        YOU = 1
        BOU = 0
    
      case 179 to 255
        YOU = 0
        BOU = 1
    
    end select
    
    SetWith ( ROU, RIN )
    SetWith ( GOU, GIN )
    SetWith ( YOU, YIN )
    
    wait 100 ms
    
    Loop
    

    The above is untested, it is just a suggested structure for your code.

     

    Last edit: Chris Roper 2020-05-28

Log in to post a comment.