Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 40

LINE FOLLOWING ROBOT

 KENALPASTI OBJEKTIF BINAAN ROBOT


 KENALPASTI INPUT/OUTPUT
 PENGHASILAN LITAR ANTARAMUKA
(INTERFACE)
 MEREKABENTUK ALGORITMA PROGRAM
(MENGGUNAKAN CARTA ALIRAN )
 PENGUJIAN ALGORITMA
 PENGUBAHAN PROGRAM/ LITAR
(JIKA DIPERLUKAN)
 DEFINASI ROBOT:
Robot adalah mesin yang direkabentuk untuk melakukan/
melaksanakan suatu kerja atau lebih berulang kali dengan
kelajuan yang tetap dan mempunyai ketepatan yang tinggi.
 Kebiasaan mikropengawal (mc) digunakan untuk pengawal
robot berskala mikro. Contohnya robot soccer dan line
following robot.
 Mikropengawal digunakan kerana ia : 1. murah
2. bersaiz kecil
 Apakah yang perlu saya lakukan untuk
memulakan pembinaan robot?
 Saya tiada pengetahuan asas
pengaturcaraan, adakah mampu saya
membinanya?
 Saya tiada pengetahuan dalam bidang
elektronik, bagaimana saya mahu membina
litar robot saya sendiri?
Otak

Denyutan
jantung
Sistem
Perkumuhan

Deria

Pelaksana Arahan
Central Procession Unit (CPU)

Input Pin Ports Crystal Clock

Current Flows
5V DC Supply

Ground Potential
Output Pin Ports
Otak Central Procession Unit (CPU)

Pengaliran Darah Current Flows

Deria Rasa Input Pin Ports

Makanan 5V DC Supply

Degupan Jantung Crystal Clock

Sistem Perkumuhan Ground Potential

Pelaksana Arahan Output Pin Ports


Vdd Supply

Resistor
LED

Push Button
Ground
Vdd Supply

Resistor
LED

Push Button
Ground

State Of The Push Button State of LED


Released OFF
Pressed ON
Istilah isyarat dalam Sistem Digit

ON HIGH YES 1 5V Vdd


OFF LOW NO 0 0V Vss
Vdd

Vdd
Resistor
LED

Push Resistor
Button Vdd
Vss
Push
LED
Tanpa mikro pengawal Button

Dengan mikropengawal
Input Output Pin
A2 A1

A3 A0
PORTA
A4 A7

A5 A6

Vss Vdd

B0 B7

B1 B6
PORTB
B2 B5

B3 B4
Sambungan Input Output Kepada Mikro pengawal

A2 A1

A3 A0
Vdd
A4 A7

Resistor A5 A6

Push
Vss Vdd
Button

B0 B7

B1 B6

B5 Resistor
B2

B3 B4

Green LED
ISYARAT DARI MIKRO PENGAWAL KEPADA LITAR
ELEKTRONIK

0V - 5V

B5 Resistor
Vdd
0

Resistor A5
1
Test LED
Push Button
Digital Logic Level
0V – 5V
2V-5V ------- Logic 1
0V-0.8V -------- Logic 0
A0

A1
A3
A2

L293 Motor Driver L293 Motor Driver


Motor Left

Motor Right
 Ini antara soalan yang selalu bermain dibenak
fikiran anda:

Saya tidak pernah belajar asas pengaturcaraan,


bagaimana hendak memulakannya?

Saya tidak pandai pengaturcaraan ini.


 Cara mudah untuk memahami suatu
rangkaian program dengan menggunakan
bantuan gambarajah.
 Amat berguna untuk memahami
pengaturacaraan.
 Merupakan bahasa aras tinggi yang
digunakan untuk pengaturcaraan.
 Pengaturcaraan C memudahkan sesuatu
sruktur pengaturcaraan dilakukan.
Main Program

#include <pic.h> // to include the contents before compiling (pic168xa.h)


__CONFIG(0x3F32); // Configuration Bits

void main(void) // the main function where the program will start operating
{
// enter your code here
}
 Define IO pin as input or output
 Example

TRISB = 0x00000000; // all port C as output


TRISB = 0x00001111; // First 4 bits as input

// The rests as output


 A special function register ( in Data Memory)
 The content of this register corresponds to
the value of electrical signal at its IO pin

PORTB = 0b00000000; // clear the content


// to innitialize
while(expression)
{ // execute if the expression is true (1) }
Basic Program to Turn ON Output

#include <pic.h> // to include the contents before compiling (pic168xa.h)


__CONFIG(0x3F32); // Configuration Bits

void main(void) // the main function where the program will start operating
{
TRISB = 0b00000000;
PORTB= 0b00000000;
while(1) {
RB3=1; // Turn on the TestLED
}
}
 Turn on an LED and OFF in a never ending
loop
while(1){
RB3=1;
RB3=0;
}

Can we see the LED blinking?


 Set the value for crystal clock
 A pre written function provided by hitech
 Set the value for crystal clock:

#define _XTAL_FREQ 20000000

A constant used in _delay_ms() function


#include <pic.h>

__CONFIG(0x3F32);
#define _XTAL_FREQ 20000000

void main(void)
{
TRISB =0b00000000;
PORTB=0b00000000;
while(1) {
RB3=0;
__delay_ms(39);
RB3=1;
__delay_ms(39);
}
}
 Connect a push button
 Define TRISB
 Draw Schematic

0 B1
while(RB1==1)
{
RB3=1;
}
do {
//code to run here
}
while (expression);
for (variable = initial value; expression;
variable = variable + value)
{
//code to run here while expression is true
}
while (expression)
for (variable = initial value; expression;
variable = variable + value)
{
//code to run here while expression is true
}
while (expression)
for (x=1; x<9; x= x+1)
{ RC3 =1}
if ( expression)
{
//code to run here while expression is true
}
if ( RB2==1)
{
//code to run here while expression is true
}
 Relational Operators
> Greater than
>= Greater than or Equal to
< Less than
<= Less than or Equal to
== Equal to
!= Not Equal to
 Logical Operations
& AND
| OR
^ XOR
~ 1’s complement
>> Right Shift
<< Left Shift
Challenge your self
1. Write a program that will make your
robot to move from point A to point B
with the fastest time possible.

2. Start with turning on the Green LED


and finish by turning on the buzzer.

You might also like