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.

Light control system for smart home

Status
Not open for further replies.
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
 
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.
 
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:
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:
 private void jButton1_actionPerformed(ActionEvent e)
	{
          }
       private void jButton2_actionPerformed(ActionEvent e)
	{
         }
 
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
 
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
 

Attachments

  • UART Improved.zip
    303.1 KB · Views: 165
Last edited:
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:
;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
 
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top