Basic Pic Book Preview03
Basic Pic Book Preview03
If you have any experience in writing programs for PIC microcontrollers in assembly language, then you are probably familiar with the other side of the medal of RISC architecture - the lack of instructions. For example, there is no appropriate instruction for multiplying two numbers. Of course, there is a way to solve this issue owing to mathematics which enables you to perform complex operations by breaking them into a number of simple ones. Accordingly, multiplication can be easily substituted by successive addition (a x b = a + a + a + ... + a). And here we are, just at the beginning of a very long story... Still there is no reason to be worried about as far as you use one of the high-level programming languages, such as Basic, as the compiler will automatically find a solution to these and similar issues. Simply write a*b.
BSF BCF CLRF L__main2: BCF CLRF ' Configure pins as outputs MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main6: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF L__main7: DECFSZ GOTO DECFSZ GOTO DECFSZ GOTO NOP NOP GOTO 11 R11 38 R12 93 R13 R13, 1 L__main6 R12, 1 L__main6 R11, 1 L__main6 STATUS, 5 STATUS, 6 TRISA
2
Programming Microcontrollers s Programming Languages
main: TRISA = 0x00 While TRUE PORTA = 0x00 Delay_ms(1000) PORTA = 0xFF Delay_ms(1000) wend end.
STATUS, 5 PORTA
Turn PORTA LEDs OFF 1 second delay Turn PORTA LEDs ON 1 second delay
255 PORTA 11 R11 38 R12 93 R13 R13, 1 L__main7 R12, 1 L__main7 R11, 1 L__main7
The same program compiled into assembly code. As can be seen, each Basic command is broken into several assembly instructions during the process of compiling.
wend GOTO
PIC
MICROCONTROLLERS
PROGRAMMING IN
BASIC
55