Learn Microcontroller Programming in basic language | Learn PIC Microcontroller Programming?

 What is a Microcontroller?

We can also call a microcontroller a mini-computer. Just like a computer has Input, Output memory and CPU, similarly, all these are inbuilt inside the microcontroller.


Microcontroller IC is used to repeat a single task or multiple tasks. Understand that if you have to maintain the temperature of an oven to a specific degree, then you will set any temperature in the microcontroller, then as soon as the temperature set point is less, the heater will be ON and the temperature will be more than the setpoint, the heater will automatically turn off like this continuously keeps going. this type of work is not possible manually, then a microcontroller IC is used to complete such tasks.

Where is microcontroller ICs used?

We use many such things every day in which Microcontroller IC is used. Such as TV, Remote controller, washing machine Microwave, etc.

Microcontroller IC's many pins have bidirectional IO which means you can use bidirectional pins as input or output. There are also some pins that you cannot change like VCC, VSS and external crystal oscillator, etc.

You can make any big project using a microcontroller IC. To use a microcontroller, first of all, the microcontroller has to be programmed. Microcontroller IC without a program will not work anything. Many companies in the market make microcontrollers. Different programming languages ​​are used to program them. Usually, C, C++, and machine languages ​​are used for this. these languages ​​are easy to use for the programming knower, but it is a bit difficult for the new learner. Another language is used to program microcontroller ICs and that is the BASIC programming language. This programming language is very easy to use and anyone can teach it easily. So we are going to learn the Basic programming language for microcontroller programming.

We will use PIC series microcontroller ICs manufactured by Microchip company to learn to program. This is a little easy way for newbies to learn Microcontroller IC programming. After writing any program, we need software to compile that program, different software is used for different programming languages.

What is IDE?

To make programming easy, we need an IDE, the full form of IDE is Integrated Development Environment, and its use makes programming easy. IDE is such software in which you can write the program and you can also compile a program, if there is some mistake while writing the program then we see a warning in IDE. So with the help of IDE, it becomes easier for us to write programs, and the chances of making mistakes are less.

We will use Pic Simulator IDE in the beginning, it is very easy to use it. And in this, we can simulate the program and understand it with animation. With the help of the pic simulator IDE, we will start learning to program.

Pic Simulator IDE Download


 



If you open the pic simulator IDE a view like this opens initially

When we click on Files then these three options will open with us.

1) clear memory

2) load memory

3) save memory

These three options come in handy during simulation.

we will discuss later of this. 



Simulation This option is used to start and stop the simulation.




Simulation This option is used to increase or decrease the speed of the simulation.



In the Tools option, we get many tools, with the help of which we can see the input-output in the simulation.



In Tools, we can see the view of the microcontroller, in which analog and digital pins are visible to us.



In this view, we can see a 16 X 2 LCD display. We can program it in the microcontroller and display its output on LCD.


Now we will learn our first program. 

How to set pic microcontroller pins as input or output?

To write the program, we will use the compiler of Pic Simulator IDE, so for this, we will click on Tools and click on Basic Compiler from it, then the compiler window will open.



The basic compiler would look something like this.



How to set microcontroller pins input and output?

TRIS resistor set microcontroller pins as an input or output
Method 1
TRISA  %111111111  ‘for input
TRISA  %00000000  ‘for output
Method 2
TRISA 0b111111111  ‘for input
TRISA 0b00000000  ‘for output

LED Program


TRISB = %10000001
TRISA = %000000
TRISC = %00000000
TRISD = %00000000
TRISE = %000
PORTB = %00000000
Loop:
PORTB.1 = 1
WaitMs 50
PORTB.1 = 0
WaitMs 50
GoTo Loop

_______________________________________________________

Switch Program



TRISA = %000000
TRISE = %000
TRISB = %10000001
TRISC = %00000000
TRISD = %00000000
Symbol led1 = PORTA
Symbol led2 = PORTE
Symbol led3 = PORTC
Symbol led4 = PORTD
Symbol led5 = PORTB
Symbol sw1 = PORTB.0
Symbol sw2 = PORTB.7
Loop:
If sw1 = 1 Then
led1 = 63
led3 = 255
Else
led1 = 0
led3 = 0
EndIf
If sw2 = 1 Then
led2 = 7
led4 = 255
Else
led2 = 0
led4 = 0
EndIf
GoTo Loop

______________________________________________________

16 X 2 LCD Program



Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_EREG = PORTB
Define LCD_EBIT = 1
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 2
AllDigital
Lcdinit LcdCurBlink
Loop:
Lcdcmdout LcdLine1Home
Lcdout "Electronicstek"
Lcdcmdout LcdLine2Home
Lcdout "12345"
WaitMs 100
Lcdcmdout LcdClear
WaitMs 100
GoTo Loop




How to use Variable?

Dim a As Bit  '0 and 1
Dim b As Byte  '0 To 255
Dim x As Word  '0 to 65535
Dim y As Long  '0 to 4294967295
Dim e As Single  '0 to 4294967295 2.5, 111.50
Dim zz As String

Define LCD_BITS = 4
Define LCD_DREG = PORTC
Define LCD_DBIT = 4
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 0
Define LCD_EREG = PORTC
Define LCD_EBIT = 1
Define LCD_RWREG = PORTC
Define LCD_RWBIT = 2
TRISB = %00000000
TRISC = %00000000
AllDigital
Lcdinit LcdCurBlink
Loop:
b = b + 1
PORTB = b
Lcdcmdout LcdLine1Home
Lcdout #b
WaitMs 1
GoTo Loop


Pic microcontroller  programming Basic Example files








    Blogger Comment
    Facebook Comment

Featured Post

Popular Posts