How to Write a Program Microcontroller Can Execute

How to Write a Program Microcontroller Can Execute, To execute an instruction on a microcontroller, you have to send commands to the microcontroller which can understand are called computer instructions.

Our first task is to use a microcontroller to illuminate an LED. Obviously, this LED must be connected to a certain pin of the MCU. Otherwise, the MCU can’t control it. So which pin is connected? In addition to the five pins that have just been used, there are 35 on the MCU. We connect this LED to the pin 1 after check microcontroller pin arrangement. (See Figure 1, where R1 is the current limiting resistor).

How to Write a Program Microcontroller Can Execute

How to Write a Program Microcontroller Can Execute

According to the connection of this figure, when the 1 pin 1 is high level, the LED is not lit, and only when the 1 pin is low level, the LED is illuminated. Therefore, we must be able to control the pin 1, that is, we must be able to make the pin 1 high or low as required.  INTEL which designed 8051 microcontroller, has already started to called P1.0.

The instruction to make a pin output high is SETB, and the instruction to make a pin output low is CLR. Therefore, we want P1.0 output high level, as long as write SETB P1.0, P1.0 output low level, just write CLR P1.0. Now we have a way to let the computer output P10 high or low, but how can we execute this command on the microcontroller?

There are still a few steps to go to solve this problem.

First, the microcontroller does not understand instructions such as SETB CLR. We have to translate the instructions into a way that microcontroller can understand, and then let the microcontroller read. What can a microcontroller know? It only knows one thing – the number. So we have to change SETB P1.0 to (D2H, 90H) and CLR P1.0 to (C2H, 90H), as to why these two numbers are also specified by the 51 chip designer – INTEL.

how to programme avr microcontroller

how to programme avr microcontroller

The second step, after getting these two numbers, how to make these two numbers enter the inside of the microcontroller?

machine code instruction

machine code instruction

This is done by means of a hardware tool “programmer”. If you still don’t know what a programmer is, let me introduce it, that is, the code that you write on the computer is written to the eprom of the microcontroller with a target generated by the compiler such as the assembler, 80c51 MCU programming is a very troublesome thing. It must be programmed on the programmer before it can be used on the device. The latest AT89s51 or STC89C51 MCU can support the online programming (ISP) function without using it. A simple circuit can be used to write the code into the microcontroller.