ls; PIC 16F84 with LED on pin 3 and an LED on pin 10 ; Flashes the LED twice quickly on startup. ; Then it loops, recording the button state for a bit and ; replaying it on the LED ; A very complex switch+LED methinks. ; adb@tardis.ed.ac.uk August 5th 1999 ; CPU configuration ; (It's a 16F84, RC oscillator, ; watchdog timer off, power-up timer on) ; data memory is 0c to 4f inclusive J equ 0x0c K equ 0x0d buffer_start equ 0x0e buffer_end equ 0x4f processor 16f84 include <16f84.inc> __CONFIG _RC_OSC & _WDT_OFF & _PWRTE_ON org 0x40 ; SUBROUTINE: wait ; Waste some time by executing nested loops ; counts 255,254...1 then 254,253...1, then ... wait: movlw 0x40 movwf J jloop: movwf K kloop: decfsz K,f ; K = K-1, skip next if zero goto kloop decfsz J,f ; J = J-1, skip next if zero goto jloop return flash: ; Flash the LED on, off, on, off MOVLW 0xff ; On MOVWF PORTB call wait MOVLW 0x00 ; Off MOVWF PORTB call wait MOVLW 0xff ; On MOVWF PORTB call wait MOVLW 0x00 ; Off MOVWF PORTB call wait RETURN org 0 initialise: clrf PORTA ; Clear portA clrf PORTB ; Clear portB BSF STATUS, RP0 ; Change to bank 1 MOVLW 0x1f ; 0001 1111 for inputs on all PortA pins MOVWF TRISA MOVLW 0x0 ; 0000 0000 for outputs on all PortB pins MOVWF TRISB BCF STATUS, RP0 ; Change back to bank 0 start: call flash ; Initialise buffer pointer MOVLW buffer_start MOVWF FSR input_loop: CALL wait ; Sleep a bit MOVF PORTA, W ; Read input MOVWF INDF ; Store it in the buffer INCF FSR, F ; Increase FSR and store back in FSR ; if FSR != buffer_end then loop MOVF FSR, W XORLW buffer_end BTFSS STATUS, Z; skip next if zero is set (FSR == buffer_end) goto input_loop ;; Finished reading data call flash ;; Now write it all out ; Initialise buffer pointer again MOVLW buffer_start MOVWF FSR write_loop: CALL wait ; Sleep a bit MOVF INDF, W ; Read value from buffer MOVWF PORTB ; Output it INCF FSR, F ; Increase FSR and store back in FSR ; if FSR != buffer_end then loop MOVF FSR, W XORLW buffer_end BTFSS STATUS, Z; skip next if zero is set (FSR == buffer_end) goto write_loop call flash goto start end