1. 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.
    Dismiss Notice

Light control system for smart home

Discussion in 'Microcontrollers' started by lebohangmaphothoane, Sep 15, 2009.

  1. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    i have not implement the hardware so the system is not yet finished. i would help you after completing it
     
  2. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    birdman0 i hope you still remember the system. could you please write the assembly code following the flowchart. remember that closing or opening the blinds you should use the unipolar stepper motor. i have tried the code. could you please compare yours with mine or just correct my code.
    Code (text):
     ;PROGRAM FUNCTION:light control for smart home


        list        P=16F877a
        include    "P16F877a.inc"
                __config 0x3D18         ;sets the configuration settings (oscillator type etc.)



    ;Declarations:

           
    NumH    equ     20h
    NumL    equ     21h
    dc1   equ     22h
    NumH1   equ     23h
    NumL1   equ     24h
    PostX   equ     25h
    Mark240 equ     26h
    PostY   equ     27h


         
        org     0x0000
        goto Start 

    ;Program Start:

    Start
        call Init             ;sets the values of ADCON0 and ADCON1
                                           ;initialize porta

    Init
    ;--------------------------------------------------------------------------
               ; Initializing porta and portb
        BCF STATUS, RP0 ;
        BCF STATUS, RP1 ; Bank0
        CLRF PORTA      ; Initialize PORTA by
                ; clearing output
                           ; data latches
        BSF STATUS, RP0 ; Select Bank 1
        MOVLW 0x06      ; Configure all pinss
        MOVWF ADCON1    ; as digital inputs
        MOVLW 0xCF      ; Value used to
                         ; initialize data
                             ; direction
        MOVWF TRISA     ; Set RA<3:0> as inputs
                               ; RA<5:4> as outputs
                               ; TRISA<7:6>are always
                               ; read as '0'.
       

     ; Initializing portb
        clrw             ;zerp
        movwf   PORTB           ; Ensure PORTB is zero before we enable it.
        bsf     STATUS,RP0      ; Select Bank 1
        movlw   0xF0            ; Set port B bits 0-3 as outputs
        movwf   TRISB           ; Set TRISB register.                                                        
        bcf     STATUS,RP0      ; Select Bank 0        


        movlw   b'00000111' ;sets up timing register
           option


         ;Initializing ADC
        movlw   b'10010001';
        movwf   ADCON0 ;
        BANKSEL ADCON1
        movlw   b'10000101'
        movwf   ADCON1
        BANKSEL ADCON0
       
        return  
    ;--------------------------------------------------------------------------
       
    ;Subroutines:  
       
    motion  movlw   b'10010001';
            movwf   ADCON0 ;
            BANKSEL ADCON1
            movlw   b'10000101'
            movwf   ADCON1
            BANKSEL ADCON0



           bsf  ADCON0, GO_DONE     ;initiate conversion
           btfsc   ADCON0, GO_DONE
           goto    $-1          ;wait for ADC to finish
           movf    ADRESH,W
           andlw   0x03
           movwf   NumH1
           BANKSEL ADRESL
           movf    ADRESL,W
           BANKSEL  ADRESH
           movwf    NumL1           ;return result in NumL1 and NumH1  
       
          return
       
    ;------------------------------------------------------------------------
    Light_on
           bsf PORTA,4       ;turn on the LED
           goto Main

           return
    ;-------------------------------------------------------------------------
    _4hr_delay
            movlw   d'144000'  
            movwf   PostX       ;sets up variable postscaler           
            movlw   d'240'      ;sets up fixed marker
            movwf   Mark240     ;
    TimeLoop

            movfw   Mark240     ;waits for TMR0 to count up
            subwf   TMR0,w      ;240 times
            btfss   STATUS,Z    ;
            goto    TimeLoop    ;hasn't, so keeps looping

            movlw   d'240'      ;resets Mark240
            addwf   Mark240,f   ;

            decfsz  PostX,f     ;does this X times
            goto    TimeLoop    ;

            retlw   0       ;returns after required time
    ;-------------------------------------------------------------------------
    second_delay  
            movlw   d'144000'  
            movwf   PostY       ;sets up variable postscaler   
            movlw   d'240'      ;sets up fixed marker
            movwf   Mark240     ;

    Time
            movfw   Mark240     ;waits for TMR0 to count up
            subwf   TMR0,w      ;240 times
            btfss   STATUS,Z    ;
            goto    Time    ;hasn't, so keeps looping

            movlw   d'240'      ;resets Mark240
            addwf   Mark240,f   ;
            goto    motion
            goto    After_6hrrs
    dky
            decfsz  PostY,f     ;does this X times
            goto    Time    ;

            goto    Main
    ;---------------------------------------------------------------------------
    wait      movlw   5   ; Outer loop iteration count
    d11       movwf   dc1        

              decfsz  dc1,F        
              goto    $-1
              return
    ;---------------------------------------------------------------------------
    After_6hrrs
            btfss NumH1,1
            goto ledoff
            bsf PORTA,4
            goto dky
    ledoff  
            bcf PORTA,4
            goto dky    
         
    ;---------------------------------------------------------------------------

    closeblinds
           movlw b'0000'
           movwf PORTB
           call wait
           goto motion
           btfss  NumH1,1
           goto Light_on
           bsf PORTA,4
           goto _4hr_delay
           bcf PORTA,4
           goto motion
           
    After_6hrs
           btfss NumH1,1
           goto led_off
           bsf PORTA,4
           goto second_delay
           
    led_off
           bcf PORTA,4
           goto second_delay


    ;--------------------------------------------------------------------------
    openblinds
           movlw b'0001'
           movwf PORTB
           call wait

           movlw b'0100'
           movwf PORTB
           call wait
       
           movlw b'0010'
           movwf PORTB
           call wait
       
           movlw b'1000'
           movwf PORTB
           call wait
           
           return
    ;-----------------------------------------------------------------------------



    Main          
    ;------------------------------------------------------------------------------  

             ; Read_ADC
        bsf ADCON0, GO_DONE     ;initiate conversion
        btfsc   ADCON0, GO_DONE
        goto    $-1         ;wait for ADC to finish
        movf    ADRESH,W
        andlw   0x03
        movwf   NumH
        BANKSEL ADRESL
        movf    ADRESL,W
        BANKSEL ADRESH
        movwf   NumL            ;return result in NumL and NumH
    ;-------------------------------------------------------------------------------
       
     
        btfss NumH,1
        goto closeblinds
        goto openblinds
        bcf PORTA,4       ; turn 0ff the LED
       
        btfss NumH1,1
        goto led_on  
       
        goto Main
    led_on  
        bsf PORTA,4       ;turn on the LED
        goto motion
        btfss NumH1,1
        goto Main  
        bcf PORTA,4



           END
     
     

    Attached Files:

    • room.jpg
      room.jpg
      File size:
      35.7 KB
      Views:
      204
  3. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    I'll only find mistakes in your code, I do not have time to write all that code for you.
     

Share This Page