קוד שכתבתי - אשמח לדעה.

הפורום הראשי, אתר הרובוטיקה הישראלי

המנהלים: אסף פוניס, גיא יונה

קוד שכתבתי - אשמח לדעה.

הודעהעל ידי Ngel » א' פברואר 04, 2007 7:24 pm

צריך להשקיע גם בתוכניות שלמות יעילות, זה מפתח את צורת החשיבה לתכנות נכון.
למשל להלן תוכנה שלי שעושה דברים אחד אחרי השני שאני כתבתי לבד,
הוספתי הערות באנגלית כי הקומפיילר שלי הופך עברית אז אם אתם רואים שגיאות כתיב אתכם הסליחה :lol: .
המערך what2do שולט על פעולת הרובוט.
המערך howlong קובע את זמן הפעולה בשניות.
PCCAP1H שולט על מהירות המנוע הימני,
PCCAP2H שולט על מהירות המנוע השמאלי.

שימוש במעבד של ATMEL: at89c5131.
בP1 מחוברים המנועים (עם גשר או בלי איך שבא לכם):
P1_0 מחובר הכיוון של המנוע.
P1_1 מחובר הכיוון של המנוע השני.
P1_4 מחובר האפשר של המנוע
P1_5 מחובר האפשר של המנוע השני.
ב P3_2 מחובר לחצן או מה שבא לכם שיבדוק שהרובוט פגע בקיר.

לקח לי בערך חצי שעה לכתוב את התוכנית ואת הרובוט קצת יותר (לוקח לי הרבה זמן להשיג חלקים :( )

והקוד שלי:

קוד: בחר הכל
 #include <at89c5131.h>
 
    
    unsigned char POINTER;      //The Position Of the ToDo List
    unsigned char what2do[5];   //What to do
    unsigned char howlong[5];  //How Long to do it
    unsigned char PCCAP1H[5];   //Speed (PWM) Of motorA
    unsigned char PCCAP2H[5];   //Speed (PWM) Of motorB
    
    #define farward 0x3
    #define backward 0x0
    #define left 0x1
    #define right 0X2
    
    
   void external1 (void) interrupt 0{  //What To do While Interrupt
   
   //**************************************************************
   //                     Here We Write New Commands
   //                     Because That The Robot Has
   //                     Saw A Wall
   //**************************************************************
   
      TR0=0;                           //cancel timer0
      POINTER=1;                        //Set Pointer To Start
      
      TH0=0X84;                        //Restart the counter to start point
      TL0=0X80;                        //Restart the counter to start point
      
      what2do[POINTER]=backward;         //set motors to go backward
      howlong[POINTER]=0x01;            //For 1 sec
      PCCAP1H[POINTER]=210;            //PWM1 = 210
      PCCAP2H[POINTER]=210;            //PWM2 = 210
      
      POINTER++;                        //inc pointer to write the next command
      
      what2do[POINTER]=left;            //set motors to go left
      howlong[POINTER]=0x02;            //For 2 sec
      PCCAP1H[POINTER]=210;            //PWM1 = 210
      PCCAP2H[POINTER]=210;            //PWM2 = 210
      
      POINTER++;                        //inc pointer to write the next command
      
      what2do[POINTER]=farward;         //set motors to go farward
      howlong[POINTER]=0xff;;            //For endless time
      PCCAP1H[POINTER]=190;            //PWM1 = 190
      PCCAP2H[POINTER]=190;            //PWM2 = 190
      
      POINTER=1;                        //set pointer back to the start point
      
      TR0=1;                           //enable timer0
   return;}
 
    void Enable_Timer0(void){ //Enabled Timer0
    
   //**************************************************************
   //                     Here We Enable the timers
   //**************************************************************
   
      TMOD=0x01;      //mode1 - counters
      EA=1;            //Enable All
      ET0=1;         //Enable Timer0
      TH0=0X84;      //TimerO Start Point High
      TL0=0X80;      //TimerO Start Point LOW
      TR0=1;         //TIMER0 RUN
      EX0=1;         //External Interrupt0 enable
      return;} 

   void init_pwm(){
   //**************************************************************
   //                     Here We Enable the PWM
   //                     (pulse width modulation)
   //**************************************************************
      CCON= 0x40;
      CCAPM1=0x42;   //PWM1=1, ECOM1=1
      CCAPM2=0x42;   //PWM2=1, ECOM2=
   return;}
   
   void Timer (void) interrupt 1{ //Timer0 Function
   
   //**************************************************************
   //                     External interrupt0 code.
   //                     do what the arry "what2do"
   //                     tell us to do, for "howlong"
   //                              seconds
   //**************************************************************
   
        static unsigned char count=0;
      TR0=0;                           //Disable timer 0
      TH0=0X84;                        //reload timer0 high for 1 sec
      TL0=0X80;                        //reload timer0 low for 1 sec
      count++;
      if(count==0x1E){                   // if it count 0x1E times 0X8480 (for 1 sec delay) then
         if(howlong[POINTER]<0xff){    //if its not endelss then
            howlong[POINTER]--;}         //count -1 sec
         if(howlong[POINTER]<=0){      //if it finished to count seconds that we write in howlong[POINTER] then
            POINTER++;                  //INC the pointer
            CCAP1H=PCCAP1H[POINTER];   //reload PWM (control the motorA speed)
            CCAP2H=PCCAP2H[POINTER];   //reload PWM (control the motorB speed)
            }
         count=0;}                     //reCount
      //P2=howlong[POINTER];            //TEST POINT!
      TR0=1;                           //Enable Timer0
      return;}
 
    void MOTORS(unsigned char direc){
    
   //**************************************************************
   //                     Function that controll the motors
   //                                 left or right.
   //**************************************************************
       if((direc&0x01)==1){
         P1_0=1;}
       else if((direc&0x01)==0){
         P1_0=0;}
       if((direc&0x02)==2){
         P1_1=1;}
       else if((direc&0x02)==0){
         P1_1=0;}
       return;}
    
    void main(void){
    
   //**************************************************************
   //                     Function that controll the motors
   //                                 left or right.
   //**************************************************************
   
      Enable_Timer0();            //enable timer0
      init_pwm();                  //enable PWM to control motor speed
      POINTER=0;                  //set the pointer to the start
      what2do[POINTER]=farward;   //set command to go farward
      howlong[POINTER]=0xff;     //for enless time
      PCCAP1H[POINTER]=190;      //speed controller motorA
      PCCAP2H[POINTER]=190;      //speed controller motorB
      CCAP1H=PCCAP1H[POINTER];   //speed controller motorA
      CCAP2H=PCCAP2H[POINTER];   //speed controller motorB
      while(1){
         MOTORS(what2do[POINTER]);}   //Set the motor directions
   }


נורא נורא מקווה שאהבתם אותו ואשמח לתגובות (אני חדש פה :) )
אם תאהבו אותו או שיהיו תגובות או בקשות אשמח לכתוב קודים נוספים.

ד"א,
אחרי קימפול התוכנה תופסת 346 בתים, אם יש לכם עצה יעילה שתפחית את הקוד אז אחלה :)
Ngel
משתמש ותיק
משתמש ותיק
 
הודעות: 310
הצטרף: א' פברואר 04, 2007 6:47 pm

יפה...

הודעהעל ידי netanel241 » ב' אוקטובר 10, 2011 4:25 am

אני מאוד ישמח אם תביא לי קוד שרק יפעיל לי את המנוע...אני משתמש בPWM1 (לא משנה רוחב הפולסים העיקר שיפעילי לי את המנוע כי אני לא מצליח להפעיל את המנו עם הPWM )
תודה :)
netanel241
משתמש חדש
משתמש חדש
 
הודעות: 2
הצטרף: ב' אוקטובר 10, 2011 4:22 am

אם

הודעהעל ידי Ngel » ב' אוקטובר 10, 2011 11:12 pm

אם אתה לא מצליח להפעיל את המנוע אני ממליץ לך לבדוק לפני כן את האלקטרוניקה אח"כ את התוכנה.
Ngel
משתמש ותיק
משתמש ותיק
 
הודעות: 310
הצטרף: א' פברואר 04, 2007 6:47 pm

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ו' נובמבר 17, 2023 3:40 am

xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ש' דצמבר 02, 2023 2:34 am

audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatormagnetotelluricfieldmailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffusersemiasphalticfluxsemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchucktaskreasoningtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimatetemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting
xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ו' פברואר 02, 2024 7:53 am

http://audiobookkeeper.ruhttp://cottagenet.ruhttp://eyesvision.ruhttp://eyesvisions.comhttp://factoringfee.ruhttp://filmzones.ruhttp://gadwall.ruhttp://gaffertape.ruhttp://gageboard.ruhttp://gagrule.ruhttp://gallduct.ruhttp://galvanometric.ruhttp://gangforeman.ruhttp://gangwayplatform.ruhttp://garbagechute.ruhttp://gardeningleave.ruhttp://gascautery.ruhttp://gashbucket.ruhttp://gasreturn.ruhttp://gatedsweep.ruhttp://gaugemodel.ruhttp://gaussianfilter.ruhttp://gearpitchdiameter.ru
http://geartreating.ruhttp://generalizedanalysis.ruhttp://generalprovisions.ruhttp://geophysicalprobe.ruhttp://geriatricnurse.ruhttp://getintoaflap.ruhttp://getthebounce.ruhttp://habeascorpus.ruhttp://habituate.ruhttp://hackedbolt.ruhttp://hackworker.ruhttp://hadronicannihilation.ruhttp://haemagglutinin.ruhttp://hailsquall.ruhttp://hairysphere.ruhttp://halforderfringe.ruhttp://halfsiblings.ruhttp://hallofresidence.ruhttp://haltstate.ruhttp://handcoding.ruhttp://handportedhead.ruhttp://handradar.ruhttp://handsfreetelephone.ru
http://hangonpart.ruhttp://haphazardwinding.ruhttp://hardalloyteeth.ruhttp://hardasiron.ruhttp://hardenedconcrete.ruhttp://harmonicinteraction.ruhttp://hartlaubgoose.ruhttp://hatchholddown.ruhttp://haveafinetime.ruhttp://hazardousatmosphere.ruhttp://headregulator.ruhttp://heartofgold.ruhttp://heatageingresistance.ruhttp://heatinggas.ruhttp://heavydutymetalcutting.ruhttp://jacketedwall.ruhttp://japanesecedar.ruhttp://jibtypecrane.ruhttp://jobabandonment.ruhttp://jobstress.ruhttp://jogformation.ruhttp://jointcapsule.ruhttp://jointsealingmaterial.ru
http://journallubricator.ruhttp://juicecatcher.ruhttp://junctionofchannels.ruhttp://justiciablehomicide.ruhttp://juxtapositiontwin.ruhttp://kaposidisease.ruhttp://keepagoodoffing.ruhttp://keepsmthinhand.ruhttp://kentishglory.ruhttp://kerbweight.ruhttp://kerrrotation.ruhttp://keymanassurance.ruhttp://keyserum.ruhttp://kickplate.ruhttp://killthefattedcalf.ruhttp://kilowattsecond.ruhttp://kingweakfish.ruhttp://kinozones.ruhttp://kleinbottle.ruhttp://kneejoint.ruhttp://knifesethouse.ruhttp://knockonatom.ruhttp://knowledgestate.ru
http://kondoferromagnet.ruhttp://labeledgraph.ruhttp://laborracket.ruhttp://labourearnings.ruhttp://labourleasing.ruhttp://laburnumtree.ruhttp://lacingcourse.ruhttp://lacrimalpoint.ruhttp://lactogenicfactor.ruhttp://lacunarycoefficient.ruhttp://ladletreatediron.ruhttp://laggingload.ruhttp://laissezaller.ruhttp://lambdatransition.ruhttp://laminatedmaterial.ruhttp://lammasshoot.ruhttp://lamphouse.ruhttp://lancecorporal.ruhttp://lancingdie.ruhttp://landingdoor.ruhttp://landmarksensor.ruhttp://landreform.ruhttp://landuseratio.ru
http://languagelaboratory.ruhttp://largeheart.ruhttp://lasercalibration.ruhttp://laserlens.ruhttp://laserpulse.ruhttp://laterevent.ruhttp://latrinesergeant.ruhttp://layabout.ruhttp://leadcoating.ruhttp://leadingfirm.ruhttp://learningcurve.ruhttp://leaveword.ruhttp://machinesensible.ruhttp://magneticequator.ruhttp://magnetotelluricfield.ruhttp://mailinghouse.ruhttp://majorconcern.ruhttp://mammasdarling.ruhttp://managerialstaff.ruhttp://manipulatinghand.ruhttp://manualchoke.ruhttp://medinfobooks.ruhttp://mp3lists.ru
http://nameresolution.ruhttp://naphtheneseries.ruhttp://narrowmouthed.ruhttp://nationalcensus.ruhttp://naturalfunctor.ruhttp://navelseed.ruhttp://neatplaster.ruhttp://necroticcaries.ruhttp://negativefibration.ruhttp://neighbouringrights.ruhttp://objectmodule.ruhttp://observationballoon.ruhttp://obstructivepatent.ruhttp://oceanmining.ruhttp://octupolephonon.ruhttp://offlinesystem.ruhttp://offsetholder.ruhttp://olibanumresinoid.ruhttp://onesticket.ruhttp://packedspheres.ruhttp://pagingterminal.ruhttp://palatinebones.ruhttp://palmberry.ru
http://papercoating.ruhttp://paraconvexgroup.ruhttp://parasolmonoplane.ruhttp://parkingbrake.ruhttp://partfamily.ruhttp://partialmajorant.ruhttp://quadrupleworm.ruhttp://qualitybooster.ruhttp://quasimoney.ruhttp://quenchedspark.ruhttp://quodrecuperet.ruhttp://rabbetledge.ruhttp://radialchaser.ruhttp://radiationestimator.ruhttp://railwaybridge.ruhttp://randomcoloration.ruhttp://rapidgrowth.ruhttp://rattlesnakemaster.ruhttp://reachthroughregion.ruhttp://readingmagnifier.ruhttp://rearchain.ruhttp://recessioncone.ruhttp://recordedassignment.ru
http://rectifiersubstation.ruhttp://redemptionvalue.ruhttp://reducingflange.ruhttp://referenceantigen.ruhttp://regeneratedprotein.ruhttp://reinvestmentplan.ruhttp://safedrilling.ruhttp://sagprofile.ruhttp://salestypelease.ruhttp://samplinginterval.ruhttp://satellitehydrology.ruhttp://scarcecommodity.ruhttp://scrapermat.ruhttp://screwingunit.ruhttp://seawaterpump.ruhttp://secondaryblock.ruhttp://secularclergy.ruhttp://seismicefficiency.ruhttp://selectivediffuser.ruhttp://semiasphalticflux.ruhttp://semifinishmachining.ruhttp://spicetrade.ruhttp://spysale.ru
http://stungun.ruhttp://tacticaldiameter.ruhttp://tailstockcenter.ruhttp://tamecurve.ruhttp://tapecorrection.ruhttp://tappingchuck.ruhttp://taskreasoning.ruhttp://technicalgrade.ruhttp://telangiectaticlipoma.ruhttp://telescopicdamper.ruhttp://temperateclimate.ruhttp://temperedmeasure.ruhttp://tenementbuilding.rutuchkashttp://ultramaficrock.ruhttp://ultraviolettesting.ru
xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Excellent Product Info

הודעהעל ידי FrankJScott » ו' פברואר 09, 2024 8:03 pm

Please try Google before asking about Useful Product Blog 01d1c08
FrankJScott
רובוטריק
רובוטריק
 
הודעות: 1128
הצטרף: ה' אוקטובר 05, 2023 6:33 pm
מיקום: SLOT GACOR

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ש' מרץ 02, 2024 1:22 am

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт
xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ה' מאי 02, 2024 4:42 am

xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » א' יוני 02, 2024 12:43 am

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт
xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am

Re: קוד שכתבתי - אשמח לדעה.

הודעהעל ידי xalmek » ו' אוגוסט 02, 2024 7:16 pm

xalmek
רובוטריק
רובוטריק
 
הודעות: 221558
הצטרף: ה' נובמבר 16, 2023 10:48 am


חזור אל פורום הרובוטיקה

מי מחובר

משתמשים הגולשים בפורום זה: אין משתמשים רשומים ו 5 אורחים

cron