Hi, I'm wondering if you can help me. I'm a total beginner with PIC programming.
I've read many tutorials, but just can't seem to get this working right. I want to make a binary clock, simply counting seconds for now, but in the end going on to cound just hours and minutes. I'm using a Velleman K8048 PIC programming kit, which utilises 6 LED's connected to RB0-RB5, and four Switches connected to RA0-RA3 (using a PIC16F84A).
Basically, I can get the LED's (1-4) counting in binary from 0 to 10, but it's going waaay too fast. Here's my code (WARNING I'm totally crap so please don't laugh at me):
I know there's too many nop's but I just got frustrated in the end . I have found 2 pieces of code which I'd love to use instead, but they don't even work at all with my set-up. They are located at the following URL's:
http://techref.massmind.org/techref/piclist/cheapic/binclock.htm
http://techref.massmind.org/techref/piclist/cheapic/bincnt.htm
Any help would be much appreciated. In fact, I'd prefer it if someone could tell me why the binary clock located at the 1st URL i gave you ^ won't work with my PIC16F84A.
Blueprint.
I've read many tutorials, but just can't seem to get this working right. I want to make a binary clock, simply counting seconds for now, but in the end going on to cound just hours and minutes. I'm using a Velleman K8048 PIC programming kit, which utilises 6 LED's connected to RB0-RB5, and four Switches connected to RA0-RA3 (using a PIC16F84A).
Basically, I can get the LED's (1-4) counting in binary from 0 to 10, but it's going waaay too fast. Here's my code (WARNING I'm totally crap so please don't laugh at me):
Code:
processor pic16f84a
include "p16f84a.inc"
__config _XT_OSC & _WDT_OFF & _PWRTE_ON
;----- Register Files------------------------------------------------------
INDF EQU H'0000'
TMR0 EQU H'0001'
PCL EQU H'0002'
STATUS EQU H'0003'
FSR EQU H'0004'
PORTA EQU H'0005'
PORTB EQU H'0006'
INTCON EQU H'000B'
OPTION_REG EQU H'0081'
TRISA EQU H'0085'
TRISB EQU H'0086'
CMCON EQU H'001F'
;----- STATUS Bits --------------------------------------------------------
IRP EQU H'0007'
RP1 EQU H'0006'
RP0 EQU H'0005'
NOT_TO EQU H'0004'
NOT_PD EQU H'0003'
Z EQU H'0002'
DC EQU H'0001'
C EQU H'0000'
;==========================================================================
; Variable Definition
;==========================================================================
TIMER1 EQU H'20' ;Used in delay routine
TIMER2 EQU H'21' ; " " "
PATERN EQU H'22' ;Pattern data for effect's
NUM0 EQU B'00000000'
NUM1 EQU B'00000001'
NUM2 EQU B'00000010'
NUM3 EQU B'00000011'
NUM4 EQU B'00000100'
NUM5 EQU B'00000101'
NUM6 EQU B'00000110'
NUM7 EQU B'00000111'
NUM8 EQU B'00001000'
NUM9 EQU B'00001001'
ORG 0 ;Reset vector address
GOTO RESET ;goto RESET routine when boot.
; *********************************************
; * Example of a delay routine *
; *********************************************
DELAY_ROUTINE MOVLW D'255' ;54 Generate approx 10mS delay at 4Mhz CLK
MOVWF TIMER2
DEL_LOOP1 MOVLW D'255' ;60
MOVWF TIMER1
DEL_LOOP2 DECFSZ TIMER1,F
GOTO DEL_LOOP2
DECFSZ TIMER2,F
GOTO DEL_LOOP1
RETLW 0
; **********************************
; ** RESET : main boot routine **
; **********************************
RESET 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' ;all RA ports are inputs
MOVWF TRISA
BCF STATUS,RP0 ;Switch Back to reg. Bank 0
CLRF PORTB
;
EFFECT_1
MOVLW NUM0 ;BINARY 0
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM1 ;BINARY 1
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM2 ;BINARY 2
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM3 ;BINARY 3
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM4 ;BINARY 4
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM5 ;BINARY 5
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM6 ;BINARY 6
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM7 ;BINARY 7
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM8 ;BINARY 8
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
MOVLW NUM9 ;BINARY 9
MOVWF PORTB
nop
nop
nop
nop
nop
nop
nop
nop
CALL DELAY_ROUTINE
GOTO EFFECT_1
END
I know there's too many nop's but I just got frustrated in the end . I have found 2 pieces of code which I'd love to use instead, but they don't even work at all with my set-up. They are located at the following URL's:
http://techref.massmind.org/techref/piclist/cheapic/binclock.htm
http://techref.massmind.org/techref/piclist/cheapic/bincnt.htm
Any help would be much appreciated. In fact, I'd prefer it if someone could tell me why the binary clock located at the 1st URL i gave you ^ won't work with my PIC16F84A.
Blueprint.