I've built a test circuit for learning how to program the 16f628 pic but I can't understand why my circuit or my code isn't working properly.
My code is...
Still learning so bear with me.
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
Loop1,Loop2
ENDC
;
; -----------
; INITIALIZE
; -----------
;
ORG 0x000 ; Program starts at 0x000
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B
BSF STATUS,RP0 ; RAM bank 1
CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,2 ; Turn on LED connected to RA2
CALL delay
BCF PORTA,2 ; Turn off LED connected to RA2
CALL delay
BSF PORTB,2 ; Turn on LED connected to RB2
CALL delay
BCF PORTB,2 ; Turn off LED connected to RB2
CALL delay
BSF PORTB,3 ; Turn on LED connected to RB3
CALL delay
BCF PORTB,3 ; Turn off LED connected to RB3
CALL delay
BSF PORTB,4 ; Turn on LED connected to RB4
CALL delay
BCF PORTB,4 ; Turn off LED connected to RB4
CALL delay
BSF PORTB,5 ; Turn on LED connected to RB5
CALL delay
BCF PORTB,5 ; Turn off LED connected to RB5
CALL delay
GOTO Main
;
; ---------------
; DELAY 250 MSEC
; ---------------
;
delay MOVLW 250
MOVWF Loop1
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
END
my circuit is attached.
Thanks,
Dominic
My code is...
Still learning so bear with me.
LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system
#include "P16F628.INC" ; Include header file
__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON
CBLOCK 0x20 ; Declare variable addresses starting at 0x20
Loop1,Loop2
ENDC
;
; -----------
; INITIALIZE
; -----------
;
ORG 0x000 ; Program starts at 0x000
CLRF PORTA ; Initialize port A
CLRF PORTB ; Initialize port B
BSF STATUS,RP0 ; RAM bank 1
CLRF TRISA ; All pins port A output
CLRF TRISB ; All pins port B output
BCF STATUS,RP0 ; RAM bank 0
;
; ------------------------
; FUNCTION OF PORT A PINS
; ------------------------
;
MOVLW 7
MOVWF CMCON ; Comparators off, all pins digital I/O
;
; ----------
; MAIN LOOP
; ----------
;
Main BSF PORTA,2 ; Turn on LED connected to RA2
CALL delay
BCF PORTA,2 ; Turn off LED connected to RA2
CALL delay
BSF PORTB,2 ; Turn on LED connected to RB2
CALL delay
BCF PORTB,2 ; Turn off LED connected to RB2
CALL delay
BSF PORTB,3 ; Turn on LED connected to RB3
CALL delay
BCF PORTB,3 ; Turn off LED connected to RB3
CALL delay
BSF PORTB,4 ; Turn on LED connected to RB4
CALL delay
BCF PORTB,4 ; Turn off LED connected to RB4
CALL delay
BSF PORTB,5 ; Turn on LED connected to RB5
CALL delay
BCF PORTB,5 ; Turn off LED connected to RB5
CALL delay
GOTO Main
;
; ---------------
; DELAY 250 MSEC
; ---------------
;
delay MOVLW 250
MOVWF Loop1
Outer MOVLW 200
MOVWF Loop2
Inner NOP
NOP
DECFSZ Loop2,F
GOTO Inner ; Inner loop = 5 usec.
DECFSZ Loop1,F
GOTO Outer
RETURN
END
my circuit is attached.
Thanks,
Dominic
Attachments
-
47.5 KB Views: 83