Académique Documents
Professionnel Documents
Culture Documents
transmitter module.
CHAPTER 1
INTRODUCTION
started, and it has started when the transistor was discover and
which could give us much greater help to improve our life style.
gives the arm forces much safer way to hunt. Some manufacturer
2
1.2 STATEMENT OF THE PROBLEM:
1.3 OBJECTIVES:
communication.
side
something that is unusual which can give us more luxury and made
3
Microcontroller can be applied in a broader way, such as
for them to capture the enemy easily or even it can take away for
this stage.
4
(430-439), 433MGz for a nominal value, and thus, the design and
more than 100ft but it can do more than 100ft distance for an
receiver side only if the RS232 serial port is decoded this done
http://www.microsoft.com.
5
1.6 DEFFINATION OF TERMS:
6
converts it for local use Also see specific entries for
7
CHAPTER II
the device is small, and controller tells you that the device
built into, or embedded in, the devices they control. You can
CPU executes instructions that perform the basic logic, math, and
8
a microprocessor requires memory for storing data and programs,
The first single chip CPU was the Intel 4004, a 4-bit
but its instructions were 8 bits long. Program and Data memory
memory. There were also sixteen 4-bit (or eight 8-bit) general
purpose registers.
digit) as a 1960's era IBM 1620. The 4040 (1972) was an enhanced
the 4-bit TMS 1000, which was the first microprocessor to include
9
without multiple external support chips. It also featured an
While the 8008 had 14 bit PC and addressing, the 8080 had a 16
bit address bus and an 8 bit data bus. Internally it had seven 8
with the addressing space, and a signal pin that allowed the
Unlike the 8080 and its kind, the 6502 and 6800 had very
bus. Inside was one 8 bit data register, two 8 bit index
address 256 ($100 hex) to 511 ($1FF)). It used these index and
10
operations (it didn't have to fetch a second byte for the
address).
interpreter in 512 word ROM (yes, 512)) and 8-pin 256 byte serial
bit data and 16 bit addressing, and could execute all of the 8080
4, 8 and 16 bit operations and even block move and block I/O).
The register set was doubled, with two banks of data registers
also added two index registers (IX and IY) and 2 types of
11
relocatable vectored interrupts (direct or via the 8-bit I
register).
But the thing that really made the Z-80 popular in designs was
the memory interface - the CPU generated its own RAM refresh
Z8671 has Tiny Basic in ROM. The Super-8 is just that, a super
space, and can be accessed directly (in a 256 byte page via I/O
12
2.3 THE ZILOG MICROCONTROLLER
CPU FEATURES:
(CPU), meets the continuing demand for faster and more code-
to function as an
13
• Software stack allows much greater depth in subroutine calls
Register File
• Up to 10 MIPS operation
• C-Compiler friendly
one 4-bit port (Port H) for general purpose I/O (GPIO). Each pin
is individually programmable.
Flash Controller
14
UARTs
(I2C)
four-wire interface.
Timers
Compare, and PWM modes. Only 3 timers (Timers 0-2) are available
Interrupt Controller
15
I/O pins. The interrupts have 3 levels of programmable interrupt
priority.
Reset Controller
The Z8F640x family can be reset using the RESET pin, power-
On-Chip Debugger
DMA Controller
the channels are for register RAM to and from I/O operations. The
For more information regarding the eZ8 CPU, refer to the eZ8 CPU
16
throughout the ages. They are computer-controlled manipulators,
like arms and hands, which can weld or spray paint cars as they
explore the ocean floor and even perform tasks in the most
to the rest of the body; arms and hands to grasp and manoeuvre
first build the Space Station and then help maintain the Station
17
Just like humans have a brain that sends messages to the
(SSRMS), Canada's new robotic arm, will be able to lift and move
objects the size and mass of the Space Shuttle. The crew of STS-
These are located in key areas of the Space Station and on the
Vision System.
18
2.5 THE RS232 DATA
19
CHAPTER 3
METHODOLOGY
but it will make workable. The mechanical parts are one of the
desktop computer using c#.net and decoding the RS232 serial port.
transmitter side.
20
3.2 THEORETICAL STRUCTURE
21
3.3.1 At the transmitter side:
created and waiting for the command to transfer which was the
data was set and sent to RS232 serial communication port where
the 9 pins only pin 3 transmitter pin, pin 4 the data terminal
ground signal.
The hexadecimal data 0x54 and 0x55 is the clock address data of
22
combination data through using the 74LS374. Upon reception, the
order to work the receiver module more efficient, avoid the robot
thick wall.
The receiver side composes of, simple mobile robot toy, the
motor, steeper and servo motor which both controls the wireless
23
CHAPTER 4
avoid the extra current spikes which can actually destroy the
24
FIG. A.4 THE CIRCUIT DIAGRAM OF MICROCONTROLLER AND STEPPER
MOTOR.
25
FIG. A.5 3DIMENSIONAL VIEW OF MCU AND PCB LAYOUT
26
For H-bridge circuit of the
motors.
27
The h-bridge circuit layout of Fig.A.9 uses the L298 power
28
meter
Mobile toy ------------------- (1)(350.00)
C#.net (Csharp) Software Open source (free
to down load)
Desktop Computer (1)()
PCB and other 700.00
components
Total: 4,762.00
without computer
data code which uses to transmit data sometimes it will not fit
and B are co-related each other and for the program of appendix B
29
FIG. A.10 THE FINAL LOOK OF THE PROJECT
30
CHAPTER 5
5.1 RECOMENDATION
security.
31
5.2 CONCLUSION
to improve our life style. On the other hand, some focuses on the
warfare technology, which gives the arm forces much safer way to
32
software used to transmit signal is the C#.net. This software can
languages the C and C++ you can begin coding right away.
program.
33
BIBLIOGRAPHY
34
APPENDIX A
namespace WindowsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
35
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.LinkLabel linkLabel1;
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.button7 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.serialPort1 = new
System.IO.Ports.SerialPort(this.components);
this.serialPort2 = new
System.IO.Ports.SerialPort(this.components);
this.serialPort3 = new
System.IO.Ports.SerialPort(this.components);
this.serialPort4 = new
System.IO.Ports.SerialPort(this.components);
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer2 = new System.Windows.Forms.Timer(this.components);
this.timer3 = new System.Windows.Forms.Timer(this.components);
this.timer4 = new System.Windows.Forms.Timer(this.components);
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.timer5 = new System.Windows.Forms.Timer(this.components);
this.button6 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.imageList1 = new
System.Windows.Forms.ImageList(this.components);
linkLabel1 = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// linkLabel1
//
resources.ApplyResources(linkLabel1, "linkLabel1");
linkLabel1.LinkBehavior =
System.Windows.Forms.LinkBehavior.HoverUnderline;
linkLabel1.LinkColor = System.Drawing.Color.Lime;
linkLabel1.Name = "linkLabel1";
36
linkLabel1.TabStop = true;
//
// progressBar1
//
this.progressBar1.AccessibleRole =
System.Windows.Forms.AccessibleRole.None;
this.progressBar1.BackColor = System.Drawing.Color.Aqua;
this.progressBar1.ForeColor = System.Drawing.Color.Maroon;
resources.ApplyResources(this.progressBar1, "progressBar1");
this.progressBar1.MarqueeAnimationSpeed = 5;
this.progressBar1.Maximum = 0;
this.progressBar1.Name = "progressBar1";
this.progressBar1.Style =
System.Windows.Forms.ProgressBarStyle.Marquee;
//
// comboBox1
//
resources.ApplyResources(this.comboBox1, "comboBox1");
this.comboBox1.ForeColor = System.Drawing.Color.Black;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
resources.GetString("comboBox1.Items"),
resources.GetString("comboBox1.Items1"),
resources.GetString("comboBox1.Items2"),
resources.GetString("comboBox1.Items3")});
this.comboBox1.Name = "comboBox1";
this.comboBox1.SelectedIndexChanged += new
System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// checkBox1
//
resources.ApplyResources(this.checkBox1, "checkBox1");
this.checkBox1.Name = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new
System.EventHandler(this.open_com_CheckedChanged);
//
// button7
//
resources.ApplyResources(this.button7, "button7");
this.button7.ForeColor = System.Drawing.Color.Red;
this.button7.Name = "button7";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new
System.EventHandler(this.button7_Click);
//
// label1
//
resources.ApplyResources(this.label1, "label1");
this.label1.Name = "label1";
//
// serialPort1
37
//
this.serialPort1.BaudRate = 2400;
//
// serialPort2
//
this.serialPort2.BaudRate = 2400;
this.serialPort2.PortName = "COM2";
//
// serialPort3
//
this.serialPort3.BaudRate = 2400;
this.serialPort3.PortName = "COM3";
//
// serialPort4
//
this.serialPort4.BaudRate = 2400;
this.serialPort4.PortName = "COM4";
//
// timer1
//
this.timer1.Interval = 250;
this.timer1.Tag = "";
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// timer2
//
this.timer2.Interval = 3;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// timer3
//
this.timer3.Interval = 3;
this.timer3.Tick += new System.EventHandler(this.timer3_Tick);
//
// timer4
//
this.timer4.Interval = 3;
this.timer4.Tick += new System.EventHandler(this.timer4_Tick);
//
// textBox1
//
this.textBox1.BackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(255)))),
((int)(((byte)(255)))), ((int)(((byte)(192)))));
resources.ApplyResources(this.textBox1, "textBox1");
this.textBox1.ForeColor = System.Drawing.Color.LimeGreen;
this.textBox1.Name = "textBox1";
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.Color.CornflowerBlue;
resources.ApplyResources(this.textBox2, "textBox2");
38
this.textBox2.ForeColor = System.Drawing.Color.Yellow;
this.textBox2.Name = "textBox2";
this.textBox2.ReadOnly = true;
this.textBox2.TextChanged += new
System.EventHandler(this.textBox2_TextChanged);
//
// label3
//
resources.ApplyResources(this.label3, "label3");
this.label3.Name = "label3";
//
// label4
//
resources.ApplyResources(this.label4, "label4");
this.label4.Name = "label4";
//
// timer5
//
this.timer5.Interval = 50;
this.timer5.Tick += new System.EventHandler(this.timer5_Tick);
//
// button6
//
this.button6.ForeColor = System.Drawing.Color.Purple;
resources.ApplyResources(this.button6, "button6");
this.button6.Name = "button6";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new
System.EventHandler(this.button6_Click_1);
//
// button8
//
this.button8.ForeColor = System.Drawing.Color.Purple;
resources.ApplyResources(this.button8, "button8");
this.button8.Name = "button8";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new
System.EventHandler(this.button8_Click);
//
// button9
//
resources.ApplyResources(this.button9, "button9");
this.button9.ForeColor = System.Drawing.Color.Purple;
this.button9.Name = "button9";
this.button9.UseVisualStyleBackColor = true;
this.button9.Click += new
System.EventHandler(this.button9_Click);
//
// button10
//
this.button10.ForeColor = System.Drawing.Color.Purple;
resources.ApplyResources(this.button10, "button10");
39
this.button10.Name = "button10";
this.button10.UseVisualStyleBackColor = true;
this.button10.Click += new
System.EventHandler(this.button10_Click);
//
// textBox3
//
this.textBox3.BackColor = System.Drawing.Color.CornflowerBlue;
resources.ApplyResources(this.textBox3, "textBox3");
this.textBox3.ForeColor = System.Drawing.Color.Red;
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
//
// button5
//
resources.ApplyResources(this.button5, "button5");
this.button5.Name = "button5";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new
System.EventHandler(this.button5_Click);
//
// button4
//
resources.ApplyResources(this.button4, "button4");
this.button4.Name = "button4";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new
System.EventHandler(this.button4_Click);
//
// button1
//
resources.ApplyResources(this.button1, "button1");
this.button1.Name = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// button2
//
resources.ApplyResources(this.button2, "button2");
this.button2.Name = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new
System.EventHandler(this.button2_Click);
//
// button3
//
resources.ApplyResources(this.button3, "button3");
this.button3.Name = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new
System.EventHandler(this.button3_Click);
40
//
// imageList1
//
this.imageList1.ImageStream =
((System.Windows.Forms.ImageListStreamer)(resources.GetObject("im
ageList1.ImageStream")));
this.imageList1.TransparentColor =
System.Drawing.Color.Turquoise;
this.imageList1.Images.SetKeyName(0, "logo2.png");
//
// Form1
//
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(224)))),
((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.Controls.Add(this.textBox3);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button6);
this.Controls.Add(linkLabel1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button7);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Cursor = System.Windows.Forms.Cursors.SizeAll;
this.ForeColor = System.Drawing.Color.DarkBlue;
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
41
private System.Windows.Forms.Button button5;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Label label1;
private System.IO.Ports.SerialPort serialPort1;
private System.IO.Ports.SerialPort serialPort2;
private System.IO.Ports.SerialPort serialPort3;
private System.IO.Ports.SerialPort serialPort4;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer timer2;
private System.Windows.Forms.Timer timer3;
private System.Windows.Forms.Timer timer4;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Timer timer5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.ImageList imageList1;
}
}
EXECUTION CODE:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Timers;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button6_Click(object sender, EventArgs e)
{
new Form2().Show();
}
private void open_com_CheckedChanged(object sender, EventArgs e)
{
42
if (checkBox1.Checked == false)
{
textBox2.Text = null;
textBox2.Text = ("stop/ready");
textBox1.Text = "\n" + " serial port closed...";
checkBox1.Enabled = false;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
button10.Enabled = false;
progressBar1.Visible = false;
comboBox1.Enabled = true;
switch (comboBox1.Text)
{
case "COM1":
{
timer1.Stop();
serialPort1.Close();
comboBox1.Text = " ";
break;
}
case "COM2":
{
timer2.Stop();
serialPort2.Close();
comboBox1.Text = " ";
break;
}
case "COM3":
{
timer3.Stop();
serialPort3.Close();
comboBox1.Text = " ";
break;
}
case "COM4":
{
textBox2.Text = ("stop/ready");
timer4.Stop();
serialPort4.Close();
comboBox1.Text = " ";
break;
}
}
}
if (checkBox1.Checked == true)
{
43
textBox1.Text = ("\n" + " serial port open ready to send
data...");
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
checkBox1.Enabled = true;
comboBox1.Enabled = false;
button6.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
button10.Enabled = true;
progressBar1.Show();
textBox2.Text = null;
textBox2.Text = ("stop/ready");
switch (comboBox1.Text)
{
case "COM1":
{
textBox2.Text = null;
textBox2.Text = "stop/ready";
serialPort1.Open();
timer1.Start();
break;
}
case "COM2":
{
textBox2.Text = null;
textBox2.Text = "stop/ready";
serialPort2.Open();
timer2.Start();
break;
}
case "COM3":
{
textBox2.Text = null;
textBox2.Text = "stop/ready";
serialPort3.Open();
timer3.Start();
break;
}
case "COM4":
{
textBox2.Text = null;
textBox2.Text = "stop/ready";
serialPort4.Open();
timer4.Start();
break;
}
}
}
44
}
private void timer1_Tick(object sender, EventArgs e)
{
//sending data at
port1********************************************
textBox1.Text = ("\n" + "sending data in serial port1...");
if (textBox2.Text == "stop/ready")
{
button7.Enabled = true;
}
else
{
button7.Enabled = false;
}
if (textBox2.Text == "stop/ready")
{
//ready stop
serialPort1.Write(new Byte[] { 0x54, 0xAA, (0x54 + 0xAA) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "reverse")
{
//reverse
serialPort1.Write(new Byte[] { 0x54, 0xA8, (0x54 + 0xA8) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_left")
{
//GO_LEFT
serialPort1.Write(new Byte[] { 0x54, 0xA6, (0x54 + 0xA6) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_right")
{
//GO_RIGHT
serialPort1.Write(new Byte[] { 0x54, 0xA4, (0x54 + 0xA4) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "forward")
{
//forward
serialPort1.Write(new Byte[] { 0x54, 0xAB, (0x54 + 0xAB) & 0xFF
}, 0, 3);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
//sending data at
port2********************************************
textBox1.Text = ("\n" + "sending data in serial port2...");
if (textBox2.Text == "stop/ready")
{
45
button7.Enabled = true;
}
else
{
button7.Enabled = false;
}
if (textBox2.Text == "stop/ready")
{
//ready stop
serialPort2.Write(new Byte[] { 0x54, 0xAA, (0x54 + 0xAA) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "reverse")
{
//reverse
serialPort2.Write(new Byte[] { 0x54, 0xA8, (0x54 + 0xA8) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_left")
{
//GO_LEFT
serialPort2.Write(new Byte[] { 0x54, 0xA6, (0x54 + 0xA6) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_right")
{
//GO_RIGHT
serialPort2.Write(new Byte[] { 0x54, 0xA4, (0x54 + 0xA4) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "forward")
{
//forward
serialPort2.Write(new Byte[] { 0x54, 0xAB, (0x54 + 0xAB) & 0xFF
}, 0, 3);
}
}
private void timer3_Tick(object sender, EventArgs e)
{
//sending data at
port3*********************************************
textBox1.Text = ("\n" + "sending data in serial port3...");
if (textBox2.Text == "stop/ready")
{
button7.Enabled = true;
}
else
{
button7.Enabled = false;
}
if (textBox2.Text == "stop/ready")
46
{
//ready stop
serialPort3.Write(new Byte[] { 0x54, 0xAA, (0x54 + 0xAA) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "reverse")
{
//reverse
serialPort3.Write(new Byte[] { 0x54, 0xA8, (0x54 + 0xA8) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_left")
{
//GO_LEFT
serialPort3.Write(new Byte[] { 0x54, 0xA6, (0x54 + 0xA6) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "go_right")
{
//GO_RIGHT
serialPort3.Write(new Byte[] { 0x54, 0xA4, (0x54 + 0xA4) & 0xFF
}, 0, 3);
}
else if (textBox2.Text == "forward")
{
//forward
serialPort3.Write(new Byte[] { 0x54, 0xAB, (0x54 + 0xAB) & 0xFF
}, 0, 3);
}
}
private void timer4_Tick(object sender, EventArgs e)
{
//sending data at
port4**********************************************
if (textBox2.Text == "stop/ready")
{
button7.Enabled = true;
}
else
{
button7.Enabled = false;
}
textBox1.Text = ("\n" + "sending data in serial port4...");
switch (textBox2.Text)
{
case "stop/ready":
{
//ready stop
serialPort4.Write(new Byte[] { 0x54, 0xAA, (0x54 + 0xAA) & 0xFF
}, 0, 3);
break;
}
47
case "reverse":
{
//reverse
serialPort4.Write(new Byte[] { 0x54, 0xA9, (0x54 + 0xA8) & 0xFF
}, 0, 3);
break;
}
case "go_left":
{
//GO_LEFT
serialPort4.Write(new Byte[] { 0x54, 0xA7, (0x54 + 0xA6) & 0xFF
}, 0, 3);
break;
}
case "go_right":
{
//GO_RIGHT
serialPort4.Write(new Byte[] { 0x54, 0xA8, (0x54 + 0xA4) & 0xFF
}, 0, 3);
break;
}
case "forward":
{
//forward
serialPort4.Write(new Byte[] { 0x54, 0xAB, (0x54 + 0xAB) & 0xFF
}, 0, 3);
break;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
button10.Enabled = false;
checkBox1.Enabled = false;
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (comboBox1.Text == ("COM1"))
{
textBox1.Text = ("\n" + "sending data in serial port4...");
checkBox1.Enabled = true;
}
else if (comboBox1.Text == ("COM2"))
48
{
textBox1.Text = ("\n" + "ready to open com2...");
checkBox1.Enabled = true;
}
else if (comboBox1.Text == ("COM3"))
{
textBox1.Text = ("\n" + "ready to open com3...");
checkBox1.Enabled = true;
}
else if (comboBox1.Text == ("COM4"))
{
textBox1.Text = ("\n" + "ready to open com4...");
checkBox1.Enabled = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = null;
textBox2.Text = ("forward");
}
private void button2_Click(object sender, EventArgs e)
{
textBox2.Text = null;
textBox2.Text = ("go_right");
}
private void button3_Click(object sender, EventArgs e)
{
textBox2.Text = null;
textBox2.Text = ("go_left");
}
private void button4_Click(object sender, EventArgs e)
{
textBox2.Text = null;
textBox2.Text = ("reverse");
}
private void button5_Click(object sender, EventArgs e)
{
textBox2.Text = null;
textBox2.Text = ("stop/ready");
}
private void button7_Click(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "COM1":
{
serialPort1.Close();
timer1.Stop();
this.Dispose(true);
break;
}
case "COM2":
49
{
serialPort2.Close();
timer2.Stop();
this.Dispose(true);
break;
}
case "COM3":
{
serialPort3.Close();
timer3.Stop();
this.Dispose(true);
break;
}
case "COM4":
{
timer4.Stop();
serialPort4.Close();
this.Dispose(true);
break;
}
case "":
{
this.Dispose(true);
break;
}
}
Application.Exit();
}
void check4()
{
switch (textBox3.Text)
{
case "up":
{
serialPort4.Write(new Byte[] { 0x54, 0xD8, (0x54 + 0xD8) & 0xFF
}, 0, 3);
textBox3.Text = "up";
break;
}
case "down":
{
serialPort4.Write(new Byte[] { 0x54, 0xD6, (0x54 + 0xD6) & 0xFF
}, 0, 3);
textBox3.Text = "down";
break;
}
case "left":
{
serialPort4.Write(new Byte[] { 0x54, 0xD2, (0x54 + 0xD2) & 0xFF
}, 0, 3);
textBox3.Text = "left";
break;
50
}
case "right":
{
serialPort4.Write(new Byte[] { 0x54, 0xD4, (0x54 + 0xD4) & 0xFF
}, 0, 3);
textBox3.Text = "right";
break;
}
}
}
void check3()
{
switch (textBox3.Text)
{
case "up":
{
serialPort3.Write(new Byte[] { 0x54, 0xD8, (0x54 + 0xD8) & 0xFF
}, 0, 3);
textBox3.Text = "up";
break;
}
case "down":
{
serialPort3.Write(new Byte[] { 0x54, 0xD6, (0x54 + 0xD6) & 0xFF
}, 0, 3);
textBox3.Text = "down";
break;
}
case "left":
{
serialPort3.Write(new Byte[] { 0x54, 0xD2, (0x54 + 0xD2) & 0xFF
}, 0, 3);
textBox3.Text = "left";
break;
}
case "right":
{
serialPort3.Write(new Byte[] { 0x54, 0xD4, (0x54 + 0xD4) & 0xFF
}, 0, 3);
textBox3.Text = "right";
break;
}
}
}
void check2()
{
switch (textBox3.Text)
{
case "up":
{
serialPort2.Write(new Byte[] { 0x54, 0xD8, (0x54 + 0xD8) & 0xFF
}, 0, 3);
51
textBox3.Text = "up";
break;
}
case "down":
{
serialPort2.Write(new Byte[] { 0x54, 0xD6, (0x54 + 0xD6) & 0xFF
}, 0, 3);
textBox3.Text = "down";
break;
}
case "left":
{
serialPort2.Write(new Byte[] { 0x54, 0xD2, (0x54 + 0xD2) & 0xFF
}, 0, 3);
textBox3.Text = "left";
break;
}
case "right":
{
serialPort2.Write(new Byte[] { 0x54, 0xD4, (0x54 + 0xD4) & 0xFF
}, 0, 3);
textBox3.Text = "right";
break;
}
}
}
void check1()
{
switch (textBox3.Text)
{
case "up":
{
serialPort1.Write(new Byte[] { 0x54, 0xD8, (0x54 + 0xD8) & 0xFF
}, 0, 3);
textBox3.Text = "up";
break;
}
case "down":
{
serialPort1.Write(new Byte[] { 0x54, 0xD6, (0x54 + 0xD6) & 0xFF
}, 0, 3);
textBox3.Text = "down";
break;
}
case "left":
{
serialPort1.Write(new Byte[] { 0x54, 0xD2, (0x54 + 0xD2) & 0xFF
}, 0, 3);
textBox3.Text = "left";
break;
}
case "right":
52
{
serialPort1.Write(new Byte[] { 0x54, 0xD4, (0x54 + 0xD4) & 0xFF
}, 0, 3);
textBox3.Text = "right";
break;
}
}
}
private void timer5_Tick(object sender, EventArgs e)
{
switch (comboBox1.Text)
{
case "COM1":
{
timer1.Stop();
for (int t = 0; t < 10; t++)
{
check1();
}
textBox3.Text = null;
timer5.Stop();
timer1.Start();
break;
}
case "COM2":
{
timer2.Stop();
for (int t = 0; t < 10; t++)
{
check2();
}
textBox3.Text = null;
timer5.Stop();
timer2.Start();
break;
}
case "COM3":
{
timer3.Stop();
for (int t = 0; t < 10; t++)
{
check3();
}
textBox3.Text = null;
timer5.Stop();
timer3.Start();
break;
}
case "COM4":
{
timer4.Stop();
for (int t = 0; t < 10; t++)
53
{
check4();
}
timer5.Stop();
timer4.Start();
textBox3.Text = null;
break;
}
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "stop/ready")
{
checkBox1.Enabled = true;
}
else
{
checkBox1.Enabled = false;
}
}
private void button6_Click_1(object sender, EventArgs e)
{
//textBox3.Text = null;
textBox3.Text = "up";
timer5.Start();
}
private void button8_Click(object sender, EventArgs e)
{
//textBox3.Text = null;
textBox3.Text = "left";
timer5.Start();
}
private void button9_Click(object sender, EventArgs e)
{
//textBox3.Text = null;
textBox3.Text = "down";
timer5.Start();
}
private void button10_Click(object sender, EventArgs e)
{
//textBox3.Text = null;
textBox3.Text = "right";
timer5.Start();
}
}
}
54
APPENDIX (B)
#include <ez8.h>
55
PCOC = 0x00;
PCAF = 0x00 | 0x01; //for timer1
PCHDE = 0x00;
}
/////////////////////////////////////////////////////////////
void main(void)
{
int detect;
strd=80;
timer_01(80);
init_pin();
delay (0x00,0x00);
timer_01(0xA0);
while(1)
{
detect = check_pin();
switch (detect)
{
/////////////////////motor control///////////////////
case reverse:
{
rev();
break;
}
case stop_ready:
{
stop();
break;
}
case forward:
{
fwrd();
break;
}
case go_left:
{
left();
break;
}
case go_right:
{
right();
break;
}
////////////////////end motor control///////////////////
////////////////////camera control//////////////////////
case camera_up:
{
cam_up();
break;
}
56
case camera_down:
{
cam_down();
break;
}
case camera_left:
{
cam_left();
break;
}
case camera_right:
{
cam_right();
break;
}
////////////////end camera control//////////////////////////
}
}
}
/////////////////////////////////////////////////////////////
int check_pin()
{
int value;
switch (PBIN)
{
/////////////////////motor control////////////////////////
case 0xAB:
value = 0xAB;
break;
case 0xA9:
value = 0xA9;
break;
case 0xA7:
value = 0xA7;
break;
case 0xA8:
value = 0xA8;
break;
case 0xAA:
value = 0xAA;
break;
///////////////////////end motor control///////////////////
/*********************************************************/
//////////////////////camera control start////////////////
case 0xD2:
value = 0xD2;
break;
case 0xD4:
value = 0xD4;
break;
case 0xD6:
57
value = 0xD6;
break;
case 0xD8:
value = 0xD8;
break;
/////////////////////end camera control////////////////////
}
return value;
}
/**********************************************************/
//using the pin PORT D ******* D0, D1,--->RIGHT WHEEL CONTROL
// D4, D5,--->LEFT WHEEL CONTROL
void rev(void) ///******PDOUT = 00010001
{
delay(0x07,0xA0);wait();
PDOUT = 0x11;
delay(0x07,0xA0);wait();
PDOUT = 0x03;
}
void stop(void)///******PDOUT = 00000000
{
PDOUT = 0x00;
}
void fwrd(void)//******PDOUT = 00100010
{
delay(0x07,0xD0);wait();
PDOUT = 0x22;
delay(0x07,0xD0);wait();
PDOUT = 0x22;
}
void left(void)//********PDOUT = 00010010
{
stop();
PDOUT = 0x12;
delay(0x07,0xA0);wait();
PDOUT = 0x12;
stop();
}
void right(void)//********PDOUT = 00100001
{
stop();
PDOUT = 0x21;
delay(0x07,0xA0);wait();
PDOUT = 0x21;
stop();
}
/**********************************************************/
58
///////////camera control///////////////////////////
void cam_left(void)
{
delay(0x07,220);
PAOUT=0x10;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT<<=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT<<=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT<<=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
}
void cam_right(void)
{
delay(0x07,220);
PAOUT=0x80;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT>>=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT>>=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
PAOUT>>=1;
while (!(IRQ0 & 0x40));
IRQ0 &= ~0x40;
}
/////timer1/////////////////////////////////////
////2ms timer0****for servo motor////////////////
/////50% 0f PWM is ((0xA0)/2 or (160/2) base 10//
//dont pass timer = 0 else it goes top by diffualt
//<-------------------------------------------->//
void timer_01(int strd)
{
PAAF = 0x02;
T0CTL &= ~0x80;
T0CTL = (0x07 << 3) | 0x43;
T0H = 0x00;
T0L = 0x01;
T0RH = 0x7F>>8;
T0RL = 160&0xFF;
T0PWMH = 0x7F>>8;
T0PWML = strd&0xFF;
IRQ0ENH &= ~0x20;
IRQ0ENL &= ~0x20;
59
IRQ0 &= ~0x20;
T0CTL |= 0x80;
}
void cam_up(void)
{
if (strd<146)
timer_01(strd = strd+2);
else
strd=144;
while (!(IRQ0 & 0x20));
IRQ0 &= ~0x20;
}
void cam_down(void)
{
if (strd>20)
timer_01(strd = strd-2);
else
strd=22;
while (!(IRQ0 & 0x20));
IRQ0 &= ~0x20;
}
/***********************************************************/
//////////END OF THE PROGRAM/////////////////////////////////
60
APPENDIX D
61
TABLE 3 LIST OF RECEIVER COMPONENTS
62
TABLE 4 TRANSMITTER COMPONETS
63