Jump to content
43oh

Laser Security V2 Msp430


Recommended Posts

Hey All,

Nate here. I'm currently a junior in EE and decided to use the msp430 in my Design 1 project(not senior design).

Built a PCB and finalized most of the design.

-Some basic features : LCD 16x2

-120 db alarm (freaking loud)

-1 5mw legal red laser

-1 red led recieving diode

-2 push buttons to enter in a code on the lcd screen

Here some pics: (will upload a video of the operation when I get some time)

 

 

14624986.png

 

444ma.png

 

74510499.png

 

1222d.png

 

Here is the schematic: (to big for site)

http://img254.imageshack.us/img254/9838/lasersspdf.png

 

and source code ( still in beta... needs abit of work as you tell)

 

main.c

// Laser Security System: 
// Code By Natahn Zimmerman
// 11/9/11

/////////////Includes///////////////////

#include "msp430g2231.h"
#include "lcd.h"

/////////////LCD Defines////////////////

#define DATAPIN BIT6
#define CLOCKPIN BIT5
#define ENABLEPIN BIT4

//////////Other Micro Defines///////////

#define 	GLED		BIT6 // Green LED saying that SS is good and active
#define		RLED		BIT7 // Red LED saying that SS has been breached and alarm is high
#define		ALARM		BIT7 // Also attached to RLED. 
#define		TXD			BIT0 // Serial Output
#define		RXD			BIT1 // Serial Input
#define		SW1			BIT2 // Disable SS
#define		SW2			BIT3 // Disable SS

//////////////Variables/////////////////

volatile unsigned int i=1; // Variable for TXD Funciton. If this value goes above a certain point, security is breached.
volatile unsigned int j=0; // Low State Check variable. This variable should increment to a certain point, if not, security is breached. 
volatile unsigned int t=0; // For loop variable for j. 

volatile unsigned int ticks=0; // Variable for Timer function. After this gets to a certain point alarm sounds. 

volatile unsigned int password=0; // value for number being keyed in on keypad. 
volatile unsigned int a = 0; 	// Password compare value
volatile unsigned int c = 0;	// Increment based upon password being correct. 

volatile unsigned int b = (0x80 | 0x40 | 0xA); // HD44780 Cursor location. 

char ptext[2]; // Password Char array. Bit 1 = password #, Bit 2 = null.  

//////////////PROTOS////////////////////

void TXD_RXD(void); // Prototype TXD Function
void dis_alarm(void);

//////////////Main//////////////////////

void main(void)
{
_delay_cycles(20000); // debug delay
  	WDTCTL = WDTPW + WDTHOLD; // turn off watchdog so micro does not reset

  _delay_cycles(100000); // debug delay

  P1OUT &= ~(CLOCKPIN + DATAPIN + RLED); //Set these pins low (ensures low when defined as output)
  P1OUT |= ENABLEPIN; // Set enable pin high. (ensures high when defined as output)
  P1DIR |= ENABLEPIN + CLOCKPIN + DATAPIN +RLED; // Define as outputs
  P1DIR &= ~(SW2 + SW1); // Define as perm inputs 


  	P1IE |= (SW1); // P1.2 interrupt enabled
P1IFG &= ~(SW1); // P1.2 IFG cleared
P1IE |= (SW2); // P1.3 interrupt enabled
P1IFG &= ~(SW2); // P1.3 IFG cleared


__enable_interrupt(); // enable all interrupts

  	P2SEL = 0x00;  // Set functionality of Port 2 to GPIO
  	P2DIR |= GLED;  // Set Green LED, AKA P2.6 AKA XIN to a output. 
  	P2OUT = 0;		// Set all outputs on port 2 to 0. AKA GLED. 

P1DIR |= ( RLED + TXD); // All outputs except DIS_ALARM and RXD
P1OUT &= ~(RLED +TXD); // All bits set high initally, need to set all bits low. 
P2OUT |= GLED; // Turns Green LED ON


  		initDisplay(); // Turn on display. 
	clearDisplay(); // Clear Display

     	Print_Screen("Zalous Laser");
    	second_line();
    	Print_Screen("Security System");
    	 _delay_cycles(5000000);
    	clearDisplay();
     	Print_Screen("Laser System");
    	second_line();
    	Print_Screen("Now Activated"); 
    	_delay_cycles(20000);

    	TXD_RXD(); // Should always stay in this state unless TXD != RXD. In which case the following happens:  	

	P2OUT &= ~GLED; // Green LED Turns off
	clearDisplay(); // Clear display for new text
     	Print_Screen("Security System");
    	second_line();
    	Print_Screen("Breached!       ");

	while(1)
	{	
	P2OUT ^= GLED;		// Blink Green LED		
	CCTL0 = CCIE;       // CCR0 interrupt enabled ( TIMER 1)
	CCR0 = 50000;		// Set Timer Value
	TACTL = TASSEL_2 + MC_1;	// Initialize Timer
	_delay_cycles(5000000);		//Pause before enter password screen. 
	clearDisplay();
     	Print_Screen("Please Enter");
    	second_line();
    	Print_Screen("Password: ");
		while(1)
		{
			if(ticks>500) // Ticks is a Timer Variable. User has 30 seconds to enter password before alarm sounds.  
			{
				while(1)
				{
				P1OUT ^= RLED;	//Pulse alarm. 
				_delay_cycles(500000);	
				}	
			} 
		}

	}    	

} // End main 




void TXD_RXD(void)
{

while(i < 10)
{

P1OUT |= TXD;
__delay_cycles(5);
if((RXD & P1IN)==0)
{ 
	i++;
}
P1OUT &= ~TXD;
__delay_cycles(20);

for(t=0;t<10;t++)
{
if((RXD & P1IN)==0)
{
	j++;
}	
}
if(j>5)
{
j=0;	
}	
else
{
i++;	
}	
__delay_cycles(20);	

} // End While
} // End Function 

void dis_alarm(void)
{

P1OUT &= ~TXD;	
for(i=0;i<10;i++)
{
_delay_cycles(300000);
P2OUT ^= GLED;
}

WDTCTL = WDT_MRST_32 + ~WDTHOLD;    
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{	
_delay_cycles(10);
if(((SW1 & P1IN)) == 0)
{
password++;
ptext[0] = password + '0';
ptext[1] = 0;
_delay_cycles(2000);
sendInstruction(b+a);
_delay_cycles(2000);
Print_Screen(ptext);
_delay_cycles(2000);
P2OUT ^= GLED;
}

	if(((SW2 & P1IN)) == 0)
{
a++;
_delay_cycles(2000);
sendInstruction(b+a);
_delay_cycles(2000);
P2OUT ^= GLED;
Print_Screen("_");	

if(a==1)
{
	if(password==3)
	{
	c++;	
	}	
}
	if(a==2)
{
	if(password==8)
	{
	c++;	
	}	
}
	if(a==3)
{
	if(password==9)
	{
	c++;	
	}	
}	
	if(a==4)
{
	if(password==1)
	{
	c++;	
	}	
}	

	if(a==4)
{
	if(password==2)
	{
	c++;
	c++;	
	}	
}	

if(c==4)
{	CCTL0 &= ~CCIE;
	_delay_cycles(20000);
	__disable_interrupt();
	_delay_cycles(120000);
	WDTCTL = WDT_MRST_32 + ~WDTHOLD;
	_delay_cycles(120000);
}

if(c==5) // debug feature. laser = always on. useful for 
{	
	P1OUT = TXD;
} // end 

if(a==4)
{
sendInstruction(b+a);
Print_Screen(" ");

a=0;
c=0;
sendInstruction(b+a);
Print_Screen("_");		
} // End If a == 4

password=0;

}

_delay_cycles(200000);
P1IFG &= ~SW1; // P1.2 IFG cleared	
P1IFG &= ~SW2; // P1.3 IFG cleared


} // End ISR


#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
 P2OUT ^= GLED;             // Toggle P1.0      
 ticks++; 
}

 

and lcd.h (many thanks to RobG for his LCD code. Modified it abit and it works incredibly well! )

 

#ifndef LCD_H_
#define LCD_H_

#define sendData(data) send(data, 1)
#define sendInstruction(data) send(data, 0)
#define initDisplay() sendInstruction(0x3C); sendInstruction(0x0C); clearDisplay(); sendInstruction(0x06)
#define clearDisplay() sendInstruction(0x01); _delay_cycles(2000)
#define second_line() sendInstruction((0x80 | 0x40)); _delay_cycles(2000)
#define DATAPIN BIT6
#define CLOCKPIN BIT5
#define ENABLEPIN BIT4


void send(char data, char registerSelect);
void sendDataArray(char data[], char length);
void Print_Screen(char *texts);

char charIndex = 0;
char bitCounter = 0;

void sendDataArray(char data[], char length) {
  charIndex = 0;
    while(charIndex < length) {
       sendData(data[charIndex]);
       charIndex++;
    }
}

void send(char data, char registerSelect) {
  bitCounter = 0;
  while(bitCounter < 8) {
       (data & BIT7) ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
       data <<= 1;
       P1OUT |= CLOCKPIN;
       P1OUT &= ~CLOCKPIN;
       bitCounter++;
    }
    registerSelect ? (P1OUT |= DATAPIN) : (P1OUT &= ~DATAPIN);
    P1OUT &= ~ENABLEPIN;
    P1OUT |= ENABLEPIN;
}


void Print_Screen(char *texts)
{
volatile int i=0;	
char *h;
h=texts;
for(i=0;i<16;i++)
{
if(h[i]==0)
{
break;	
}
}
sendDataArray(h, i);	
}

#endif /*LCD_H_*/

post-4818-135135521785_thumb.png

Link to post
Share on other sites
Very cool project! Will you have any pcb's for sale? I've had this massive 5W laser kicking around just begging for something to do. Maybe setup some mirrors and make a perimeter alarm around my property?

 

Hey, glad you like it! A 5W laser would be pretty stinkin sweet! However, not sure a 5W laser would work so well on a LED. It would probably burn it up. Also, with mirrors, the issue is the laser spread becomes to big over long distance for my laser input... unless you have a 5W laser with no divergence which would be quite impressive. Sadly my circuit for the LED receiver requires a very precise aim since i'm using the LED as a generator. A far better more generic use circuit would be this for the laser input.

 

laserinput.png

 

Wasn't thinking to much when I made my laser input so its not quite as a generic use as it could be. It works, but only for a strict wavelength and focus. If I make another rev of the design i'll probably use the above instead. If your still interested in the pcb your welcome to PM me regarding it.

 

Nice one, Nate. What did you do your schematics in?

 

Altium Designer. By far my favorite.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...