How to write a picaxe program




















I've made a small program for my picaxe 08M chips that works pretty well. However, I want to be able to put it into different programming languages C, Basic, etc and I'm not sure the best way to go about it. I've only learned Picaxe Basic, so I'm not sure what kind of work the basic interpreter does. I suppose if I knew that, I would know how to write my program in regular Basic code. Any help would be greatly appreciated! Thank you Code:.

It's not simply a matter of conversion. First you would need a reason to change, either the existing code is not fast enough or won't address certain problems. Then you would need to select the chip to use. Then select a compiler and code type. Then read the existing code to see what you intend the code to do. Then start to write the new code by configuring the new chip Write and then test the new code in a simulator and fix any bugs. Well, if it "works pretty well", what is the reason for converting it?

Wow what a great response, thank you jedynakiewicz! Firstly thank you for the warm welcome--I've been lurking around these forums for a while now, this is my first real challenge that I was hoping to get some help with. I was pretty confused initially when learning about the different 'dialects' as you put it so your response really clears up a lot of my confusion. Basically I have been using strictly Picaxe chips for my projects so I was feeling pretty comfortable and confident in that.

However, I have since earned myself some free PIC chips from a friend, as well as another chip from a free giveaway, and I wanted to see if I could make this current project work on the PIC chip. I don't want to stop using my Picaxe chips because they are just so versatile and I'm actually getting the hang of them! But, I would like to remain versatile myself and be able to do projects on both my picaxe chips and my pic chips fyi the pic chips I have are PIC10F I have no idea how to use the new additions to my hobby, and while I want to be able to try this program on this new pic chip it's much smaller so I can run the project in a much smaller container, which I'm excited about , I dont really have the time to learn an entirely different language.

Although the PIC18F portfolio is very large, many of the chips have several commonalities. For detailed pin-outs of the PIC microcontroller see the "Pin Diagram" section in your devices datasheet. Connect a 0. Leave pin 6 of the PICkit 3 unconnected. Connect any analog inputs to pins with ANx functionality where x is a number. Connect any digital inputs or outputs to pins with Rxy functionality where x is a letter identifying the port, and y is a number identifying the bit.

You may find it easier to program the PIC if you have sketched down a schematic of your circuit. This step will explain how to get these tools and ensure they have been installed correctly. Note: If you are using Windows 8 you may need to run the installers in compatibility mode for Windows 7. If it is listed select OK and move on the next step. If it is not listed ensure that instillation has completed, and click Scan for Build Tools button.

If still not listed, look on Microchips forum for help with your specific problem. In this step we will create a new project based on a template from Microchip.

Before we can get started programming we need to set the build parameters. Create Configuration Right click on the project name in the projects tool bar. In the Project Properties dialog select Manage Configurations Text will start scrolling in the output window at the bottom of the page. If you get an error, go back through this step making sure that you did not miss anything, and that everything was applied.

The next step is setting the configuration bits. The configuration bits tell the MCU its initial conditions for when it turns on. They are used to set the clock source and speed, watchdog time configuration, and other similar features. Configuration bits are device dependent, so check the data sheet for the chip you are using for more information.

Since these are chip dependent, check the data sheet for more information about what each does. Unless you are using an external crystal, leave set as Internal RC oscillator. See data sheet for other oscillator configurations.

Note: this will not turn on the PLL, it will only enable it. It is recommended to enable it. Watchdog Timer -- The watch dog timer is used to ensure the processor will not lock up. It however makes it much harder to debug. It is recommended to disable it while initially programming, and only enable it after the project is nearly done. Leave all of these disabled.

If unsure about a setting, it is usually safe to leave it default. After all configuration bits have been set, click the "Generate Source Code to Output" button at the bottom of the panel. The panel will now switch to the Output tab.

Clean and build the project again by clicking the broom and hammer icon. Ensure the build was successful. Also check to make sure there was no errors in the output If everything has worked move on to the next step. If there are errors or warnings fix them before moving on. The next step is to start programming; however, before we get to the application code we must program the system code. The system code are the low level functions such as configuring the oscillator and basic delay functions.

Determining Settings Before we can program the settings, we must choose what speed we would like to run at. If you are using the internal oscillator then use the settings relating to INTIO1 On the next page or two you will find a schematic drawing of the oscillator similar to the one shown.

It is helpful to trace the signal on this drawing to ensure the correct speed is being selected. The next step is to program these settings to the MCU. This is done by setting registers.

IDLEN -- used to control the action of the sleep command. Can be left as default. IRCF -- Oscillator selection. Remove the comments in that function. To set the bits of a register type in all caps the register name, followed by the lowercase word bits and then a period and the bit name.

To set the bits follow that with an equal sign. Lastly end the line with a semi-colon. See below for an example of a finished ConfigureOscillator function. This however is not a function in the standard library, and will need to be programmed by you. For this implementation there will be a loop which will hold the processor until the given time has passed.

PIC18F microcontrollers need 4 clock cycles to execute one line of assembly code. Since a for loop will take one instruction each time for the comparison, and two for the operation one for the body of the loop, it will work perfectly.

We just need the for loop to loop time per milli-second. In system. The best way to test that everything is set up correctly is to blink an LED light. If the light blinks at the expected rate then everything has been configured correctly. If you have your LED connected to a different pin, use the appropriate registers and bits. Open main. The function void main void is the main entry point of the program.

When the MCU first powers on it will enter into this function. The first line calls the ConfigureOscillator function you filled in to set the clock source and speed. The next line calls InitApp, a function that we will fill in shortly, and finally it enters an infinite loop.



0コメント

  • 1000 / 1000