Semaforo
MATERIA:
ARQUITECTURA DE COMPUTADORAS
MAESTRO:
MATA
ALUMNO:
SERGIO MARTINEZ PALACIO
TRABAJO:
SEMAFOROS
ANALISIS
| | R | A | V | 0 | R | A | V |1000001 | 41 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |
100001 | 21 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
10100 | 14 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
10010 | 12 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
CODIGO
LIST p=16F84; PIC16F844 is the target processor
#include "P16F84.INC" ; Include header file
CBLOCK 0x10 ; Temporary storage
state
l1,l2ENDC
org 0 ; Start up vector.
goto setports ; Go to start up code.
org 4 ; Interrupt vector.
halt goto halt; Sit in endless loop and do nothing.
setports clrw ; Zero in to W.
movwf PORTA ; Ensure PORTA is zero before we enable it.
movwfPORTB ; Ensure PORTB is zero before we enable it.
bsf STATUS,RP0 ; Select Bank 1
clrw ; Mask for all bits as outputs.
movwfTRISB ; Set TRISB register.
bcf STATUS,RP0 ; Reselect Bank 0.
initialise clrw ; Initial state.
movwf state ; Set it.
loopcall getmask ; Convert state to bitmask.
movwf PORTB ; Write it to port.
incf state,W ; Increment state in to W.
andlw 0x03; Wrap it around.
movwf state ; Put it back in to memory.
call wait ; Wait :-)
goto loop ; And loop :-); Function to return bitmask for output port for current state.
; The top nibble contains the bits for one set of lights and the
; lower nibble the bits for the other...
Regístrate para leer el documento completo.