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)
    so can u help me with any material or code of making interfaces
     
  2. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Hmmm, do you mean help or do it for you :p
     
  3. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    i would be pleased if you guide me, i want to use visual studio.but im confused since for USART and transmission of data through rs232 i used assembly language, i wonder if visual studio would allow me to create interface using assembly language. but if the interface is made by C or C++ would they be able to match with the code of turning motor because i have written it using assembly language. could u please make an interface for me then i would try to make it to communicate with rs232 then if i fail to make them communicate then i would be happy if u do it for me
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec

    Can you download C++ (2008) It's free from microsoft, I could write you up some code, or the whole program I guess if I find the time.
     
  6. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    yes i have downloaded it
     
  7. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Have you played around with it yet?
     
  8. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    iam in a place where internet is a problem i hardly access it and the bandwith is very small .i did not know that i have to be online when installing it. im trying my best to have it installed. but i have also got NetBeans IDE 6.7.1 installed in my computer and by tomorow i would know how it works. but i promise i would ask for visual c++ 2008 somewhere if i have a problem of installing it online.
     
  9. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Where are you from anyways?
     
  10. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    Im from Southern Africa in Lesotho
     
  11. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    i have successfuly installed c++ 2008, like i promised. i have made an interface using JFrameBuilder(JBF_331). but it support java only and the code looks like this:
    Code (text):

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /**
     * Summary description for turn
     *
     */
    public class turn extends JFrame
    {
        // Variables declaration
        private JButton jButton1;
        private JButton jButton2;
        private JPanel contentPane;
        // End of variables declaration


        public turn()
        {
            super();
            initializeComponent();
            //
            // TODO: Add any constructor code after initializeComponent call
            //

            this.setVisible(true);
        }

       
        private void initializeComponent()
        {
            jButton1 = new JButton();
            jButton2 = new JButton();
            contentPane = (JPanel)this.getContentPane();

            //
            // jButton1
            //
            jButton1.setText("clockwise");
            jButton1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    jButton1_actionPerformed(e);
                }

            });
            //
            // jButton2
            //
            jButton2.setText("anticlockwise");
            jButton2.setMaximumSize(new Dimension(151, 25));
            jButton2.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e)
                {
                    jButton2_actionPerformed(e);
                }

            });
            //
            // contentPane
            //
            contentPane.setLayout(null);
            addComponent(contentPane, jButton1, 26,32,83,28);
            addComponent(contentPane, jButton2, 194,38,108,28);
            //
            // turn
            //
            this.setTitle("turn - extends JFrame");
            this.setLocation(new Point(76, 59));
            this.setSize(new Dimension(390, 300));
        }

        /** Add Component Without a Layout Manager (Absolute Positioning) */
        private void addComponent(Container container,Component c,int x,int y,int width,int height)
        {
            c.setBounds(x,y,width,height);
            container.add(c);
        }

        //
        // TODO: Add any appropriate code in the following Event Handling Methods
        //
        private void jButton1_actionPerformed(ActionEvent e)
        {
            System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
            // TODO: Add any handling code here

        }

        private void jButton2_actionPerformed(ActionEvent e)
        {
            System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");
            // TODO: Add any handling code here

        }

        ;
            }
            new turn();
        }


    }
     
    i do not know how to write a code that can transmit data through rs232 using java language, im familiar with assembly language. the above code, i did not write it but i can see that i have to write instructions that would transmit and receive data under these two classes
    Code (text):
     private void jButton1_actionPerformed(ActionEvent e)
        {
              }
           private void jButton2_actionPerformed(ActionEvent e)
        {
             }

     
     
  12. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
  13. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    thanks i will look at it. i have installed C++ 2008 i would be glad if u do that code for me,
     
  14. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    I'll post it tomorrow, getting late here
     
  15. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    Im just seggesting. What about if you write the code in such away that, if clicking the button clockwise on the interface then a letter C must be send through rs232 then on the receiving side on the code of turning motor, i will check the received bit and if it is C then i will call the Subroutine that turn the motor clockwise. The same thing aplies if clicking the button anticlockwise then a letter A must be sent and on the receiving side i will call subroutine anticlockwise that would rotate the motor anticlockwise directon
     
  16. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Here is your program and A video of it as promised!
    The GUI you can fix up yourself if need be.
    I hope you enjoy :D
    (Sorry I don't have any stepper motors around so I just used an LCD to prove the point)


    YouTube - C and A usart
     

    Attached Files:

    Last edited: Nov 12, 2009
  17. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    This is the asurt code for turning the motor, do u think it will work because i have not tested it, i have just built it on mplab and there were no errors. what i did is that i made a subroutine that read the input data from the rs232and if received data is c then i call clockwise subroutines and if it is A i call anticlockwise subroutines. can you correct it for me or modify it iam not sure if it will work because i think there are important instructions or subroutines i have not included.
    Code (text):
    ;Author : LEBOHANG MAPHOTHOANE
    ;PROGRAM FUNCTION:turning motor


        list        P=16F877a

        include    "P16F877a.inc"
                    __config 0x3D18
        ;errorlevel -302, -207;suppress message 302 from the list
     ;Declarations:

        CBLOCK 20h   ; Temporary storage                
                   
                     dc1      ; General purpose registers for delay
                     dc2      ;General purpose registers for storing received data
                   
                  ENDC



         
         
        org     0x0000
        goto Init  
     

    ;Subroutines:          
    Init
                  clrw                    ; Zero.
                  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.                                                        
                 

    ;*** UART Set Up ***

        MOVLW   0x19            ; 0x19 = 9600 BPS (0x0C = 19200 BPS)
        MOVWF   SPBRG           ; Baud Rate Generator Store Location
        BSF     TXSTA,BRGH  ; High Baud Rate Select bit
        BCF     STATUS,RP0  ; Bank 0
        BSF     RCSTA,SPEN  ; Serial Port Enable bit
        BSF     RCSTA,CREN  ; Continuous Receive Enable bit
       


    Main  
    ;*** Receive ***

    Receive:
        BTFSS   PIR1,RCIF   ; P1R1 is set when byte is recieved
        GOTO    Receive     ;
        MOVF    RCREG,W     ; Move received data into W      
            movwf   dc2           ; move data from the working register into general purpose register
            btfss   dc2,1          ;check if the  second bit is 1 and if it is 1 the data received is letter A(1010)
           goto   clockwise        ; if not the letter is C(1100)
        goto   anticockwise                

    clockwise
    ;1-----------------------
         
           movlw b'1000'
           movwf PORTB
           call wait  
           goto Main

    anticockwise

           movlw b'0100'
           movwf PORTB
           call wait
           goto Main

    wait      movlw   40   ; Outer loop iteration count
    d11       movwf   dc1        
              decfsz  dc1,F        
              goto    $-1
              return

     end
     
  18. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    Looks good so far, let me know if it works! Excited to see final product :D
     
  19. lebohangmaphothoane

    lebohangmaphothoane New Member

    Joined:
    Aug 20, 2009
    Messages:
    103
    Likes:
    0
    Location:
    Lesotho (Mountain Kingdom)
    i will tell you, i was busy writting exams, so i had to put it aside. thank you
     
  20. birdman0_o

    birdman0_o Active Member

    Joined:
    Feb 23, 2009
    Messages:
    1,370
    Likes:
    18
    Location:
    Montreal, Quebec
    I hope they went well.
     
  21. techies

    techies New Member

    Joined:
    Dec 3, 2009
    Messages:
    5
    Likes:
    0
    Hi leboh..may i know how did you create your light control sensor for MCU? i would like to build one for other controller.. mind to share out the circuit? thanks
     

Share This Page