Replacing existing pic


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Gone completely back to the idea of replacing the pic.

    I think I'll be best served by hooking up my soundcard scope and seeing if it is indeed scanning the input buttons.

  2. #2
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Thumbs up

    Ok guys, I've replicated the functionality of the original 8 pin chip, here's the code - any thoughts?

    This is why there's pin fiddling on BUTTONA and BUTTONB
    Attachment 2617

    Thanks some more

    Code:
    ' Configure the FUSE options for the compiler
    @     device pic16F628A, hs_osc, wdt_off, pwrt_on, lvp_off, protect_off, bod_on, cpd_off, pwrt_off, mclr_off
    
    ' Running a 20Mhz clock
    DEFINE OSC 20
    DEFINE PULSIN_MAX 3000
    
    CMCON        = 7
    VRCON        = 0
    
    ALL_DIGITAL
    
    ' Setup the USART
    DEFINE HSER_RCSTA 90h      ' Receive register to receiver enabled
    DEFINE HSER_TXSTA 20h      ' Transmit register to transmitter enabled
    DEFINE HSER_BAUD 19200     ' Set baud rate
    
    ' Alias our pins           
    BEEP VAR PORTA.0           ' Buzzer
    RFIN VAR PORTA.1           ' Remote input
    RELAY1 VAR PORTB.4         ' Relay 1 output
    RELAY2 VAR PORTB.5         ' Relay 2 output
    BUTTONA VAR PORTB.6        ' Primary panel button input
    BUTTONB VAR PORTB.7        ' Secondary panel button input
    
    ' Set the pin directions
    INPUT RFIN
    INPUT BUTTONA
    INPUT BUTTONB
    
    OUTPUT BEEP
    OUTPUT RELAY1
    OUTPUT RELAY2
    
    ' Configure the output pins as low
    LOW BEEP
    LOW RELAY1
    LOW RELAY2
    
    ' Turn on weak pull-ups - IMPORTANT: After making relays and beepers low...
    OPTION_REG.7 = 0 
    
    ' Set us up some variables
    PBITS       VAR BYTE[24]   ' The bits we've read
    RAW         VAR WORD       ' The raw pulsin value
    ADDRESS     VAR WORD       ' Storage for the address
    DBYTE       VAR BYTE       ' Storage for the data
    LOOPADDRESS VAR WORD       ' Second loop storage of first loop addres
    LOOPDBYTE   VAR BYTE       ' Second loop storage of first loop data byte
    X           VAR BYTE       ' Loop/TMP var
    Y           VAR BYTE       ' Loop/TMP var
    STATE       VAR BYTE       ' Current state of the device
    
    ' Constants
    STATE_STOPPED    CON 0     ' Screen is stopped
    STATE_GOING_UP   CON 1     ' Screen is going up
    STATE_GOING_DOWN CON 2     ' Screen is going down
    
    ' Default state
    STATE = STATE_STOPPED
    
    ' Reset all the primary RF variables
    TOP:
        ADDRESS = 0 : RAW = 0 : DBYTE = 0
        
    ' This is the real main - almost all the looping comes back here
    MAIN:
        ' Set both buttons for input
        INPUT BUTTONA
        INPUT BUTTONB
        ' Check to see if the individual buttons are toggled
        IF NOT BUTTONA THEN GOSUB subDown
        IF NOT BUTTONB Then GOSUB subUp
        ' Fiddle with the inputs to see if the middle button is pushed
        LOW BUTTONB
        X = BUTTONA ' If it's LOW then there's a good chance the middle button is down
        HIGH BUTTONB
        INPUT BUTTONB
        LOW BUTTONA  
        Y = BUTTONB ' If it's LOW then there's a good chance the middle button is down
        HIGH BUTTONA
        INPUT BUTTONB
        INPUT BUTTONA
        IF NOT Y AND NOT X THEN GOSUB subStop ' Both register as LOW then the middle button is down!
        
        ' Look for one huge low pulse
        PULSIN RFIN, 0, RAW
        ' 2350 is about mean average
        IF RAW < 2340 OR RAW > 2360 THEN MAIN
    
        ' Read 16 address bits and 8 data bits    
        FOR X = 0 TO 23
            PULSIN RFIN, 0, RAW
            ' Check the pulse parameters
            IF RAW < 30 OR RAW > 240 THEN MAIN
            PBITS[x] = NCD RAW
        NEXT X
        
        ' Gather the address
        ADDRESS = 65535 ' Maxmimum known ID
        FOR X = 0 to 15
            IF PBITS[x] > 7 THEN ADDRESS.0[X] = 0
        NEXT X
        
        ' Gather the data
        DBYTE = 255 ' Maximum known data value
        Y=0
        FOR X = 16 TO 23
            IF PBITS[X] > 7 THEN DBYTE.0[Y] = 0
            Y = Y + 1
        NEXT X
    
        ' If we've done a loop...
        IF ADDRESS == LOOPADDRESS AND DBYTE == LOOPDBYTE THEN
            SELECT CASE DBYTE
                CASE 3
                    GOSUB subUp
                CASE 12
                    GOSUB subStop
                CASE 192
                    GOSUB subDown
            END SELECT
            LOOPDBYTE = 0
            LOOPADDRESS = 0
        ELSE
            ' Start a loop
            LOOPDBYTE = DBYTE
            LOOPADDRESS = ADDRESS
        ENDIF
    
        GOTO TOP
    END
    
    subUp:
        IF STATE != STATE_GOING_UP THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["UP",10,13]  ' DEBUG
            LOW RELAY1            ' Make sure the down relay is off (Don't know what happens otherwise, don't want to know!)
            PAUSEUS 65355         ' Wait a bit
            HIGH RELAY2           ' Turn the up relay on
            LOW BEEP              ' STFU :)
            STATE = STATE_GOING_UP
        ENDIF
        RETURN
        
    subStop:
        IF STATE != STATE_STOPPED THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["STOP", 10, 13] ' DEBUG
            LOW RELAY1            ' Turn off the down relay
            LOW RELAY2            ' Turn off the up relay
            PAUSEUS 65355         ' Wait a bit
            LOW BEEP              ' STFU :)
            STATE = STATE_STOPPED
        ENDIF
        RETURN
    
    subDown:
        IF STATE != STATE_GOING_DOWN THEN
            HIGH BEEP             ' Start making noise
            HSEROUT ["DOWN",10,13] ' DEBUG
            LOW RELAY2            ' Make sure the up relay is off (Don't know what happens otherwise, don't want to know!)
            PAUSEUS 65355         ' Wait a bit
            HIGH RELAY1           ' Turn the down relay on
            LOW BEEP              ' STFU :)
            STATE = STATE_GOING_DOWN
        ENDIF
        RETURN

  3. #3
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    He guys.

    Is there any way (other then DarrelTaylor's elapsed timer) to work out how many seconds have passed?

    Darrel's method K/O's my pulsin code.

    I was looking to time the descent of the screen and stop it at 44 seconds - which is the right height for viewing.

    My fall back method is a reed switch - but that'll mean that there's an ugly reed switch visible to the naked eye when the screen is up.

    For the record the screen takes 49 seconds to fully descend but that leaves it about a foot too long.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Search the forum for Mel's Olympic Timer and RTC. The might do the trick.

    Paul has one also.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

  6. #6
    Join Date
    May 2008
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Thanks mackrackit, I'll have a look at these.

    I've already worked out I can't rely simply on adding 1 to a word (while in theory this works, in reality there's quite a deviation)

    I am prepared to fall back on pullies, string, and a piece of pvc with a magnet/reed switches if I have to - this will allow me to put the sensors out of sight... hopefully

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Freman View Post
    I am prepared to fall back on pullies, string, and a piece of pvc with a magnet/reed switches if I have to - this will allow me to put the sensors out of sight... hopefully
    Haven't read the whole thread..but...
    Couldn't you put a small piece of something reflective on the back of the screen, have an IR led/detector module or similar mounted in the wall behind the screen, if even a few feet behind the screen, and use the detector output as the start/stop sensor? One gets set up so when the beam is there (i.e. reflective piece is bouncing back the light), the screen is all the way down, the other is set up at the top so when the beam is there, the screen isn't quite all the way up. You really wouldn't even need the beam on continuously, just a quick blip every second or so might tell you what you want to know.

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 11:00
  2. Replacing Hall Effect throttle with PIC
    By idtat in forum General
    Replies: 4
    Last Post: - 22nd October 2009, 22:55
  3. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 22:01
  4. Replacing shift register with PIC
    By TonyA in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th April 2008, 19:31
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th March 2005, 00:14

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