How To Write A Program For A Microcontroller

Table of contents:

How To Write A Program For A Microcontroller
How To Write A Program For A Microcontroller

Video: How To Write A Program For A Microcontroller

Video: How To Write A Program For A Microcontroller
Video: How to Use a Simple Microcontroller Part 1 - An Introduction (PIC10F200) 2024, November
Anonim

Writing a program for a microcontroller with knowledge of the basics of programming languages is very easy. You just need to decide which microcontroller you want to use. Consider writing a program for the PIC16F877, which includes all sorts of technologies and interfaces and is quite good in terms of performance.

How to write a program for a microcontroller
How to write a program for a microcontroller

Instructions

Step 1

Run the preinstalled MPLAB program and select the Project / project Wizard item from the menu. Then a window will open where click "Next". Select PIC16F877 from the list of available microcontrollers and click Next.

Step 2

In the window that opens, select the compiler that will process the code of your future program. Be sure to select HITECH PICC Toolsuite in the Active Toolsuite list. It is a C compiler. Then give the project a name (TestPIC) and specify its directory. Do not write in Russian letters, otherwise problems will arise when opening files. Click Next and then Finish. So, an empty project template is ready.

Step 3

Click File / New. In the Untitled window that appears, select File / Save as … Specify the name TestPIC.c and go to the folder with the project. Check the box next to Add File to Project. Below, place this code in an open project window #include _CONFIG (0x03F72); int i = 0; void main (void) {T0IE = 0; GIE = 0; TRISB = 0; PORTB = 0; while (1 == 1) {PORTB ++; for (i = 0; i

Step 4

Open Configure / Configuration Bits … Here, set the values of the options for the project: Oscillator - HS (a quartz resonator will act as a clock generator), WatchDog Timer - Off (turn off the reset of the microcontroller), Power Up Timer - On (stay in the reset state), Brown Out Detect - On, Low Voltage Program - Disabled, Flash Program Write - Enabled, Data EE Read Protect - Off), Code Protect - Off (disable MK code protection).

Step 5

Compile the code. To do this, click Project / Build All. After the compilation is finished, a window will appear about the successful completion. After that, the TestPIC.hex file will appear in the project folder, which will contain a special code. Write it to the microprocessor using the programmer.

Recommended: