hi, im having issues using the book pic in practice (which uses the 16f84 chip) and the chip that i got with the pickit2 the 16f690.
now after bodging the book code (which is a million times easier to understand than the supplied "lesson" code (that leaves out minor items...) that comes with the pickit2.
i have got the led on, and ive got it flashing, but to get the desired half a second delay in flashes ive had to call the delay routine 8 times for on and 8 times for off... this isnt useful, and is a bodge on how it is meant to be done... so my question is, how do i do this using normal integer numbers without massive duplications.
i should be able to put a number / order the code so that tmr0 is .32 for half a second?
now after bodging the book code (which is a million times easier to understand than the supplied "lesson" code (that leaves out minor items...) that comes with the pickit2.
i have got the led on, and ive got it flashing, but to get the desired half a second delay in flashes ive had to call the delay routine 8 times for on and 8 times for off... this isnt useful, and is a bodge on how it is meant to be done... so my question is, how do i do this using normal integer numbers without massive duplications.
Rich (BB code):
;********************************************
; EQUATES SECTION
TMR0 EQU 1 ;means TMR0 is file 1
STATUS EQU 3 ;STATUS is file 3
PORTA EQU 05H ;PORTA is file 5
PORTB EQU 06H ;PORTB is file 6
PORTC EQU 07H ;PORTC is file 7
TRISA EQU 85H ;TRISA (the PORTA i/o selection is file 85H
TRISB EQU 86H ;TRISB (the PORTB i/o selection is file 86H
TRISC EQU 87H ;TRISC (the PORTC i/0 selection is file 87H
OPTION_REG EQU 81H ;the OPTION register is file 81H
ZEROBIT EQU 2 ;means ZEROBIT is bit 2
COUNT EQU 0CH ;COUNT is file 0C, a register to count events
;********************************************
; LIST P=16F690 ;PIC16F690 chip
#include <p16F690.inc> ;PIC16F690 CHIP
ORG 0 ;the start address is memory 0
GOTO START ;goto START
;********************************************
;CONFIGURATION BITS
;REQUIRES 2X _ _ AND PLACED IN COLOUM 2... THANKS BOOK!
__CONFIG (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF);copied from lesson1 low pin count demo
;********************************************
;SUBROUTINE SECTION
;1 Second Delay
DELAY1 CLRF TMR0 ;START TMR0
LOOPA MOVF TMR0,W ;read TMR0 into W
SUBLW .255 ;TIME-32
BTFSS STATUS,ZEROBIT ;check TIME-W = 0
GOTO LOOPA ;TIME is not = 32
RETLW 0 ;TIME is 32, RETURN
;0.5 second delay
DELAYP5 CLRF TMR0 ;START TMR0
LOOPB MOVF TMR0,W ;read TMR0 into W
SUBLW .127 ;TIME-32
BTFSS STATUS,ZEROBIT ;check TIME-W = 0
GOTO LOOPB ;TIME is not = 16
RETLW 0 ;TIME is 16, RETURN
;********************************************
;CONFIGURATION SECTION
START ;BSF STATUS,5 ;turns to BANK1
BSF STATUS, RP0
MOVLW B'11111111' ;sets 8 bits as input (1)
MOVWF TRISA ;move to PORTA
MOVLW B'00000000' ;sets 8 bits as output (0)
MOVWF TRISB ;move to PORTB
MOVLW B'00000000' ;sets 8 bits as output (0)
MOVWF TRISC ;move to PORTC
MOVLW B'00000111' ;prescaler is /256
MOVWF OPTION_REG ;TIMER is 1/32 secs
BCF STATUS,RP0 ;return to BANK0
CLRF PORTA ;clears PORTA
CLRF PORTB ;clears PORTB
CLRF PORTC ;clears PORTC
CLRF COUNT ;clears COUNT
;********************************************
;Program starts now
BEGIN BSF STATUS,1 ;select register page 1
BCF TRISC,0 ;make i/0 pin C0 an output
BSF PORTC,0 ;turn ON C0
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
BCF PORTC,0 ;turn OFF C0
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
CALL DELAYP5 ;wait 0.5 seconds
BCF STATUS,0 ;back to register page 0
BSF PORTC,0 ;turn on LED C0
GOTO BEGIN ;repeat
END ;This must come at the end of your code