Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

programming a byte on one pin

Status
Not open for further replies.
Check in next week Mike I might have some further software developments using the blindfold method--lol
It works for Washington D.C.---lol
 
Check in next week Mike I might have some further software developments using the blindfold method--lol
It works for Washington D.C.---lol

Thank you for having a good sense of humor, and I agree about Washington D.C. (wink).

As bewildering as it might seem to a few of us who watch you take the long meandering route, as opposed to a more direct route, I don't think anyone can dispute that you always arrive at your destination with the results you were looking for. If you enjoyed the journey and accomplished your goals, what else matters? Right?

Happy Holidays and cheerful regards, Mike
 
Last edited:
Thank you for having a good sense of humor, and I agree about Washington D.C. (wink).

As bewildering as it might seem to a few of us who watch you take the long meandering route, as opposed to a more direct route, I don't think anyone can dispute that you always arrive at your destination with the results you were looking for. If you enjoyed the journey and accomplished your goals, what else matters? Right?

Happy Holidays and cheerful regards, Mike

i am also a avid MR DEB reader!! has to be said it is always a riveting read ;)- and to be honest i can see why some get frustrated but you have to admire MR DEB'S single minded determination to do the thing come hell or high water!! full marks for not giving up :D and Burt i am gonna get you canonized by the pope! saint Burt of ETO lol well done to both.
 
Gotta admit I'd have thrown in the towel a lot sooner than I could have a 15 page thread on the subject.

But, back to the fun...
In the end I want to be able to exit RIDE anytime. Seems like a button press takes a long time to react
And it would. In the latest code I see it could be almost a second before you leave RIDE and get back to the main button polling loop. In the original code it could have been almost twice that.

Did you try my suggestion? Polling the button press pins inside RIDE should get you back quite a bit faster.
 
Well I just got back from doing some minor repairs to our church.
When I have the monster running, durring the RIDE routine, then press a button, BAM the led flashes. then it goes into the turn routiine.
Can't tell if its one flash or two short flashes but it does flash upon pressing a button.
I have a video of it in action. Just need to upload. You can see the green LED flash for amusement purposes only. Just don't get to excited. I know saint Burt will ---lol
 
Video of LED

The button is really small but when I press it the RIDE sequence stops and it jumps to a turn routine. I don't think its two flashes?
[video]http://s992.beta.photobucket.com/user/MrDEB/media/Video7.mp4.html[/video]
Going to investigate if I can slow it down then see just where the routine stops in the middle or ?
 
In the for next loop of ride just test the buttons and exit. IF pressed and if the loop is 750mS your button test cold happen less then 100 mS which would be fine and no debounce needed.

If you really think about it ride should be the main loop, Then if you call the subs left right run that loop and test the button press each run of the for next loop which can be a fast test
 
Last edited:
Burt is entirely right. "RIDE" is the default state when the program is doing nothing else. "LEFT" and "RIGHT" are exceptions to the default state, initiated by a bottom press or head tip for whatever...who can keep track. Since it's always doing RIDE, put it in the main program loop.
 
I did this before reading

But yes RIDE should be in the main loop. Here I inserted a CHECK SWITCH in the RIDE SUB (going to make RIDE in main loop instead of sub?
I slowed down the RIDE sub and now it stops and exits to what ever turn is wanted.
Now to mess up Tumbleweeds code. Don't worry I saved my Bowels of hell code under a different name.
Code:
Sub RIDE()
    Dim index As Byte 
    Dim X As Byte
 
    For index = 0 To Bound (Ride_Data)
        DelayMS(500)//10 500us for constant on
        X = Ride_Data(index)
 
        LE = 0
        ResetPin_R = 1   // disable OE RED
        ResetPin_G = 1  // disable OE Green
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // CHECK SWITCHES
        If s1 = 0 Then          // sw 1 closed
        count = 0
       exit
    End If 
 
    If s2 = 0 Then          // sw 2 closed
        count = 0
    exit
 
    End If 
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
 
        Shift.Out(MSB_FIRST, X ,8)  
        LE = 1         //Latch data
        PORTB = R_Rows(index)  
        DelayUS(200) //20 us
        ResetPin_G = 0  // output LOW = ON HIGH = OFF
        ResetPin_R = 1
        LE = 0
    
    Next
 
End Sub
 
Just sit right back and hear a tale

A tale of a faithful code, that set sail for a 12 page tour, a 12 page tour.


Well I changed things around, put the RIDE in the main loop then inserted a check switch routoines in between.
Slowed down the RIDE sequence and upon pressing a switch, BAM it immedieatly or there abouts, goes to a turn sequence.
This seems S M OO T H ER
THANKS to ST. Burts suggestion
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/28/2012                                                     *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2012 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/27/2012                                                     *
*  Version : 1.0                                                            *
*  Notes   :  tumbleweed code rev 2                                                              *
*          :                                                                *
*****************************************************************************
}
Device = 18F2420
Clock = 20
 
// external xtal
Config OSC = HS
 
// uncomment next line to use internal osc
//Include "InternalOscillator.bas"          // module sets Config OSC = INTIO7 for you
 
Include "shift.bas"
Include "utils.bas"
Include "convert.bas"
 
Dim SDI As PORTC.4
Dim CLK As PORTC.5
Dim LE As PORTC.3
Dim RED_OE As PORTC.0
Dim GREEN_OE As PORTC.1
 
Dim DataPin As SDI  
Dim ClockPin As CLK
Dim ResetPin_R As RED_OE
Dim ResetPin_G As GREEN_OE
 
// pushbutton switches inputs S1 and S2
Dim s1 As PORTA.2
Dim s2 As PORTA.3
Dim count As Byte 
dim switch as byte
dim led as porta.0
Dim index As Byte 
Dim X As Byte  
Const Data(15)As Byte = (%00010001, %00001010 ,%00000100, %00010001, %00001010, %00000100, 
%00010001, %000001010 ,%00000100, %000010001,%00001010, %00000100, %000010001,%00001010, %00000100)
 
Const Rows(15) As Byte =(%00000001, %000000010 ,%00000100, %000000010, %00000100, %00001000,
 %00000100 ,%000001000 ,%00010000 ,%00001000,%00010000 ,%00100000, %00010000 ,%00100000, %01000000)
 
Const L_TRows(15) As Byte =( %01000000,%00100000,%00010000,%00100000,%000010000, %00001000, 
%00010000, %00001000, %00000100 ,%00001000, %000000100,%00000010,%00000100, %000000010,%00000001)
 
Const Ride_Data(15)As Byte = (%00011111, %00000100 ,%00011111, %00000100, %00011111, %00000100, 
%00011111, %00000100 ,%00011111, %00000100,%00011111, %00000100, %00011111,%00000100, %00011111)
 
Const R_Rows(15) As Byte =(%00001000, %011111111 ,%00001000, %011111111, %00001000, %01111111,
 %00001000 ,%011111111 ,%00001000 ,%01111111,%00001000 ,%01111111, %00001000 ,%01111111, %00001000)
 

 
Sub RIGHT()
    Dim index As Byte 
    Dim X As Byte
 
    For index = 0 To Bound (Data)
        DelayMS(10)//10 500us for constant on
        X = Data(index)
 
        LE = 0
        ResetPin_R = 1   // disable OE RED
        ResetPin_G = 1  // disable OE Green
        Shift.Out(MSB_FIRST, X ,8)  
        LE = 1         //Latch data
        PORTB = Rows(index)  
        DelayUS(20) //20 us
        ResetPin_R = 0  // output LOW = ON HIGH = OFF
        ResetPin_G = 1
        LE = 0
    Next
 
End Sub
 
Sub LEFT()
    Dim index As Byte 
    Dim X As Byte
 
    For index = 0 To Bound (Data)
        DelayMS(10)//10 500us for constant on
        X = Data(index)
 
        LE = 0  // move to top
        ResetPin_R = 1   // disable OE RED
        ResetPin_G = 1  // disable OE Green
        Shift.Out(MSB_FIRST, X ,8)  
        LE = 1         //Latch data
        PORTB = L_TRows(index)   // display byte on matrix
        DelayUS(20) //10  1 us for constant on
        ResetPin_R = 0  // output LOW = ON HIGH = OFF
        ResetPin_G = 1
    Next
 
End Sub
 
// start of main
SetAllDigital
 
Shift.SetOutput(DataPin)
Shift.SetClock(ClockPin)
 
High(ResetPin_R)        // make output and set high
High(ResetPin_G)        // make output and set high
Low(LE)                 // make output and set low
 
PORTB = 0
TRISB = %00000000       // make PORTB outputs
 
// make S1 and S2 switch inputs (assumes there are external pullups on the pins)
Input(s1)
Input(s2)
    
 
While true                   // durring RIDE the code jumps to here if switch = 1
   
  //  Dim index As Byte 
  //  Dim X As Byte
 
    For index = 0 To Bound (Ride_Data)
        DelayMS(500)//10 500us for constant on
        X = Ride_Data(index)
 
        LE = 0
        ResetPin_R = 1   // disable OE RED
        ResetPin_G = 1  // disable OE Green
        //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        // CHECK SWITCHES
        
        If s1 = 0 Then          // sw 1 closed
        count = 0
        repeat
        LEFT
        delayms(200)
        inc(count)
        until count=10
       End If  
        
       If s2 = 0 Then          // sw 1 closed
        count = 0
        repeat
        RIGHT
        delayms(200)
        inc(count)
        until count=10
       End If  
        
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
 
        Shift.Out(MSB_FIRST, X ,8)  
        LE = 1         //Latch data
        PORTB = R_Rows(index)  
        DelayUS(200) //20 us
        ResetPin_G = 0  // output LOW = ON HIGH = OFF
        ResetPin_R = 1
        LE = 0
    
    Next
 
wend
End
 
Burt is entirely right. "RIDE" is the default state when the program is doing nothing else. "LEFT" and "RIGHT" are exceptions to the default state, initiated by a bottom press or head tip for whatever...who can keep track. Since it's always doing RIDE, put it in the main program loop.

You know, I was just kind of thinking the same thing. Now that (I hope) I understand what he's trying to do I suspect a minor restructuring would probably solve a couple problems, including switch response, by simply building the main program loop around the switch code and using the switch "debounce" interval as the main loop timing interval.

What do you guys think of this loop model in pseudo C code (below)? I've taken a number of short-cuts, including connecting the driver IC <latch> and </oe> lines to a single I/O for both the green and red driver ICs.

If you don't understand the parallel switch state logic, just think of it as non-blocking multi-switch "black box" code that filters out all but a "new press" switch state change and uses it to emulate a "toggle" switch. That is, any "new press" will toggle a flag from either on-to-off or from off-to-on. In operation this means when you press the <left> turn signal switch, the left turn signal sequence continues indefinitely, until you press the <left> turn signal switch again. Of course using momentary contact push button switches to emulate toggle switches allows using an LED on the same I/O pin so you can have a visual "turn signal on" indicator right at each switch at practically no cost.

Could a structure change be beneficial?

Regards, Mike

Code:
    while(1)                           //
    { delay_ms(25);                    // 25-ms 'debounce' interval
     /*                                                                 *
      *  K8LH parallel switch state logic (with "new press" filter)     *
      *                                                                 *
      *  swnew  ___---___---___---_____   invert active lo switches     *
      *  swold  ____---___---___---____   switch state latch            *
      *  swnew  ___-__-__-__-__-__-____   changes, press or release     *
      *  swnew  ___-_____-_____-_______   filter out 'release' bits     *
      *  flags  ___------______--------   toggle flag bits for main     *
      *                                                                 */
      swnew = ~porta;                  // sample active lo switches
      swnew &= 0b00011000;             // on the RA4..RA3 pins only
      swnew ^= swold;                  // changes, press or release
      swold ^= swnew;                  // update switch state latch
      swnew &= swold;                  // filter out 'release' bits
      flags ^= swnew;                  // toggle flag bits for main

      if(swnew)                        // if any new press (toggle)
      { index = 0;                     // reset array index
      }                                //

     /*                                                                 *
      *  refresh matrix display for "ride", "left", or "right" mode     *
      *                                                                 */
      if(!flags)                       // if no switches (ride mode)
      { if(index > bound(ride_data))   // if index overflow
          index = 0;                   // reset index
        shiftout(ride_data[index]);    // send "ride" column SR data
        redlat = 1;                    // red disp off & latch data
        grnlat = 1;                    // grn disp off & latch data
        portb = ride_rows[index++];    // portb = "ride" row data
        grnlat = 0;                    // grn display on
      }                                //
      else                             // sw1 (right) or sw2 (left)
      { if(index > bound(turn_data))   // if index overflow
          index = 0;                   // reset index
        shiftout(turn_data[index]);    // send "turn" column SR data
        redlat = 1;                    // red disp off & latch data
        grnlat = 1;                    // grn disp off & latch data
        if(flags.3)                    // if sw1 (right) 'on'
          portb = rt_rows[index++];    // portb = right row data
        else                           // otherwise, sw2 (left) 'on'
          portb = lt_rows[index++];    // portb = left row data
        redlat = 0;                    // red display on
      }                                // 
    }                                  // end while(1){}
  }                                    // end main{}
 
Last edited:
That's to simple but its the right way to handle this after all you want turn signals on the whole time you turn and now all we need is a way to flip the handle back when where going strait. :D:D:D
 
It went down with the Titanic --lol
Am connecting up the encoder/dcecoder chips with their respective RX/TX modules.Need to insert a voltage reg as well. In between sessions(get frustrated) I tinker with a project that Brads projectshttp://www.bradsprojects.com/electronics/BradsProjects-Welcome.html has (I received boards but can't get the PICKIT2 to recognize the PIC.)
Having to recheck all my connections as the PICKIT2 keeps saying ALL PROTECT or CODE PROTECT?The PIC is a 16F677
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top