Home
> pic18f, Uncategorized > pic18f assembly example 1 – digital output controlled by digital input
pic18f assembly example 1 – digital output controlled by digital input
;----------------------------------------------------------------------------------------------------------------------------- ; This assembly code monitors RD4 (pin 27) on the pic18f4620. If RD4 is high LATD2 (pin 21) is set high otherwise LATD2 is set low ; ; by David Dorran (https://dadorran.wordpress.com) May 2014 ;----------------------------------------------------------------------------------------------------------------------------- ; TRY TO DO THE FOLLOWING IN ORDER TO DEVELOP YOUR PROGRAMMING SKILLS: ; 1. change the digital input monitored to RD3 ; 2. Set LATD2 high if both RD3 and RD4 are high ;configure the assembler directive 'list' so as to set processor to 18f4620 and set the radix used for data expressions to decimal (can be HEX|DEC|OCT) list p=18f4620, r=DEC #include <p18f4620.inc> ; configure the micro so that the watchdog timer is off, low-voltage programming is off, master clear is off and the clock works off the internal oscillator config WDT=OFF, LVP=OFF, MCLRE=OFF, OSC=INTIO67 ;The org directive tells the compiler where to position the code in memory org 0x0000 ;The following code will be programmed in reset address location i.e. This is where the micro jumps to on reset goto Main ;Jump to Main immediately after a reset ;NOTE: When an interrupt is triggered the micro jumps to 0x0008 for high priority and 0x0018 for low priority. For this reason you ;don't want to place any 'code' at these locations and this is why the you just jump to somewhere else in memory after a reset. ;If interrupts aren't used then there's no problem just moving the Main code to address 0x0000 ;-------------------------------------------------------------------------- ; Main Program ;-------------------------------------------------------------------------- org 0x0020 ;The main code section will be programmed starting from address 20H. Main ; configure D0-D3 as outputs and D4-D7 as inputs by modifying the TRISD register movlw 0xf0 movwf TRISD CLRF LATD ; turn off all the outputs main_loop BTFSS PORTD,4 ; if RD4 is set skip the next line goto turn_LATD2_off bsf LATD,2 ; turn on LATD2 - we wont reach this line in loop if RD4 is low goto main_loop turn_LATD2_off bcf LATD,2 ; turn on LATD2 goto main_loop END
Categories: pic18f, Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback