 |

|
Elektronika.lt portalo forumas
Jūs esate neprisijungęs lankytojas. Norint dalyvauti diskusijose, būtina užsiregistruoti ir prisijungti prie forumo.
Prisijungę galėsite kurti naujas temas, atsakyti į kitų užduotus klausimus, balsuoti forumo apklausose.
Administracija pasilieka teisę pašalinti pasisakymus bei dalyvius,
kurie nesilaiko forumo taisyklių.
Pastebėjus nusižengimus, prašome pranešti.
Dabar yra 2025 02 22, 21:52. Visos datos yra GMT + 2 valandos.
|
|
|
 |
Forumas » Mikrovaldikliai » linija sekantis robotas su atmega8
|
Jūs negalite rašyti naujų pranešimų į šį forumą Jūs negalite atsakinėti į pranešimus šiame forume Jūs negalite redaguoti savo pranešimų šiame forume Jūs negalite ištrinti savo pranešimų šiame forume Jūs negalite dalyvauti apklausose šiame forume
|
|
|
 |
 |
 |
 |
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 15, 00:20 |
|
|
|
#include <iom8.h>
Sensors input port - PD
PD_0 --------> Left sensor
PD_1 --------> Middle sensor
PD_2 --------> Right sensor
Motors output port - PB
PB_0 --------> will drive the left motor in forward direction
PB_1 --------> will drive the left motor in reverse direction
PB_2 --------> will drive the right motor in forward direction
PB_3 --------> will drive the right motor in reverse direction
void Delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++); //Idle loop
}
void Forward()
{
PB_0==1;
PB_1==0;
PB_2==1;
PB_3==0;
}
void TurnLeft()
{
PB_0=0; /*Left motor is not running in any direction.*/
PB_1=0;
PB_2=1; /*Right motor is running in forward direction. bOt will eventually turn left*/
PB_3=0;
Delay(50); /* Wait for 50 ms*/
PB_0=0; /*Motors are not running*/
PB_1=0;
PB_2=0;
PB_3=0;
Delay(50); /*Delay of another 50 ms*/
}
void TurnRight()
{
PB_0=1; /*Left motor running in forward direction.*/
PB_1=0;
PB_2=0; /*Right motor is not running.*/
PB_3=0;
Delay(50); /*50ms time delay*/
PB_0=0; /*Motors not running in any direction*/
PB_1=0;
PB_2=0;
PB_3=0;
Delay(50); /*50ms time delay*/
}
void main()
{
PD_0=1; /*Left sensor input*/
PD_1=1; /*Middle sensor input*/
PD_2=1; /*Right sensor input*/
//main loop of the program
while(1)
{
if((PD_0==0)&&(PD_1==0)&&(PD_2==1))
TurnRight();
else if((PD_0==1)&&(PD_1==0)&&(PD_2==0))
TurnLeft();
else if((PD_0==0)&&(PD_1==1)&&(PD_2==0))
Forward();
}
} |
|
|
|
|
 |
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 15, 08:45 |
|
|
|
vyttasas rašo: |
gal pasakysit ka ne taip parašiau? |
Ka reiškia tavo ši funkcija?:
Kodas: |
void Forward()
{
PB_0==1;
PB_1==0;
PB_2==1;
PB_3==0;
}
|
|
|
|
|
|
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 15, 16:29 |
|
|
|
vyttasas rašo: |
tai ar atsiras žinančių? |
Atsiras nemazai, bet kai tu uzduodi tokius zalius klausimus, tai pries atsakant, noretusi, kad pats daugiau pasistudijuotum apie C kalba ir mikrovaldiklius.
PORTB = 0x00; nustato visus B porto bitus i nulius. |
|
|
|
|
 |
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 23, 18:41 |
|
|
|
tai vat su draugo pagalba irašėme i atmega8 koda bet kažkodėl roboto varikliai nesisuka. gal kodas blogas?
/*
int main( void )
{
return 0;
}
*/
#include <iom8.h>
void Delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++); //Idle loop
}
void Forward()
{
PORTB=5;
/*PB_0=1;
PB_1=0;
PB_2=1;
PB_3=0;*/
}
void TurnLeft()
{
PORTB=4;
// PB_0=0; /*Left motor is not running in any direction.*/
// PB_1=0;
// PB_2=1; /*Right motor is running in forward direction. bOt will eventually turn left*/
// PB_3=0;
Delay(50); /* Wait for 50 ms*/
PORTB=0;
//PB_0=0; /*Motors are not running*/
//PB_1=0;
//PB_2=0;
//PB_3=0;
Delay(50); /*Delay of another 50 ms*/
}
void TurnRight()
{
PORTB=1;
//PB_0=1; /*Left motor running in forward direction.*/
//PB_1=0;
//PB_2=0; /*Right motor is not running.*/
//PB_3=0;
Delay(50); /*50ms time delay*/
PORTB=0;
//PB_0=0; /*Motors not running in any direction*/
//PB_1=0;
//PB_2=0;
//PB_3=0;
Delay(50); /*50ms time delay*/
}
void main()
{
PORTD=255;
//PD_0=1; /*Left sensor input*/
//PD_1=1; /*Middle sensor input*/
//PD_2=1; /*Right sensor input*/
//main loop of the program
while(1)
{
if(PIND==4) //4
TurnRight();
else if(PIND==1)// 1
TurnLeft();
else if(PIND==2) //2
Forward();
/*if((PD_0==0)&&(PD_1==0)&&(PD_2==1))
TurnRight();
else if((PD_0==1)&&(PD_1==0)&&(PD_2==0))
TurnLeft();
else if((PD_0==0)&&(PD_1==1)&&(PD_2==0))
Forward();*/
}
} |
|
|
|
|
 |
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 23, 18:59 |
|
|
|
Tai jei neveikia, tai ir tiketina kad blogas tavo delay f-ja kazkokia isvis neaiski. Greiciausiai kompiliatorius ja isvis ismeta. |
|
|
|
|
 |
linija sekantis robotas su atmega8 |
Parašytas: 2012 01 23, 20:45 |
|
|
|
vyttasas rašo: |
deje neišmeta o normalei sukomplikuoja |
Tu visgi nelabai supratai ka norejau pasakyt ir juolabiau nezinai kaip kompiliatorius optimizuoja tavo koda ishmesdamas galimai nereikalinga shlamshta Pasigilink kaip veikia kompiliatorius. |
|
|
|
|
|
 |
Google paieška forume |
|
 |
Naujos temos forume |
|
 |
FS25 Tractors
Farming Simulator 25 Mods,
FS25 Maps,
FS25 Trucks |
 |
ETS2 Mods
ETS2 Trucks,
ETS2 Bus,
Euro Truck Simulator 2 Mods
|
 |
FS22 Tractors
Farming Simulator 22 Mods,
FS22 Maps,
FS25 Mods |
 |
VAT calculator
VAT number check,
What is VAT,
How much is VAT |
 |
LEGO
Mänguköök,
mudelautod,
nukuvanker |
 |
KCD2 Mods
Installing KCD 2 Mods,
KCD 2 Guides,
KCD 2 Cheats |
 |
FS25 Mods
FS25 Harvesters,
FS25 Tractors Mods,
FS25 Maps Mods |
 |
Dantų protezavimas
All on 4 implantai,
Endodontija mikroskopu,
Dantų implantacija |
 |
FS25 Mods
FS25 Maps,
FS25 Cheats,
FS25 Install Mods |
 |
GTA 6 Wiki
GTA 6 Map,
GTA 6 Characters,
GTA 6 News |
 |
FS25 Mods
Farming Simulator 25 Mods,
FS25 Maps |
 |
ATS Trailers
American Truck Simulator Mods,
ATS Trucks,
ATS Maps |
|

|
 |