Am I heading in the right direction?


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Sorry i can't read the file you have attach. I would suggest you to convert it in a BMP, PNG, or whatever else format.

    If your schematic software don't allow that, use PrimoPDF. This will act as a virtual printer. So you just need to select PrimoPDF before you print and it will create a PDF file.

    Nice nifty and FREE software -> http://www.primopdf.com/

    this..
    Code:
    @  DEVICE  11111101110100b           ; Internal Osc, WDT, PWRT, BOD, MCLR reset, CCP w/ RB2, LVprog disabled,
                                         ; Flash program memory write enabled, No Code Prot., No EEPROM Prot.
                                         ; Fail-safe clock monitor enabled, Internal external switch over enabled.
    don't looks familiar. I would suggest you to read the following post

    http://www.picbasic.co.uk/forum/showthread.php?t=543

    also make sure you have pull-up resistor on PORTB...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Schematic Round 2. . . fight

    I learned the @ device command from my boss, for setting the fuses. The binary comes from page 130 of the datasheet for PIC16F88.

    Schematic should be readable now, although Im fairly positive my problem lies within my code. thank you thus far.
    Attached Images Attached Images  

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Code is working the way it is written. Your IF THEN loops basicly check to see if logic 0 is detected, if so it checks the next switch and if good continues . . . , it then executes a GOTO main and never goes to the next subroutine. it goes to the subroutine Continue if the if then is false, which as shown is an empty subroutine. The MAIN loop reinitializes the LEDs as off and sets the internal registers as logic high.
    I think you only want to execute the code listed as main at startup. I would use gosub to execute the subroutines and return in the subroutine to cause the code to RETURN to the place just after it was sent there. something like:<p>
    ' code initialization

    led1 = 0 'Turn LED1 off
    led2 = 0 'Turn LED2 off
    led3 = 0 'Turn LED3 off
    led4 = 0 'Turn LED4 off
    pswitch1 = 1 'Define switch1 as not pressed
    pswitch2 = 1 'Define switch2 as not pressed
    pswitch3 = 1 'Define switch3 as not pressed
    pswitch4 = 1 'Define switch4 as not pressed

    ' here is your main loop
    main:
    gosub nothing ' check this sub routine and then gosub to the next sub r...
    gosub LEDtwo ' this is the next thing loop will check
    gosub LEDfour ' and then it will heck here
    goto main ' now the loop repeats


    nothing:
    BLA BLA BLA
    return

    LEDtwo:
    MORE BLA BLA
    return

    YAGETTHEIDEA:
    bla bla
    return
    end

    HTH
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Jul 2007
    Location
    Maryland, USA
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Not clear?

    I dont think my orginal explanation of this project was clear enough.

    Digits come at intervals of 30 seconds. Total digits per input = 1. Total inputs per code = 4 So I need to scan for 2 minutes, then once I have all four digits, I need to send an output based on the input received.

    Look for input1 for 30seconds = TS1
    Look for input2 for 30seconds = TS2
    Look for input3 for 30seconds = TS3
    Look for input4 for 30seconds = TS4


    so if I get a 1 as my first input, then the other 3 inputs dont matter, LED1 lights up.
    If my first input is a 2 but the other inputs are all zero's, then no LED's light up
    If my first input is a 2 and any other input is 1-4, then LED2 + LED1 light up
    my examples of the first inputs being 2 correspond with the first inputs being 3 or 4 aswell.

    Example of 5 different codes received and their output operation:
    ts1---ts2---ts3---ts4
    1-----0-----1-----0---= HIGH LED1
    2-----0-----0-----0---= NO LED'S HIGH
    2-----1-----0-----0---= HIGH LED1 and LED2
    3-----0-----0-----0---= NO LED'S HIGH
    3-----0-----2-----0---= HIGH LED1 and LED3


    hopefully this will help clarify the operation. i've changed my code a bit, I "think" its starting to get to where it needs to be, but I still dont know how to assign 30seconds per input received.

    Code:
    'Code Development / Debug Device Setting
    '           DCBA9876543210
    @  DEVICE  11111101110100b           ; Internal Osc, WDT, PWRT, BOD, MCLR reset, CCP w/ RB2, LVprog disabled,
                                         ; Flash program memory write enabled, No Code Prot., No EEPROM Prot.
                                         ; Fail-safe clock monitor enabled, Internal external switch over enabled.
    
    '------( Symbols/ Labels )------
    '     
    Symbol Pswitch1 = portb.0                'Pin6/RB0 is assigned as switch1
    Symbol Pswitch2 = portb.1                'Pin7/RB1 is assigned as switch2
    Symbol Pswitch3 = portb.2                'Pin8/RB2 is assigned as switch3
    Symbol Pswitch4 = portb.3                'Pin9/RB3 is assigned as switch4
    Symbol LED1 = portb.7                 'Pin13/RB7 is assigned as LED1
    Symbol LED2 = portb.6                 'Pin12/RB6 is assigned as LED2
    Symbol LED3 = portb.5                 'Pin11/RB5 is assigned as LED3
    Symbol LED4 = portb.4                 'Pin10/RB4 is assigned as LED4
    
    '------( Constants )------
    '
    
    '------( Defines  )------ 
    '    
        Define OSC          8               'Set oscillator at 8MHz
        
    '------( Variables )------
    '
    GotInfo     var byte
    GotInfo1    var byte
    GotInfo2    var byte
    GotInfo3    var byte
    empty       var byte                         'Time variable not used
    tS1         var byte                         'Time variable for 1st digit
    tS2         var byte                         'Time Variable for 2nd digit
    tS3         var byte                         'Time Variable for 3rd digit
    tS4         var byte                         'Time Variable for 3th digit
    
    '------( Registers )------
    '            76543210
        OSCCON = %01110110                   'Set Osc for 8Mhz
        TRISB  = %00001111                   'RB0-RB3 = inputs, RB4-RB7 = outputs
        TRISA  = %00000000                   'RA0-RA7 = outputs
        PORTA  = %00000000                   'Turn off portA
        CMCON  = %00000111                   'Turn comparators OFF   
        ANSEL  = %00000000                   'A/D converter set as Digital I/0
    
    '------( Disable Interrupts/Registers )------    
    '                  76543210
        INTCON      = %00000000
        PIE1        = %00000000
        PIR1        = %00000000
        OPTION_REG  = %00000000
    '------( Initialization )------
    ' 
    main:
    
        led1 = 0                                'Turn LED1 off
        led2 = 0                                'Turn LED2 off
        led3 = 0                                'Turn LED3 off
        led4 = 0                                'Turn LED4 off
        pswitch1 = 1                            'Define switch1 as not pressed
        pswitch2 = 1                            'Define switch2 as not pressed
        pswitch3 = 1                            'Define switch3 as not pressed
        pswitch4 = 1                            'Define switch4 as not pressed
    
        goto inputloop
    '------( Main Code )------
    '  
    Inputloop:                      'Wait here for input
            
        if pswitch1 = 0 then        'If switch1 is pressed         
            led1 = 1                'Light LED1
            pause 3000              'Pause 3 seconds
            led1 = 0                'Turn LED1 off
            goto inputloop          'check for more inputs   
        endif                       
                                        
        
        if pswitch2 = 0 then                                            'If Switch2 is pressed
            tS1 = gotinfo                                               'rename Switch2, tS1 
                while ts1 = gotinfo                                     '
                '----------------------------   
                    if pswitch1 = 0 then                                '
                        ts2 = Gotinfo1 
                    else 
                        ts2 = empty 
                    '---------------------------- 
                            if pswitch3 = 0 then
                                ts2 = gotinfo1    
                            else 
                                ts2 = empty
                            '----------------------------        
                                    if pswitch4 = 0 then
                                        ts2 = gotinfo1
                                    else 
                                        ts2 = empty
                                    '----------------------------
                                            if ts2 = empty then
                                                goto checkTs3
                                            endif
                                    endif                   
                            endif
                    endif
                wend
        endif   
    
    checkTS3:
        while ts1 = gotinfo and ts2 = empty
            
            if pswitch1 = 0 then
                ts3 = gotinfo2
            else
                ts3 = empty
            '----------------------------    
                    if pswitch3 = 0 then
                        ts3 = gotinfo2
                    else
                        ts3 = empty
                    '----------------------------
                            if pswitch4 = 0 then
                                ts3 = gotinfo2
                            else
                                ts3 = empty
                            '----------------------------
                                if ts3 = empty then
                                    goto checkts4
                                endif
                            endif
                    endif
            endif
        wend
    
    
    checkTS4:
        WHILE TS1 = gotinfo and ts2 = empty and ts3 = empty
            
            if pswitch1 = 0 then
                ts4 = gotinfo3
            else
                ts4 = empty
            '----------------------------
                    if pswitch3 = 0 then
                        ts4 = gotinfo3
                    else 
                        ts4 = empty
                    '----------------------------
                            if pswitch4 = 0 then
                                ts4 = gotinfo3
                            else 
                                ts4 = empty
                            '----------------------------         
                                if ts4 = empty then
                                    goto nothing
                                    
                                endif
                            endif
                    endif     
            endif                        
        wend
    
    
        if ts1 = gotinfo then
            led1 = 0
            led2 = 0
            led3 = 0
            led4 = 0
            goto inputloop
        endif
    
        if ts1 = gotinfo and ts2 = gotinfo1 then
            led2 = 1
            led1 = 1
            pause 3000
            led2 = 0
            led1 = 0
            goto inputloop
        endif
        
        if ts1 = gotinfo and ts3 = gotinfo2 then
            led2 = 1
            led1 = 1
            pause 3000
            led2 = 0
            led1 = 0
            goto inputloop
        endif
        
        if ts1 = gotinfo and ts4 = gotinfo3 then
            led2 = 1
            led1 = 1
            pause 3000
            led2 = 0
            led1 = 0
            goto inputloop
        endif
    Last edited by james; - 26th September 2007 at 15:33.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi James,
    try this for your config setting instead of the @ devise xxx you have, and use the osccon settings below to set osc speed, just remove the comment for the one you need. MPASM assembler settings

    @ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF

    ' for 8mhz
    'OSCCON=%01111000
    'for 4MHZ
    'OSCCON=%01101000

    You might give this a try too:
    If PortB != %00001111 then PAUSE 30000 ' pause 30 seconds

    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Math help - rolling average Wind Direction
    By wjsmarine in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 23rd July 2009, 00:08
  3. How to detect sound direction?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th December 2008, 04:53
  4. Replies: 10
    Last Post: - 8th April 2008, 21:07
  5. Replies: 5
    Last Post: - 12th September 2007, 15:59

Members who have read this thread : 0

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