;LED DIE 12F629.asm ;7 LEDs - slow down and stops on a random face of a dice - ; list p=12F629 radix dec include "p12f629.inc" errorlevel -302 ; Dont complain about BANK 1 Registers during assembly __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc. ; globals ;20h ;this is the first available file fileA equ 26h fileB equ 27h fileC equ 28h fileD equ 29h temp1 equ 2Ah temp2 equ 2Bh temp3 equ 2Ch random equ 30h ;5Fh ;this is the last available file status equ 03h option_reg equ 81h ; bits on GPIO pin7 equ 0 ;GP0 pin6 equ 1 ;GP1 pin5 equ 2 ;GP2 pin4 equ 3 ;GP3 input only pin3 equ 4 ;GP4 pin2 equ 5 ;GP5 ;bits rp0 equ 5 ;bit 5 of the status register Start org 0x00 ;program starts at location 000 nop nop nop nop ;NOPs to get past reset vector address nop nop SetUp bsf status, rp0 ;Bank 1 movlw b'11001000' ;GP3 input movwf TRISIO ; bcf status, rp0 ;bank 0 movlw 07h ;Set up W to turn off Comparator ports movwf CMCON ;must be placed in bank 0 clrf GPIO ;Clear GPIO of junk clrf random goto Main ;Delay - slow-down Del_1 movlw 01h movwf fileC movf temp1,0 movwf fileB DelY decfsz fileA,1 goto DelY btfsc GPIO,3 goto _AA incf random,1 movlw 07 subwf random,0 btfss 03,0 ;test the Carry. Carry is SET if W is less than or equal goto _AA clrf random incf random,1 _AA decfsz fileB,1 goto DelY decfsz fileC,1 goto DelY retlw 00 Del_10 movlw 12h movwf fileC DelZ decfsz fileA,1 goto DelZ decfsz fileB,1 goto DelZ decfsz fileC,1 goto DelZ blank bsf status, rp0 ;Bank 1 movlw b'11111111' ;Set GP 1,2 4 5 input movwf TRISIO ; movf GPIO,0 movlw b'00001000' ;must clear the GPIF flag!! movwf INTCON bsf IOC,3 sleep nop bcf status, rp0 ;bank 0 goto SetUp cycle movlw 0Ch movwf temp3 movlw 20h movwf temp2 cycle1 call face1 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 call face2 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 call face3 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 call face4 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 call face5 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 call face6 incf temp2,1 incf temp2,1 incf temp2,1 movf temp2,0 movwf temp1 call Del_1 decfsz temp3,1 goto cycle1 retlw 00 end1 call face1 movf temp2,0 movwf temp1 call Del_1 retlw 00 end2 call face2 movf temp2,0 movwf temp1 call Del_1 retlw 00 end3 call face3 movf temp2,0 movwf temp1 call Del_1 retlw 00 end4 call face4 movf temp2,0 movwf temp1 call Del_1 retlw 00 end5 call face5 movf temp2,0 movwf temp1 call Del_1 retlw 00 face1 movlw b'00010000' ; movwf GPIO retlw 00 face2 movlw b'00000100' ; movwf GPIO retlw 00 face3 movlw b'00010100' ; movwf GPIO retlw 00 face4 movlw b'00000110' ; movwf GPIO retlw 00 face5 movlw b'00010110' ; movwf GPIO retlw 00 face6 movlw b'00100110' ; movwf GPIO retlw 00 finish1 call end1 goto Del_10 finish2 call end1 call end2 goto Del_10 finish3 call end1 call end2 call end3 goto Del_10 finish4 call end1 call end2 call end3 call end4 goto Del_10 finish5 call end1 call end2 call end3 call end4 call end5 goto Del_10 Main btfsc GPIO,3 goto Main call cycle Main1 decfsz random,1 goto Main2 goto finish1 Main2 decfsz random,1 goto Main3 goto finish2 Main3 decfsz random,1 goto Main4 goto finish3 Main4 decfsz random,1 goto Main5 goto finish4 Main5 decfsz random,1 goto Del_10 goto finish5 ;oscillator calibration call 03ffh movwf OSCCAL end