microcontrollers comments

Thread Starter

DILPREET SINGH011

Joined Mar 3, 2017
3
PIC18F87J11 Configuration Bit Settings

; ASM source line config statement
my instructor just did this coding and I just wanted to know that how to comment the code as I really wanted to know that what is actually happening . so i am attaching two program and i tried to do as you will see in program 1.

1.
Code:
#include "p18F87J11.inc"
temp equ 0x20
 
 
 
 
 
    org 0
    bra mainprog ; jump into main program


oscinit:
 
    bcf OSCCON,IRCF2
    bcf OSCCON,IRCF1;
    bsf OSCCON,IRCF0;
 
    return
 
t1init:
 
    movlw 0x30;  Timer0,8-bit,ext clk,no prescale
    movwf T1CON; load T1CON register
 
    clrf TMR1H; LOAD TH1 as an output
    clrf TMR1L; LOAD TL1 as an output
 
    return

ionit:
 
    clrf TRISD; PORTD as a output
 
    return




mainprog:
 
 
 
     call oscinit;
     call t1init
     call ionit
   
     bsf T1CON,TMR1ON;timer1 ON Enable(start)timer1
   
mainloop:
 
    movff TMR1L,temp
    movff TMR1H,WREG
 
    movff temp,PORTD
 
 
    bra mainloop; jump into main loop
 
 
 
 
 
 
    end
2.
Code:
org 0

bra mainprog

oscinit:

bcf OSCCON,IRCF2 ;

bcf OSCCON,IRCF1
bsf OSCCON,IRCF0

return



tmr2pwm:

movlw 0x10 ;

movwf CCP1CON ;

movlw 0xff ;

movwf PR2 ;

movlw 0x80 ;

movwf CCPR1L ;

movlw 0x03 ;

movwf T2CON ;

bcf TRISC,2

3

return

mainprog:

call oscinit

call tmr2pwm

bsf T2CON,TMR2ON



mainloop:

bra mainloop ;



end
Mod edit: added code tags
 
Last edited by a moderator:

LesJones

Joined Jan 8, 2017
4,190
p18F87J11.inc is just a file that contains things like equ statements so that you can use names for registers rather than entering their address. For example OSCCON EQU H'0FD3' and IRCF2 EQU H'0006'
So the first instruction in the oscinit subroutine " bcf OSCCON,IRCF2" is translated to "bcf 0x0FD3, 0x6" which means clear bit 6 of location 0X0FD3 You will need to read the data sheet on the PIC18F87J11 to see wat all the instructions do and what the bits in registers do. You can find the .inc files in the mpasmx directory of MPLABX. They can be viewed with any text editor.

Les.
 

vead

Joined Nov 24, 2011
629
PIC18F87J11 Configuration Bit Settings

; ASM source line config statement
my instructor just did this coding and I just wanted to know that how to comment the code as I really wanted to know that what is actually happening . so i am attaching two program and i tried to do as you will see in program 1.

1. #include "p18F87J11.inc"
temp equ 0x20





org 0
bra mainprog ; jump into main program


oscinit:

bcf OSCCON,IRCF2
bcf OSCCON,IRCF1;
bsf OSCCON,IRCF0;

return

t1init:

movlw 0x30; Timer0,8-bit,ext clk,no prescale
movwf T1CON; load T1CON register

clrf TMR1H; LOAD TH1 as an output
clrf TMR1L; LOAD TL1 as an output

return

ionit:

clrf TRISD; PORTD as a output

return




mainprog:



call oscinit;
call t1init
call ionit

bsf T1CON,TMR1ON;timer1 ON Enable(start)timer1

mainloop:

movff TMR1L,temp
movff TMR1H,WREG

movff temp,PORTD


bra mainloop; jump into main loop






end


2.
org 0

bra mainprog

oscinit:

bcf OSCCON,IRCF2 ;

bcf OSCCON,IRCF1
bsf OSCCON,IRCF0

return



tmr2pwm:

movlw 0x10 ;

movwf CCP1CON ;

movlw 0xff ;

movwf PR2 ;

movlw 0x80 ;

movwf CCPR1L ;

movlw 0x03 ;

movwf T2CON ;

bcf TRISC,2

3

return

mainprog:

call oscinit

call tmr2pwm

bsf T2CON,TMR2ON



mainloop:

bra mainloop ;



end
please use code tag when posting code
 

Thread Starter

DILPREET SINGH011

Joined Mar 3, 2017
3
p18F87J11.inc is just a file that contains things like equ statements so that you can use names for registers rather than entering their address. For example OSCCON EQU H'0FD3' and IRCF2 EQU H'0006'
So the first instruction in the oscinit subroutine " bcf OSCCON,IRCF2" is translated to "bcf 0x0FD3, 0x6" which means clear bit 6 of location 0X0FD3 You will need to read the data sheet on the PIC18F87J11 to see wat all the instructions do and what the bits in registers do. You can find the .inc files in the mpasmx directory of MPLABX. They can be viewed with any text editor.

Les.
thank you so much
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
PIC18F87J11 Configuration Bit Settings
my instructor just did this coding and I just wanted to know that how to comment the code as I really wanted to know that what is actually happening
All you have to do is to compare each instruction with the section of the Pic manual that explains each instruction in detail, as to what is happening.
The INC file just contains the address of registers.
It avoids having to define them ahead of time.
Max.
 
Top