KITT2000 Stoplight - Indexing/Referencing Ports & Tristate use


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891

    Default KITT2000 Stoplight - Indexing/Referencing Ports & Tristate use

    The aim of this circuit is to create à "KITT2000" effect on a car's stoplight.

    Just look here how the final result looks like: http://home.citycable.ch/flotulopex/...O_KITT2000.mov

    The circuit and the program are themselves not complicated but there are some interresting pieces of information I could gather in the forum and want to summarize here.

    I had to finish this circuit in a rush since my daugther became 18 and her car had to be ready and "tuned" on time. For this reason, I didn't use an interresting way to apply the tristate functionality of the PIC to make the circuit even more interresting (MicroChip's "Tips & Tricks" is not applicable here). Nevertheless, thanks to lots of you, here is a schema made and tested by Alain allowing the tristage usage for "high" power leds. Have a look here: http://www.picbasic.co.uk/forum/showthread.php?t=7056
    <table border=0><tr><td><img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2057&stc=1&d=119107111 3"></td><td>
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2056&stc=1&d=119107167 2"></td></tr></table>
    In the code, you'll find how to use the stoplight (there is no extra switch - only the brake pedal is used) and an example about how to Index or Reference Ports (look at the KITT2000 subroutine).
    Code:
    '****************************************************************
    '*  Name    : KITT2000_2x-LEDs-per-port_16F630_v2.BAS           *
    '*  Author  : FLOTUL                                            *
    '*  Notice  : Copyright (c) 2006 Flotulopex & Co.               *
    '*          : All Rights Reserved                               *
    '*  Date    : 11.08.2007                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : "Knight Rider" style stoplight                    *
    '*          :  KITT = Knight Industries Two Thousand            *
    '*  Tested  : yes                                               *
    '*  Finished: yes                                               *
    '****************************************************************
    '
    ' Make 20 LEDs car stoplight scroll from left to right and backwards like
    '  KITT2000 car.
    '
    ' When going on brakes, the stoplight will light-up normally (all leds
    '  appearing to light simultaneously).
    '
    ' If the brakes are released for a very short time (47...100µ capa determines
    '  the duration), the program switches to KITT led mode.
    '
    ' There are two light "modes":
    ' 1) STOPLight: go on brakes and all leds appear to light-up simultaneously.
    '   In this mode, leds are grouped in 5 pairs. They are swicthed-ON and -OFF
    '   in sequence to keep the total current low (around 200mA).
    ' 2) KITT2000: the "Knight Rider" effet. The leds scroll from left to right and
    '   vice-versa.
    '
    ' To index the PORTs, the "trick" is to use PORTA.0 as offset point (0).
    ' Since all other ports are consecutive, PORTB.0 is bit 8,
    '  and PORTC.0 is bit 16, etc. So, it looks like this:
    '  PORTA.2 = 2,  PORTA.4 = 4,  PORTA.5 = 5
    '  PORTB.3 = 11, PORTB.4 = 12, PORTB.5 = 13
    '  PORTC.0 = 16, PORTC.1 = 17, PORTC.2 = 18
    '
    ' Power OFF/ON (brake release) detect on PORTA.3
    ' LEDs = PORTA.1-2-4-5, PORTC.0-1-2-3-4-5
    '
    ' Currently, I paired the leds so each ports light-up two leds simultaneously.
    
    '-------------------------------------------------------------------------------
    ' Fuses
    @ DEVICE PIC16F630,BOD_ON   ; Mandatory for this circuit
    @ DEVICE PIC16F630,CPD_OFF
    @ DEVICE PIC16F630,PROTECT_OFF
    @ DEVICE PIC16F630,MCLR_OFF
    @ DEVICE PIC16F630,PWRT_OFF
    @ DEVICE PIC16F630,WDT_OFF
    @ DEVICE PIC16F630,INTRC_OSC_NOCLKOUT
    
    '-------------------------------------------------------------------------------
    ' Registers   76543210
    TRISA      = %00001000 'Set Input/Output
    PORTA      = %00000000 'Ports High/Low
    TRISC      = %00000000 'Set Input/Output
    PORTC      = %00000000 'Ports High/Low
    OPTION_REG = %10000000 'PORTA Pull-Ups disabled, prescaler bits 2-0
    WPUA       = %00000000 'Weak Pull-up of PORTA disabled
    INTCON     = %00000000 'GIE & TMR0 disabled
    OSCCAL     = %10000000 'Oscillator Calibration when Internal RC set to 4MHz
    CMCON      = %00000111 'Comparator Module is OFF
    
    '-------------------------------------------------------------------------------
    ' Defines
    
    '-------------------------------------------------------------------------------
    ' Variables
    Counter   var byte
    counter   = 0
    STOPSpeed var byte
    STOPspeed = 5
    KITTSpeed var byte
    KITTSpeed = 45
    
    Led    var byte[10]
    Led[0] = 1  'PORTA.1
    Led[1] = 2   'PORTA.2
    Led[2] = 4    'PORTA.4
    Led[3] = 5     'PORTA.5
    Led[4] = 16     'PORTC.0
    Led[5] = 17 'PORTC.1
    Led[6] = 18  'PORTC.2
    Led[7] = 19   'PORTC.3
    Led[8] = 20    'PORTC.4
    Led[9] = 21     'PORTC.5
    
    '-------------------------------------------------------------------------------
    ' Program
    MAIN:
        'STOPlight mode
        PORTA.0(1)=1 : PORTA.0(17)=1  'Leds 0 & 5
            pause stopspeed
        PORTA.0(1)=0 : PORTA.0(17)=0
        PORTA.0(2)=1 : PORTA.0(18)=1  'Leds 1 & 6
            pause stopspeed
        PORTA.0(2)=0 : PORTA.0(18)=0
        PORTA.0(4)=1 : PORTA.0(19)=1  'Leds 2 & 7
            pause stopspeed
        PORTA.0(4)=0 : PORTA.0(19)=0
        PORTA.0(5)=1 : PORTA.0(20)=1  'Leds 3 & 8
            pause stopspeed
        PORTA.0(5)=0 : PORTA.0(20)=0
        PORTA.0(16)=1 : PORTA.0(21)=1 'Leds 4 & 9
            pause stopspeed
        PORTA.0(16)=0 : PORTA.0(21)=0
        
        if PORTA.3 = 0 then 'if the brakes are released shortly...
            goto kitT2000    'go and stay there!
        endif
    
        goto main
    end
    
    
    ' Initial version (103 Words)
    KITT2000:
        'Scroll Led from left to right
        for counter = 0 to 9
            PORTA.0(Led[counter]) = 1 'switch led ON
            PAUSE KITTSpeed
            PORTA.0(Led[counter]) = 0 'switch led OFF
        next counter
        'Reverse order
        for counter = 8 to 1 step -1  'also try from 9 to 1
            PORTA.0(Led[counter]) = 1 'switch led ON
            PAUSE KITTSpeed
            PORTA.0(Led[counter]) = 0 'switch led OFF
        next counter
        goto kitT2000
    
    
    ' LOOKUP version (121 Words)
    'KITT2000:
    '    'Scroll Led from left to right
    '    for counter = 0 to 9
    '        lookup counter,[1,2,4,5,16,17,18,19,20,21],led
    '        PORTA.0(led) = 1 'switch led ON
    '        PAUSE KITTSpeed
    '        PORTA.0(led) = 0 'switch led ON
    '    next counter
    '    'Reverse order
    '    for counter = 0 to 7
    '        lookup counter,[20,19,18,17,16,5,4,2],led
    '        PORTA.0(led) = 1 'switch led ON
    '        PAUSE KITTSpeed
    '        PORTA.0(led) = 0 'switch led ON
    '    next counter
    '    goto KITT2000
    Attached Images Attached Images   
    Attached Files Attached Files
    Roger

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hello Roger

    Ben au moins ça fait plaisir de voir que tu es content !!! ...

    Nice to see you happy with your project !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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