19
Brendan BurrBTEC National Certificate in Electronics Using a Microprocessor Development System 1

BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Embed Size (px)

DESCRIPTION

This assignment has been uploaded for REFERENCE ONLY, direct copying will only be a short term benefit!

Citation preview

Page 1: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

1

Page 2: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

2

Page 3: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

3

Page 4: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

Task 1

4

Page 5: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

5

Page 6: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

Task 22.1 There are a few benefits to using an assembler.

Speed – the software is easy to use once you become familiar with it. If there are errors in the program then it is extremely simple to locate and rewrite the code. In MPASMWIN the software produces an Error list. This list enables the user to read and locate where potential errors could be in the code, speeding up the problem finding process.

Size – the code can be written to produce relatively complex results, without taking up a massive amount of memory.

Range – the range of use is large, as there are many IC chips which can be programmed using assembler code. So by using similar language there are many possibilities for the required output.

2.2 Explain clearly the difference between an assembler mnemonic instruction and an assembler directive.

Assembler Mnemonic Instruction is an instruction which is used to perform arithmetic and logical operations on data residing in either memory or registers.Mnemonic Instructions also have the ability to move data in and out of registers and memory and can also perform conditional branching to specified program addresses.

An example of Assembler Mnemonic Instruction:

BSF STATUS, BIT5 ;Bit 5 in Status Register is set to 05h

Assembler Directives provide control of the operation. This is because the Directives allow the assembler to recognise how to treat the mnemonic instructions, reference data and format the listing and output files.

An example of Assembler Directive:

RTCC EQU 01h ;real time clock counter equates to 1 in decimal

6

Page 7: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

2.3 State 2 different classes of assembler directives.

Data Directives control the allocation of memory and provides a way to refer to data items symbolically, be meaningful names.

Control Directives permit sections of conditionally assembled code.

2.4 Give 1 example of an assembler directive for each class stated in 2.3 above.

Data Directives Data Zero Set Res Equ Include

Control Directives If Else Endif Org End

7

Page 8: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

Task 3Identify and correct a linear and subroutine programming errors in given fragments of a program.

8

Page 9: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

Task 44.1 Explain the use of interrupts in a microcontroller.

Interrupts are used to indicate that a change in situation has occurred.A simple example of an interrupt would be the keys on a keyboard. Every time a key is pressed it sends an interrupt signal to indicate that a button has been pressed, these are called hardware interrupts. Software interrupts are initiated from software, software interrupts are also called traps and exceptions.

A personal computer can support 256 software interrupts and 15 hardware interrupts. Each of the 256 software interrupts has an interrupt handler. An interrupt handler is a routine which takes control when the interrupt signal is received. The full list of interrupts and the corresponding interrupt handlers are stored in a table called the interrupt vector table, which is located in the first 1Kb of addressable memory.

The main reason for the use of interrupts is so that time critical functions (such as typing on a keyboard) can be separated from the main software code, so they do not get overwritten and lost by the hardware. They do exactly as their name suggests, they interrupt the main code from its current task and get the processor to process the interrupt handler routine, taken from the interrupt vector table.

9

Page 10: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

4.2 Evaluate and contrast the operation of a conventional programmed subroutine with that of an interrupt driven routine.

When programming a PIC Chip using assembler code, the program loops around. This means that it will have to complete an entire loop every time, even if nothing has happened wasting the processors time. An interrupt can used to run a routine if an event occurs, keeping wastage of processing power to a minimum.

A conventional programmed subroutine will be run when it is called in the programs main code. It could be bypassed with a “BTFSS” command, which would skip the subroutine until the logic in a sensor went to zero. This would speed the overall program run time as it would simply test the sensors logic level before running the subroutine.

Example of calling a subroutine:

CALL SUBROUTINE1

This would call the routine which is labelled. The routine would then follow on after the label.

SUBROUTINE1MOVLW .32 ;loads W with decimal 32

NEXTMOVWF TEMP ;move value of W into TEMPDECFSZ TEMP,0 ;decrement 1 from TEMP store the result in

;the carry bit (MSB). Skip the next ;instruction if value equals zero

GOTO NEXT ;the program jumps to the NEXT routine ;until zero is reached

RETLW 0 ;return from the subroutine with 0 in W

This subroutine would be called in the main code and then keep looping (32 times) until the value in the Temporary register equals 0. Once it equals zero the following line of code is skipped and the subroutine will then be complete. The program will return to its original location (with zero loaded into the working register) in the main code, the rest of the main code will then be processed.

10

Page 11: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

When an interrupt driven routine is used, an asynchronous signal is generated, the routine is then pulled from the interrupt vector table. However in a subroutine, the input will be tested in every single loop.

For example:

BTFSC PORTA,BIT0 ;Test Bit 0 in PORT A to see if it set ;to logic ’1’, if it is then DO the next ;instruction.

CALL SUBROUTINE1 ;Call and do subroutine1

This would be in the main code. It would test BIT 0 in PORT A on every single loop. If for example every key on a keyboard was to be tested in the routine the response time would become slow, this is because the program would have to test every single key before beginning a new loop.When an interrupt driven routine is used, there is no testing on every loop, the program simply responds and executes its routine when a key is pressed.

This shows that there is a much bigger advantage in using an interrupt driven routine, over the conventional programmed subroutine.

11

Page 12: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

Task 5Produce program code to facilitate digital input and output of data appropriate interfacing and explain the operation of the interfacing devices.

;Brendan Burr 11/06/2009 Filename :8 Bit Left and Right rotate ;of 1 Bit (Task 5).ASM

;This program produces a walking 1 (LED) left and right when a corresponding ;push button is pressed.;Requires an LED box connected to PORT B and Push Buttons connected to PORT A.

title 'assignment 3 task 5' ;assembler directive

;**********General Equates**********

RTCC EQU 01h ;The REAL TIME CLOCK COUNTER is located in ;File Address 01h on Page 0 of the ;Register Files.

PORTA EQU 05h ;PORT A is located in File Address 05h on ;Page 0 of the Register Files.

TRISA EQU 05h ;TRIS A is located in File Address 85h on;Page 1 of the Register Files.

PORTB EQU 06h ;PORT B is located in File Address 06h on ;Page 0 of the Register Files.

TRISB EQU 06h ;TRIS B is located in File Address 86h on;Page 1 of the Register Files.

OPTI EQU 01h ;The Operation Register is located in File ;Address 81h on Page 1 of the Register ;Files.

STATUS EQU 03h ;STATUS REGISTER is located in File ;Address 03h on Page 0 of the Register ;Files.

CARRYEQU 00h ;Carry bit equates to 00 in Hexadecimal.BIT0 EQU 00h ;BIT 0 equates to 00 in Hexadecimal.BIT1 EQU 01h ;BIT 1 equates to 01 in Hexadecimal.Z EQU 02h ;Z equates to 02 in Hexadecimal.BIT5 EQU 05h ;BIT 5 equates to 05 in Hexadecimal.TIME EQU 01h ;TIME equates to 1 in decimal.TEMP EQU 20h ;The TEMPORARY REGISTER can be found at

;20h on Page 0 of the Register Files.

;**********Initialisation Code**********

ORG 0 ;start of program initialisation .

BSF STATUS,BIT5 ;Bit 5 in Status Register is set to ;LOGIC ‘1’. This makes Page 1 in the

;Register Files active. MOVLW b'00001111' ;loads decimal 15 into W. MOVWF TRISA ;loads the decimal 15 (from W) into TRISA, ;setting BIT 0, BIT 1, BIT 2, and BIT 3

;as INPUTS.MOVLW b'00000000' ;loads decimal 0 into W.

MOVWF TRISB ;loads the decimal 0 (from W) into TRISB, ;setting all Pins as OUTPUTS.

MOVLW b'00000111' ;loads decimal 7 into W. MOVWF OPTI ;loads the decimal 7 (from W) into the

12

Page 13: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

;Option Register. ;This then sets - ;-RTCC Signal Source to 0 (Internal Clock). ;-RTCC Signal Edge Bit to 0 (Low to High on ;RTCC Pin). ;-Pre Scaler Assignment Bit to 0 (RTCC). ;-Pre Scaler Bits to 1 1 1, giving a ratio ;of 1:256 (RTCC Rate) and 256uS per count.

BCF STATUS,BIT5 ;Bit 5 in Status Register is cleared to ;LOGIC ‘0’. This makes Page 0 in the ;Register Files active.

MOVLW b'00000001' ;loads decimal 1 into W.(illuminating ;the corresponding LED).

MOVWF PORTB ;send this value to the Port B output ;(illuminating one LED).

MOVLW TIME ;load W with decimal 1. MOVWF RTCC ;loads the 01h (from W) into the RTCC.

BCF STATUS,BIT0 ;BIT 0 (CARRY BIT) in the Status Register ;is cleared to LOGIC ‘0’.

MAINLOOP ;start of my program main code.CALL DELAY1 ;call the DELAY (shown below).

MOVLW TIME ;load W with decimal 1. MOVWF RTCC ;loads the 01h (from W) into the RTCC.

BTFSS PORTA,BIT0 ;Test BIT 0 in PORT A. If it is ;LOGIC ‘1’ (i.e. push to make button 1 is ;pressed), then SKIP the next instruction. ;If BIT O in PORT A is LOGIC ‘0’ ;(i.e. push to make button 1 is NOT ;pressed) then DO the next instruction.

GOTO MAIN2 ;Calls the MAIN2 (shown below).BTFSC PORTA,BIT1 ;Test BIT 1 in PORT A. If it is

;LOGIC ‘1’ (i.e. push to make button 1 is ;pressed), then DO the next instruction. ;If BIT 1 in PORT A is LOGIC ‘0’ ;(i.e. push to make button 1 is NOT ;pressed) then SKIP the next instruction.

GOTO MAINLOOP ;repeat the MAINLOOP.RLF PORTB,1 ;rotate all bits 1 place to the left

;(Moving the illumiated LED one place to ;the left).

BTFSC STATUS,CARRY ;check if the carry bit in the status ;register is ‘0’, if it is then skip the ;next instruction. If carry bit is ;logic ‘1’ then do next instruction.

RLF PORTB,1 ;rotate all bits 1 place to the left ;(Moving the illumiated LED one place to ;the left).

GOTO MAINLOOP ;repeat the MAINLOOP.

MAIN2BTFSS PORTA,BIT1 ;Test BIT 1 in PORT A. If it is

;LOGIC ‘1’ (i.e. push to make button 1 is ;pressed), then SKIP the next instruction. ;If BIT O in PORT A is LOGIC ‘0’ ;(i.e. push to make button 1 is NOT ;pressed) then DO the next instruction.

GOTO MAINLOOP ;repeat the MAINLOOP.

13

Page 14: BTEC NC - Microprocessor Systems and Application - Using a Microprocessor Development System

Brendan Burr BTEC National Certificate in ElectronicsUsing a Microprocessor Development System

RRF PORTB,1 ;rotate all bits 1 place to the right ;(Moving the illumiated LED one place to ;the right).

BTFSC STATUS,CARRY ;check if the carry bit in the status ;register is ‘0’, if it is then skip the ;next instruction. If carry bit is ;logic ‘1’ then do next instruction.

RRF PORTB,1 ;rotate all bits 1 place to the right ;(Moving the illumiated LED one place to ;the right).

GOTO MAINLOOP ;repeat the MAINLOOP.

DELAY1 ;beginning of the DELAY.

MOVLW .10 ;loads decimal 10 into W.

NEXT1 ;beginning of the NEXT1 LOOP.MOVWF TEMP ;loads the decimal 10 (from W) into the

;TEMPORARY REGISTER. Each cycle of the ;NEXT1 routine will decrement 1 from this ;value. ;This means that the larger the number loaded ;into W (at the beginning of DELAY) the more ;times the cycle is looped until the value in ;TEMP is ‘0’ making it longer to run a ;complete cycle, resulting in a time DELAY!

CALL DELAY2 ;calls the NEXT2 (shown below).CALL DELAY2 ;calls the NEXT2 (shown below).DECFSZ TEMP,0 ;decrement decimal 1 from the decimal 25

;stored in the TEMPORARY REGISTER. Skip the ;next instruction if the TEMP value equals ;zero.

GOTO NEXT1 ;the program jumps to the NEXT1 routine until ;zero is reached.

RETLW 0 ;return back to the MAINLOOP from the DELAY1 ;subroutine with 0 in W.

DELAY2 ;beginning of the DELAY2 NEXT2 ;beginning of the NEXT2 LOOP.

MOVF RTCC,W ;move decimal 1 from the RTCC into W.BTFSS STATUS,Z ;Test the Zero Bit in the Status Register to

;see if it is SET to LOGIC ‘1’ if it is then ;SKIP the next instruction, if it is CLEAR to ;LOGIC ‘0’ then DO the next instruction.

GOTO NEXT2 ;program jumps to NEXT2 LOOP.MOVLW TIME ;loads 01h into W.MOVWF RTCC ;loads the 01h (from W) into the RTCC.RETLW 0 ;return back to the NEXT1 from the

;subroutine with 0 in W.

END ;end of program.

14