Need help programming 12F675 for Halloween project

Discussion in 'Embedded Systems and Microcontrollers' started by booji, Sep 27, 2009.

  1. booji

    Thread Starter New Member

    Sep 27, 2009
    3
    0
    Hi. I need help writing code for a 12F675 to flash LEDs in a specific sequence.
    I want to press a switch, display the following binary sequence, then pause until the switch is pressed again: 1000,0100,0010,0001,1111,1000,0100,0010,1111,1000,0100,1111,1000,1111

    Seems simple enough, but I've been unsuccessful in my lame attempts at coding. I can design & build the circuit easily, just need the asm code.
    This is for a custom T-shirt using 4 LED backlight assemblies from ipod screens. Thanks very much!
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Why don't you post your source code and schematic so we can see where you are now?
     
  3. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi booji,
    This is a very easy program. I am busy now and hope to provide you the Code tomorrow. Since you require 5 Pins (4 for 4 Leds and 1 for Switch), You have to use internal 4MHz Oscillator as you cannot use external Xtal as its use will keep only 4 pins for you out of 6 and you have to use Shift Register or you have to use a Microcontroller with more I/O Pins. Do you know how to use internal Oscillator? O.K. I will see tomorrow. Thanks.
     
  4. booji

    Thread Starter New Member

    Sep 27, 2009
    3
    0
    Tahmid, thank you for the reply. The OSCCAL value is 0002, if I didn't already erase it by accident. Is that critical? I need each step to light for approx 500ms, give or take 100ms. The start switch will be on GP3, and the LED's on GP0, GP1, GP2 & GP5.
     
  5. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    Here is the code in ASM. Delay is 500ms in between. If you require 1sec, call the 500ms delay twice. Circuit, if required, is attached. Sequence is maintained according to your requirement.

    Code ( (Unknown Language)):
    1. ; PROG WITH PIC 12F675 - SEQUENTIAL LED LIGHTING.
    2. ; PROCESSOR - 12F675
    3. ; INTERNAL OSCILLATOR - 4MHZ
    4. ; DATED:28 SEPTEMBER, 2009
    5. ; PREP BY: SYED TAHMID MAHBUB.
    6. ;----------------------------------------------------------------
    7.  
    8.   TITLE:"SEQUENTIAL LED LIGHTING WITH PIC 12F675."
    9.  
    10.        LIST P = 12F675
    11.        #INCLUDE "P12F675.INC"
    12.  
    13.          __CONFIG     H'31C4'
    14.    
    15.        ; 0011 0001  1100     0100
    16.        ;  3      1       c         4        ; MASTER CLR PIN USED AS INPUT PIN
    17.  
    18.  
    19.  
    20.           CBLOCK      0X20
    21.           D1,D2,D3,D4,D5     ; VARIABLES USED IN DELAY ROUTINES
    22.           ENDC
    23.    
    24.      
    25.     #DEFINE BANK0    BCF   STATUS,5
    26.     #DEFINE BANK1    BSF   STATUS,5
    27.     #DEFINE SWITCH   GPIO,3        ; GPIO,3 PIN IS USED AS SWITCH.
    28.    
    29.              ORG        0X00
    30.              GOTO       INIT
    31. ;--------------------------------------------------------------------------
    32.  
    33. SWITCH_DE_BOUNCE_DLY      ; 40 MS DELAY
    34.        
    35.              MOVLW       0X3E    
    36.              MOVWF       D1    
    37.              MOVLW       0X20    
    38.              MOVWF       D2
    39.  
    40. DELAY_0 DECFSZ       D1,F
    41.             GOTO          $+2  
    42.             DECFSZ       D2,F
    43.             GOTO          DELAY_0        
    44.             GOTO          $+1
    45.             NOP
    46.             RETURN
    47. ;------------------------------------------------------------------------
    48.  
    49. DELAY_500_MS                ; 500MS DELAY
    50.             MOVLW   0X03
    51.             MOVWF   D3        
    52.             MOVLW   0X18
    53.             MOVWF   D4
    54.             MOVLW   0X02
    55.             MOVWF   D5
    56.  
    57. DELAY_NEW
    58.            DECFSZ    D3,F
    59.            GOTO       $+2
    60.            DECFSZ    D4,F
    61.            GOTO       $+2
    62.            DECFSZ    D5,F
    63.            GOTO       DELAY_NEW    
    64.            GOTO       $+1
    65.            RETURN
    66.  
    67. ;--------------------------------------------------------------------------
    68.  
    69. INIT      BANK1
    70.            CALL          0X3FF ; FIRST TIME USE INTERNAL OSC
    71.            MOVWF      OSCCAL
    72.            CLRF          ANSEL          ; PINS ALL DIGITAL
    73.            MOVLW      B'001000'      ; GP3 PIN (MASTER CLR) AS INPUT
    74.            MOVWF      TRISIO
    75.            BANK0
    76.            MOVLW      0X07
    77.            MOVWF      CMCON          ; MAKING COMPARATOR INACTIVE
    78.            CLRF          GPIO
    79.          
    80. MAIN    BTFSC      SWITCH
    81.            GOTO        MAIN
    82.  
    83. AGAIN   CALL         SWITCH_DE_BOUNCE_DLY
    84.            CLRF         GPIO
    85.  
    86.            MOVLW      B'100000'     ; 1000
    87.            MOVWF      GPIO
    88.            CALL          DELAY_500_MS
    89.  
    90.            MOVLW      B'000100'     ; 0100
    91.            MOVWF      GPIO
    92.            CALL          DELAY_500_MS
    93.  
    94.            MOVLW      B'000010'     ; 0010
    95.            MOVWF      GPIO
    96.            CALL          DELAY_500_MS
    97.  
    98.            MOVLW      B'000001'     ; 0001
    99.            MOVWF      GPIO
    100.            CALL          DELAY_500_MS
    101.            
    102.            MOVLW      B'100111'     ; 1111
    103.            MOVWF      GPIO
    104.            CALL          DELAY_500_MS
    105.  
    106.            MOVLW      B'100000'     ; 1000
    107.            MOVWF      GPIO
    108.            CALL          DELAY_500_MS
    109.            
    110.            MOVLW      B'000100'     ; 0100
    111.            MOVWF      GPIO
    112.            CALL          DELAY_500_MS
    113.  
    114.            MOVLW      B'000010'     ; 0010
    115.            MOVWF      GPIO
    116.            CALL          DELAY_500_MS
    117.            
    118.            MOVLW      B'100111'     ; 1111
    119.            MOVWF      GPIO
    120.            CALL          DELAY_500_MS
    121.          
    122.            MOVLW      B'100000'     ; 1000
    123.            MOVWF      GPIO
    124.            CALL          DELAY_500_MS
    125.            
    126.            MOVLW      B'000100'     ; 0100
    127.            MOVWF      GPIO
    128.            CALL          DELAY_500_MS
    129.            
    130.            MOVLW      B'100111'     ; 1111
    131.            MOVWF      GPIO
    132.            CALL          DELAY_500_MS
    133.  
    134.            MOVLW      B'100000'     ; 1000
    135.            MOVWF      GPIO
    136.            CALL          DELAY_500_MS
    137.  
    138.            MOVLW      B'100111'     ; 1111
    139.            MOVWF      GPIO
    140.            CALL          DELAY_500_MS
    141.  
    142. KHELA   BTFSC       SWITCH
    143.            GOTO        KHELA
    144.            GOTO        AGAIN
    145.  
    146.            END
    147.            
    148.            
    149. ;--------------------------------------------------------------------------------                  
    150.          
    151. ;NOTE:
    152.  
    153. FIRST TIME USE-  CALL    0X3FF
    154.                          MOVWF   OSCCAL
    155.  
    156. BEFORE ERASE, READ THE VALUE WRITTEN IN THE PIC INSIDE. KEEP IT RECORDED.
    157. THEN ERASE BEFORE SUBSEQUENT USE AND WRITE THE FOL:
    158.  
    159.                        MOVLW   0X0002 ; SUPPOSE VALUE WRITTEN IS 0002
    160.                        MOVWF   OSCCAL
    161. ;-------------------------------------------------------------------------
     
    • ND.JPG
      ND.JPG
      File size:
      11.9 KB
      Views:
      56
    Last edited: Sep 29, 2009
  6. booji

    Thread Starter New Member

    Sep 27, 2009
    3
    0
    Many thanks Tahmid! I will try the code tomorrow & let you know the results.
     
Loading...