I have just loaded the demo code for chasing LED’s, all works perfectly. I have read the data sheet for 16F627 and absorbed about 10% of it while trying to find each one of the operation codes that were used in the demo I loaded. I am hungry for more 16F627 asm files for standard functions, such as, an event counter where I can use one of the push buttons as the event trigger, count the number of times it is pushed and then give a result with an LED when it reaches a preset number, but it must be for 16F627 because that is the one I have on the VM111 kit.
Does anyone have some code for this kind of study please?
Hello, anyone !
Yes, i know it’s a little late, answering this topic, but perhaps somebody would find it useful ?
I have done a little programming:
;========================================================================================
;= =
;= EVENTCOUNTER FOR PIC16F627 AND K 8048 / VM 111 =
;= =
;= BY BRUSHLESS 333, 28/6-'14. =
;= =
;========================================================================================
INCLUDE p16f627.inc
__CONFIG _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC
;========================================================================================
; Variable Definition =
;========================================================================================
CBLOCK H'0020'
TIMER1
TIMER2
UPCOUNTER
REG_1
ENDC
SW1 EQU 0
SW2 EQU 1
LD1 EQU 0
LD2 EQU 1
ORG 0 ; Reset vector address
GOTO BOOT ; Go to boot-sequence...
;========================================================================================
;= DELAY-ROUTINE - about 50 msec's at 4 MHz clock =
;========================================================================================
DELAY_50ms MOVLW D'050'
MOVWF TIMER2
DEL_LOOP1 MOVLW D'250'
MOVWF TIMER1
DEL_LOOP2 NOP
DECFSZ TIMER1,F
GOTO DEL_LOOP2
DECFSZ TIMER2,F
GOTO DEL_LOOP1
RETLW 0
;========================================================================================
;= BOOT-SEQUENCE =
;========================================================================================
BOOT MOVLW B'00000111' ;Disable Comparator module's
MOVWF CMCON
;
BSF STATUS,RP0 ;Switch to register bank 1
;Disable pull-ups
;INT on rising edge
;TMR0 to CLKOUT
;TMR0 Incr low2high trans.
;Prescaler assign to Timer0
;Prescaler rate is 1:256
MOVLW B'11010111' ;Set PIC options (See datasheet).
MOVWF OPTION_REG ;Write the OPTION register.
CLRF INTCON ;Disable interrupts
MOVLW B'11000000'
MOVWF TRISB ;RB7 & RB6 are inputs - RB5...RB0 are outputs...
MOVLW B'11111111' ;Make PORTA all inputs...
MOVWF TRISA
BCF STATUS,RP0 ;Switch Back to reg. Bank 0
CLRF PORTB ; resets all outputs...
CLRF UPCOUNTER ; ensures, that the counter starts from zero, after power-on...
CLRF REG_1
;========================================================================================
;= PROGRAM STARTS HERE =
;========================================================================================
BEGINNING CALL DELAY_50ms ; short break...
BTFSC PORTA,SW1 ; testing for released SW1...
GOTO $-1 ; ( circulates through these two instructions, until button is released )
BCF PORTB,LD1 ; indicates a released button...
BTFSC REG_1,0 ; checks what to do - test for "clock-pulse" to the upcounter, or test for manual reset of the completed cycle...
GOTO CHECK_SW2
CALL DELAY_50ms ; short break, in order to prevent any false triggering due to contact bounce...
BTFSS PORTA,SW1 ; testing for an activated SW1...
GOTO $-1 ; ( circulates through these two instructions, until button is depressed )
BSF PORTB,LD1 ; indicates an activated button...
INCF UPCOUNTER,F ; increments the counter one step...
MOVLW D'010' ; ( this value can be between 1-255 )
SUBWF UPCOUNTER,W
BTFSS STATUS,Z ; tests for an "overflow"...
GOTO BEGINNING ; if none, go back and test SW1 again...
BSF PORTB,LD2 ; turns on LD2, when the specified number of cycles is completed...
BSF REG_1,0 ; sets a controlbit for "mission accomplished"
GOTO BEGINNING ; go back, and see what to do next...
;-------------- CHECK FOR RESET ---------------------------------------------------------
CHECK_SW2 BTFSC PORTA,SW2 ; checks for released SW2...
GOTO $-1
CALL DELAY_50ms
BTFSS PORTA,SW2 ; waits for a manual reset on SW2...
GOTO $-1 ; and carries on, when you are ready to start over again...
BCF PORTB,LD2 ; turns off LD2
CLRF UPCOUNTER ; resets the upcounter...
BCF REG_1,0 ; resets controlbit...
CALL DELAY_50ms
GOTO BEGINNING ; now, all is cleared up, nice and tidy, and we make a new start...
END
It’s important to have the p16f627.inc file copied from the include-folder to the examples-folder, in
order to make the ASSEMBLER-software able to find it !