The exercise involved producing a program to output a binary count sequence on portB after pressing a switch on port A bit RAO.
| ;The following program will produce a binary count sequence
on port B ;after pressing switch A0. ; |
|||
| LIST | p=16F84 | ||
| ; ****** PROGRAM EQUATES ****** ; |
|||
| pc | EQU | 0x02 | |
| status | EQU | 0x03 | |
| porta | EQU | 0x05 | |
| trisa | EQU | 0x05 | |
| portb | EQU | 0x06 | |
| trisb | EQU | 0x06 | |
| delay1 | EQU | 0x0c | |
| delay2 | EQU | 0x0d | |
| delay3 | EQU | 0x0e | |
| value | EQU | 0x12 | |
| ; | |||
| timer | EQU | 0x0f | |
| r0 | EQU | 0x10 | |
| r1 | EQU | 0x11 | |
| dat5msh | EQU | .10 | |
| dat5msl | EQU | .167 | |
| ; | |||
| rp0 | EQU | 5 | |
| f | EQU | 1 | |
| w | EQU | 1 | |
| ; ; ****** MAIN PROGRAM ****** |
|||
| ORG | 0x00 | ||
| ; | |||
| init | BSF | status,rp0 | ;Select register page 1 |
| MOVLW | 0x00 | ||
| MOVWF | trisb | ;Set port B all outputs | |
| MOVLW | 0xff | ||
| MOVWF | trisa | ;Set port A all inputs | |
| BCF | status,rp0 | ;Select register page 0 | |
| ; | |||
| MOVLW | 0xff | ;Switch off all LEDs | |
| MOVWF | portb | ||
| MOVWF | value | ;'value' is output value | |
| ; | |||
| start | BTFSC | porta,0 | ;Check for RA0 = 0 |
| GOTO | start | ;No, read port A again | |
| ; | |||
| begin | MOVLW | .20 | ;Yes set timer value = 20 dec |
| MOVWF | timer | ||
| MOVLW | 0x01 | ||
| SUBWF | value,f | ;Subtract 0x01 from value | |
| ; | |||
| wait | MOVF | value,w | |
| MOVWF | portb | ;Output value to port B | |
| CALL | dly5ms | ;Call delay subroutine | |
| DECFSZ | timer | ;timer:=timer - 1 | |
| GOTO | wait | ;if timer != 0 do subroutine again | |
| ; | |||
| GOTO | begin | ;go back to set timer | |
| ; ; ****** DELAY SUBROUTINE ****** |
|||
| dly5ms |
MOVLW | dat5msh | ; - outer delay loop |
| MOVWF | r0 | ||
| ; | |||
| dly5ms1 | MOVLW | dat5msl | ; -inner delay loop |
| MOVWF | r1 | ||
| ; | |||
| dly5ms2 | DECFSZ | r1 | ; -inner delay loop |
| GOTO | dly5ms2 | ||
| DECFSZ | r0 | ||
| GOTO | dly5ms1 | ;- outer delayloop | |
| ; | |||
| enddly | RETURN | ||
| END | |||
Now derive a stimulus file for the above program.
[On to Unit 4 - A more detailed look at Microcontroller Peripheral Modules]
[back to Practical 5 Question sheet]
Updated 20.06.07 ML
Powered by Google
Site Map