Documente Academic
Documente Profesional
Documente Cultură
Pic microcontroller assembly language programing: Like we need language to communicate with each other.
Language is a set of symbols by which we convery our message to others. Similarly, we communicate with
microcontrollers with a language called assembly. A assembler is used to understand our instruction or you can say
our symbols which we provide to microcontroller Assembly language program is basically a set of instructions stored
in computer memory. Computer can only understand 1’s and 0’s. Assembly language instructions are for humans
only. Computer do not understand them. So we need to converter these assembly language instructions to binary
form which is understandable for computers. Assembly language commands are converted into one’s and zero’s by
compiler. A data le used for storing compiled program is called an “executive le”, i.e. “HEX data le”. The name
comes from the hexadecimal presentation of a data le and has a su x of “hex” as well, for example “probe.hex”.
After has been generated, the data le is loaded into the microcontroller using a programmer. Assembly language
codes can be written in any editor. Let’s start with registers of pic microocntrollers to understand basic instructions
of pic microcontroller
Literal addressing
Used when moving constant values. For example MOVLW 0x23, will move 23 (hex) to WREG.
Direct Addressing
Used when moving variables. For example MOVWF _myReg will move contents of myReg to WREG.
Opcode in pic microcontroller assembly language
An opcode is short for ‘Operation Code’. It is a number interpreted by your machine (uC) that represents the
operation to perform. For example MOVLW is an Opcode.
Labels
A label is an identi er used to represent a line in code or section of a program. Goto statements can be used in
conjunction with a Label to jump to the execution of code identi ed by the particular label. See Task 1 code for
example.
mikroC Debugger can be used to check execution of pic microcontroller assembly language instructions.
void main() {
ANSELA =2; //
asm{
GOTO LOOP_START;
}
}
void main() {
OSCCON.IRCF0=0;
OSCCON.IRCF1=1;
OSCCON.IRCF2=1;
ANSELA =2;
asm{
MOVLW 0X01 ;
Loop:
INCF _i,1;// i=i+1
MOVF _i,0;// move i to Wreg
ADDWF _x,1; //x=x+Wreg
MOVLW 9; // Wreg=10
CPFSGT _i;
goto Loop
}
}
X=I; // Set a break point here
unsigned short I,J,X;
void main() {
OSCCON.IRCF0=0;
OSCCON.IRCF1=1;
OSCCON.IRCF2=1;
ANSELB=0;
TRISB=0;
asm {
MOVLW 0xF0;
MOVWF LATB,0;
Rotate:
RLNCF LATB,1,0;
goto Outer
Inner:
INCF _J,1;// J=J+1
MOVF _J,0;// move J to Wreg
ADDWF _X,1; //X=X+Wreg
TRISB = 0x00;
LATB = 0x01;
asm{
CLRF ANSELA; // Write 0 to ANSELA
CLRF ANSELB; // Write 0 to ANSELB
CLRF ANSELC; // Write 0 to ANSELC
CLRF ANSELD; // Write 0 to ANSELD
RLNCF LATB,1;
}}
short var2 = 0;
var2 = abs(var1); //The var2 must get the absolute value of var1
void main() {
asm{
MOVLW 0;
MOVFF _var1,_var2;
ADDWF _var1,0;
BNN end
NEGF _var2
end:
goto end
}
//Global Variables
short max_of_2(){
if(num1>num2){
maximum = num1;
}else{
maximum = num2;
void main() {
asm{
//call max_of_2;
max_of_2:
MOVFF _num1, _maximum;
MOVF _num1,0;
CPFSGT _num2
return
MOVFF _num2,_maximum
return
short array_element = 0;
short i =0;
for(i=0;i<size_array;i++){
array_element=My_array[i];
}
while(1);
void main() {
My_array[1]=2;
asm{
LFSR 1, 0x0060;
for:
INCF _i,1;
MOVFF POSTINC1,_array_element;
MOVLW _size_array;
CPFSEQ _i
goto for
end:
goto end;
I will keep updating this post with more pic assembly language programming examples.
Ezzayany
May 5, 2018 at 12:30 pm | Reply
hai my name is ezza and im a student . i have one problem with my project, Auto Irragation system using soil
moisture sensor and pic microcontroller. Im still new with the programmer and when I already write the
coding and build it,then I put the coding into proteus to make sure my coding function as what I want. then
when I want to burn it to PIC and hardware, the program not function and its like i never write any coding
into PIC. can u help me how to make my PIC function ..
Gedion
May 28, 2018 at 5:55 pm | Reply
hey, I’m a student from Ethiopia. I faced some difficulities while working my project and I’m sending this
comment hoping that you will help me. the project is a simple DC motor speed control using PIC 16f877
microcontroller and the problem is that I couldn’t write the assembly language. I have written the c-language
but the assembly language is difficult for me so please help me
Radhika Dapkar
January 25, 2019 at 3:47 pm | Reply
I want to write simple 4bit addition programme in pic18 , how can I write it?
Please help me
Leave a Comment
Name *
Email *
Website
POST COMMENT
Email Address
SUBSCRIBE
Categories
Select Category
Project services terms of service Privacy Policy Contact us 500+ Electronics tutorials and projects