Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

00-99 COUNT UP & DOWN USING PIC16f887a

Status
Not open for further replies.
Try this code I think I pasted it wrong the first time.
When i commented the code changes I deleted part of the code lol.
This works as shown in the short video. Now for ISIS i don't like it and don't use it any more.
It's so much easier to use real hardware and a lot more fun.
Code:
;*************************************************  *****************
;  (C) K8LH 2-Digit Up/Dn Counter, Isochronous Loop Example v2    *
;*************************************************  *****************
  list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
        errorlevel -302
 
       	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

 
 
number  equ     0x20            ; packed BCD, 0x00..0x99
swlatch equ     0x21            ; switch state latch variable
swflags equ     0x22            ; switch flag bits
DelayHi equ     0x23            ; DelayCy() subsystem variable
 
#define Dn      3               ; RA3
#define Up      2               ; RA2
 
;*************************************************  *****************
;
;  K8LH DelayCy() subsystem macro generates four instructions
;
        radix   dec
clock   equ     16               ; clock frequency in Megahertz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
 
DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   DelayHi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm
 
;*************************************************  *****************
;
;  init hardware and program variables
;
        org     0x000
Init
        bsf     STATUS, RP0     ; Select Bank 1
		movlw   0x07
        movwf   CMCON
        movlw   0x07            ; Configure all pins
        movwf   ADCON1          ; as digital inputs 
        movlw   b'00001100'     ;                                      |B1
        movwf   TRISA           ; RA3-RA2 inputs, others outputs  |B1
        clrf    TRISB           ; portb all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTB           ; clear portb output latches      |B0
        movlw   b'00000001'     ; digit select bits (RA1-RA0)     |B0
        movwf   PORTA           ; select the 'ones' display       |B0
        clrf    swlatch         ; clear switch state latch        |B0
        clrf    swflags         ; clear switch flags              |B0
        clrf    number          ; number = 00                     |B0
;
;  isochronous 8 msec program loop (62.5 Hz display refresh rate)
;
Display
        clrf    PORTB           ; blank the display               |B0
        movf    PORTA,W         ;                                 |B0
        xorlw   b'00000011'     ; flip digit select bits          |B0
        movwf   PORTA           ;                                 |B0
        swapf   number,W        ; W = tens in right nybble        |B0
        btfss   PORTA,1         ; 10's display? yes, skip, else   |B0
        movf    number,W        ; W = ones in right nybble        |B0
        call    segtbl          ; get segment data                |B0
        movwf   PORTB           ; display new digit               |B0
Buttons
        comf    PORTA,W         ; sample active low switches      |B0
        andlw   b'00001100'     ; on RA3 and RA2 pins             |B0
        xorwf   swlatch,W       ; changes (press or release)      |B0
        xorwf   swlatch,F       ; update switch state latch       |B0
        andwf   swlatch,W       ; filter out "new release" bits   |B0
        movwf   swflags         ; save any "new press" bits       |B0
CountUp
        movf    number,W        ;                                 |B0
        addlw   7               ; increment + bcd adjust?         |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; increment only                  |B0
        btfsc   swflags,Up      ; Up press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        movf    number,W        ;                                 |B0
        xorlw   0xA0            ; upper limit 99?                 |B0
        skpnz                   ; no, skip, else                  |B0
        clrf    number          ; reset to 00 (rollover mode)     |B0 <-
CountDn
        movf    number,W        ; lower limit 00?                 |B0
        skpnz                   ; no, skip, else                  |B0
        movlw   0xA0            ; reset to 99 (rollover mode)     |B0 <-
        addlw   -1              ; decrement only?                 |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; decrement + bcd adjust          |B0
        btfsc   swflags,Dn      ; Dn press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        DelayCy(8*msecs-41)     ; precise 8 msec loop timing      |B0
        goto    Display         ; loop                            |B0
;
;  segment data table (caveat, non-boundary tolerant)
;
segtbl
        andlw   0x0F            ; strip off upper nybble          |B0
        addwf   PCL,F           ;                                 |B0
        retlw   b'00111111'     ; "0"   -|-|F|E|D|C|B|A           |B0
        retlw   b'00000110'     ; "1"   -|-|-|-|-|C|B|-           |B0
        retlw   b'01011011'     ; "2"   -|G|-|E|D|-|B|A           |B0
        retlw   b'01001111'     ; "3"   -|G|-|-|D|C|B|A           |B0
        retlw   b'01100110'     ; "4"   -|G|F|-|-|C|B|-           |B0
        retlw   b'01101101'     ; "5"   -|G|F|-|D|C|-|A           |B0
        retlw   b'01111101'     ; "6"   -|G|F|E|D|C|-|A           |B0
        retlw   b'00000111'     ; "7"   -|-|-|-|-|C|B|A           |B0
        retlw   b'01111111'     ; "8"   -|G|F|E|D|C|B|A           |B0
        retlw   b'01101111'     ; "9"   -|G|F|-|D|C|B|A           |B0
;
;  K8LH DelayCy() subsystem 16-bit timing subroutine
;
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract "loop" cycle time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  DelayHi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0
 
        end
See it works
[video=youtube_share;30jcRxCZAY8]http://youtu.be/30jcRxCZAY8[/video]
 
Last edited:
AnneMaj,

Since the program clearly works, you need to post the exact circuit and code that you are using. Are you still trying the Isis simulator or have you moved on to actual hardware?

John
 
Burt!!! Very worrying.... I hope you have something on under the desk!!!!;););)

I think that piece of fabric is a blanket. He is in bed with the circuit :).. filming a home video.
 
I simulated in proteus with the program and it was working with no problem except the display is alternating between the tenth and unit digits at the speed of about 1 Hz.

You have to show us a picture of your simulation or your hardware in order for us to help finding the problem..

Allen
 

Attachments

  • 877a up_down counter 2.PNG
    877a up_down counter 2.PNG
    11.2 KB · Views: 1,752
Last edited:
is mplab ide not working on windows 8 os? cause i just build the asm file on my classmate's PCs. thanks for the help guys.. especially 'be80be'.. tnx. i'll try to build this tomorrow.. tnx again.. :)
 
If the OP would read the code the delay can be changed for what ever crystal your using I set it for a 16 mhz I couldn't find a 8. So you have to change that to match the crystal

Code:
        radix   dec
clock   equ     16               ; clock frequency in Megahertz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
Change the 16 to what your using
 
Burt!!! Very worrying.... I hope you have something on under the desk!!!!;););)

Yes I just was going to bed and read this didn't work so I looked it over and I had commented out a define. But the code I posted was to show what needed changing. Any way the last code I didn't comment the needed changes for the 16F877a.

All the OP had to do was change the configure word and the ADC stuff to turn it off. Mike K8LH Writes great ASM some of the best I ever seen.
 
I was zooming around trying to find a thread and thought it was in this one. Suddenly I see your movie.

You'll not be labeled by "Dunning, Kruger " You just hit my top 10 "Nerdiest at ETO List" Sometime you just gotta show 'em how it's done.

Thanks, Burt. Good one:)
 
Try this code I think I pasted it wrong the first time.
When i commented the code changes I deleted part of the code lol.
This works as shown in the short video. Now for ISIS i don't like it and don't use it any more.
It's so much easier to use real hardware and a lot more fun.
Code:
;*************************************************  *****************
;  (C) K8LH 2-Digit Up/Dn Counter, Isochronous Loop Example v2    *
;*************************************************  *****************
  list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
        errorlevel -302
 
       	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

 
 
number  equ     0x20            ; packed BCD, 0x00..0x99
swlatch equ     0x21            ; switch state latch variable
swflags equ     0x22            ; switch flag bits
DelayHi equ     0x23            ; DelayCy() subsystem variable
 
#define Dn      3               ; RA3
#define Up      2               ; RA2
 
;*************************************************  *****************
;
;  K8LH DelayCy() subsystem macro generates four instructions
;
        radix   dec
clock   equ     16               ; clock frequency in Megahertz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
 
DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   DelayHi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm
 
;*************************************************  *****************
;
;  init hardware and program variables
;
        org     0x000
Init
        bsf     STATUS, RP0     ; Select Bank 1
		movlw   0x07
        movwf   CMCON
        movlw   0x07            ; Configure all pins
        movwf   ADCON1          ; as digital inputs 
        movlw   b'00001100'     ;                                      |B1
        movwf   TRISA           ; RA3-RA2 inputs, others outputs  |B1
        clrf    TRISB           ; portb all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTB           ; clear portb output latches      |B0
        movlw   b'00000001'     ; digit select bits (RA1-RA0)     |B0
        movwf   PORTA           ; select the 'ones' display       |B0
        clrf    swlatch         ; clear switch state latch        |B0
        clrf    swflags         ; clear switch flags              |B0
        clrf    number          ; number = 00                     |B0
;
;  isochronous 8 msec program loop (62.5 Hz display refresh rate)
;
Display
        clrf    PORTB           ; blank the display               |B0
        movf    PORTA,W         ;                                 |B0
        xorlw   b'00000011'     ; flip digit select bits          |B0
        movwf   PORTA           ;                                 |B0
        swapf   number,W        ; W = tens in right nybble        |B0
        btfss   PORTA,1         ; 10's display? yes, skip, else   |B0
        movf    number,W        ; W = ones in right nybble        |B0
        call    segtbl          ; get segment data                |B0
        movwf   PORTB           ; display new digit               |B0
Buttons
        comf    PORTA,W         ; sample active low switches      |B0
        andlw   b'00001100'     ; on RA3 and RA2 pins             |B0
        xorwf   swlatch,W       ; changes (press or release)      |B0
        xorwf   swlatch,F       ; update switch state latch       |B0
        andwf   swlatch,W       ; filter out "new release" bits   |B0
        movwf   swflags         ; save any "new press" bits       |B0
CountUp
        movf    number,W        ;                                 |B0
        addlw   7               ; increment + bcd adjust?         |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; increment only                  |B0
        btfsc   swflags,Up      ; Up press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        movf    number,W        ;                                 |B0
        xorlw   0xA0            ; upper limit 99?                 |B0
        skpnz                   ; no, skip, else                  |B0
        clrf    number          ; reset to 00 (rollover mode)     |B0 <-
CountDn
        movf    number,W        ; lower limit 00?                 |B0
        skpnz                   ; no, skip, else                  |B0
        movlw   0xA0            ; reset to 99 (rollover mode)     |B0 <-
        addlw   -1              ; decrement only?                 |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; decrement + bcd adjust          |B0
        btfsc   swflags,Dn      ; Dn press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        DelayCy(8*msecs-41)     ; precise 8 msec loop timing      |B0
        goto    Display         ; loop                            |B0
;
;  segment data table (caveat, non-boundary tolerant)
;
segtbl
        andlw   0x0F            ; strip off upper nybble          |B0
        addwf   PCL,F           ;                                 |B0
        retlw   b'00111111'     ; "0"   -|-|F|E|D|C|B|A           |B0
        retlw   b'00000110'     ; "1"   -|-|-|-|-|C|B|-           |B0
        retlw   b'01011011'     ; "2"   -|G|-|E|D|-|B|A           |B0
        retlw   b'01001111'     ; "3"   -|G|-|-|D|C|B|A           |B0
        retlw   b'01100110'     ; "4"   -|G|F|-|-|C|B|-           |B0
        retlw   b'01101101'     ; "5"   -|G|F|-|D|C|-|A           |B0
        retlw   b'01111101'     ; "6"   -|G|F|E|D|C|-|A           |B0
        retlw   b'00000111'     ; "7"   -|-|-|-|-|C|B|A           |B0
        retlw   b'01111111'     ; "8"   -|G|F|E|D|C|B|A           |B0
        retlw   b'01101111'     ; "9"   -|G|F|-|D|C|B|A           |B0
;
;  K8LH DelayCy() subsystem 16-bit timing subroutine
;
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract "loop" cycle time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  DelayHi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0
 
        end
See it works
[video=youtube_share;30jcRxCZAY8]http://youtu.be/30jcRxCZAY8[/video]


can you show me your circuit?
 
Try this code I think I pasted it wrong the first time.
When i commented the code changes I deleted part of the code lol.
This works as shown in the short video. Now for ISIS i don't like it and don't use it any more.
It's so much easier to use real hardware and a lot more fun.
Code:
;*************************************************  *****************
;  (C) K8LH 2-Digit Up/Dn Counter, Isochronous Loop Example v2    *
;*************************************************  *****************
  list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
        errorlevel -302
 
       	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

 
 
number  equ     0x20            ; packed BCD, 0x00..0x99
swlatch equ     0x21            ; switch state latch variable
swflags equ     0x22            ; switch flag bits
DelayHi equ     0x23            ; DelayCy() subsystem variable
 
#define Dn      3               ; RA3
#define Up      2               ; RA2
 
;*************************************************  *****************
;
;  K8LH DelayCy() subsystem macro generates four instructions
;
        radix   dec
clock   equ     16               ; clock frequency in Megahertz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
 
DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   DelayHi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm
 
;*************************************************  *****************
;
;  init hardware and program variables
;
        org     0x000
Init
        bsf     STATUS, RP0     ; Select Bank 1
		movlw   0x07
        movwf   CMCON
        movlw   0x07            ; Configure all pins
        movwf   ADCON1          ; as digital inputs 
        movlw   b'00001100'     ;                                      |B1
        movwf   TRISA           ; RA3-RA2 inputs, others outputs  |B1
        clrf    TRISB           ; portb all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTB           ; clear portb output latches      |B0
        movlw   b'00000001'     ; digit select bits (RA1-RA0)     |B0
        movwf   PORTA           ; select the 'ones' display       |B0
        clrf    swlatch         ; clear switch state latch        |B0
        clrf    swflags         ; clear switch flags              |B0
        clrf    number          ; number = 00                     |B0
;
;  isochronous 8 msec program loop (62.5 Hz display refresh rate)
;
Display
        clrf    PORTB           ; blank the display               |B0
        movf    PORTA,W         ;                                 |B0
        xorlw   b'00000011'     ; flip digit select bits          |B0
        movwf   PORTA           ;                                 |B0
        swapf   number,W        ; W = tens in right nybble        |B0
        btfss   PORTA,1         ; 10's display? yes, skip, else   |B0
        movf    number,W        ; W = ones in right nybble        |B0
        call    segtbl          ; get segment data                |B0
        movwf   PORTB           ; display new digit               |B0
Buttons
        comf    PORTA,W         ; sample active low switches      |B0
        andlw   b'00001100'     ; on RA3 and RA2 pins             |B0
        xorwf   swlatch,W       ; changes (press or release)      |B0
        xorwf   swlatch,F       ; update switch state latch       |B0
        andwf   swlatch,W       ; filter out "new release" bits   |B0
        movwf   swflags         ; save any "new press" bits       |B0
CountUp
        movf    number,W        ;                                 |B0
        addlw   7               ; increment + bcd adjust?         |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; increment only                  |B0
        btfsc   swflags,Up      ; Up press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        movf    number,W        ;                                 |B0
        xorlw   0xA0            ; upper limit 99?                 |B0
        skpnz                   ; no, skip, else                  |B0
        clrf    number          ; reset to 00 (rollover mode)     |B0 <-
CountDn
        movf    number,W        ; lower limit 00?                 |B0
        skpnz                   ; no, skip, else                  |B0
        movlw   0xA0            ; reset to 99 (rollover mode)     |B0 <-
        addlw   -1              ; decrement only?                 |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; decrement + bcd adjust          |B0
        btfsc   swflags,Dn      ; Dn press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        DelayCy(8*msecs-41)     ; precise 8 msec loop timing      |B0
        goto    Display         ; loop                            |B0
;
;  segment data table (caveat, non-boundary tolerant)
;
segtbl
        andlw   0x0F            ; strip off upper nybble          |B0
        addwf   PCL,F           ;                                 |B0
        retlw   b'00111111'     ; "0"   -|-|F|E|D|C|B|A           |B0
        retlw   b'00000110'     ; "1"   -|-|-|-|-|C|B|-           |B0
        retlw   b'01011011'     ; "2"   -|G|-|E|D|-|B|A           |B0
        retlw   b'01001111'     ; "3"   -|G|-|-|D|C|B|A           |B0
        retlw   b'01100110'     ; "4"   -|G|F|-|-|C|B|-           |B0
        retlw   b'01101101'     ; "5"   -|G|F|-|D|C|-|A           |B0
        retlw   b'01111101'     ; "6"   -|G|F|E|D|C|-|A           |B0
        retlw   b'00000111'     ; "7"   -|-|-|-|-|C|B|A           |B0
        retlw   b'01111111'     ; "8"   -|G|F|E|D|C|B|A           |B0
        retlw   b'01101111'     ; "9"   -|G|F|-|D|C|B|A           |B0
;
;  K8LH DelayCy() subsystem 16-bit timing subroutine
;
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract "loop" cycle time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  DelayHi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0
 
        end
See it works
[video=youtube_share;30jcRxCZAY8]http://youtu.be/30jcRxCZAY8[/video]


it's working.. thank you very much.. :)
 
Try this code I think I pasted it wrong the first time.
When i commented the code changes I deleted part of the code lol.
This works as shown in the short video. Now for ISIS i don't like it and don't use it any more.
It's so much easier to use real hardware and a lot more fun.
Code:
;*************************************************  *****************
;  (C) K8LH 2-Digit Up/Dn Counter, Isochronous Loop Example v2    *
;*************************************************  *****************
  list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
        errorlevel -302
 
       	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

 
 
number  equ     0x20            ; packed BCD, 0x00..0x99
swlatch equ     0x21            ; switch state latch variable
swflags equ     0x22            ; switch flag bits
DelayHi equ     0x23            ; DelayCy() subsystem variable
 
#define Dn      3               ; RA3
#define Up      2               ; RA2
 
;*************************************************  *****************
;
;  K8LH DelayCy() subsystem macro generates four instructions
;
        radix   dec
clock   equ     16               ; clock frequency in Megahertz
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     usecs*1000      ; cycles/millisecond multiplier
 
DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   DelayHi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm
 
;*************************************************  *****************
;
;  init hardware and program variables
;
        org     0x000
Init
        bsf     STATUS, RP0     ; Select Bank 1
		movlw   0x07
        movwf   CMCON
        movlw   0x07            ; Configure all pins
        movwf   ADCON1          ; as digital inputs 
        movlw   b'00001100'     ;                                      |B1
        movwf   TRISA           ; RA3-RA2 inputs, others outputs  |B1
        clrf    TRISB           ; portb all outputs               |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTB           ; clear portb output latches      |B0
        movlw   b'00000001'     ; digit select bits (RA1-RA0)     |B0
        movwf   PORTA           ; select the 'ones' display       |B0
        clrf    swlatch         ; clear switch state latch        |B0
        clrf    swflags         ; clear switch flags              |B0
        clrf    number          ; number = 00                     |B0
;
;  isochronous 8 msec program loop (62.5 Hz display refresh rate)
;
Display
        clrf    PORTB           ; blank the display               |B0
        movf    PORTA,W         ;                                 |B0
        xorlw   b'00000011'     ; flip digit select bits          |B0
        movwf   PORTA           ;                                 |B0
        swapf   number,W        ; W = tens in right nybble        |B0
        btfss   PORTA,1         ; 10's display? yes, skip, else   |B0
        movf    number,W        ; W = ones in right nybble        |B0
        call    segtbl          ; get segment data                |B0
        movwf   PORTB           ; display new digit               |B0
Buttons
        comf    PORTA,W         ; sample active low switches      |B0
        andlw   b'00001100'     ; on RA3 and RA2 pins             |B0
        xorwf   swlatch,W       ; changes (press or release)      |B0
        xorwf   swlatch,F       ; update switch state latch       |B0
        andwf   swlatch,W       ; filter out "new release" bits   |B0
        movwf   swflags         ; save any "new press" bits       |B0
CountUp
        movf    number,W        ;                                 |B0
        addlw   7               ; increment + bcd adjust?         |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; increment only                  |B0
        btfsc   swflags,Up      ; Up press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        movf    number,W        ;                                 |B0
        xorlw   0xA0            ; upper limit 99?                 |B0
        skpnz                   ; no, skip, else                  |B0
        clrf    number          ; reset to 00 (rollover mode)     |B0 <-
CountDn
        movf    number,W        ; lower limit 00?                 |B0
        skpnz                   ; no, skip, else                  |B0
        movlw   0xA0            ; reset to 99 (rollover mode)     |B0 <-
        addlw   -1              ; decrement only?                 |B0
        skpdc                   ; yes, skip, else                 |B0
        addlw   -6              ; decrement + bcd adjust          |B0
        btfsc   swflags,Dn      ; Dn press? no, skip, else        |B0
        movwf   number          ; update 'number'                 |B0
        DelayCy(8*msecs-41)     ; precise 8 msec loop timing      |B0
        goto    Display         ; loop                            |B0
;
;  segment data table (caveat, non-boundary tolerant)
;
segtbl
        andlw   0x0F            ; strip off upper nybble          |B0
        addwf   PCL,F           ;                                 |B0
        retlw   b'00111111'     ; "0"   -|-|F|E|D|C|B|A           |B0
        retlw   b'00000110'     ; "1"   -|-|-|-|-|C|B|-           |B0
        retlw   b'01011011'     ; "2"   -|G|-|E|D|-|B|A           |B0
        retlw   b'01001111'     ; "3"   -|G|-|-|D|C|B|A           |B0
        retlw   b'01100110'     ; "4"   -|G|F|-|-|C|B|-           |B0
        retlw   b'01101101'     ; "5"   -|G|F|-|D|C|-|A           |B0
        retlw   b'01111101'     ; "6"   -|G|F|E|D|C|-|A           |B0
        retlw   b'00000111'     ; "7"   -|-|-|-|-|C|B|A           |B0
        retlw   b'01111111'     ; "8"   -|G|F|E|D|C|B|A           |B0
        retlw   b'01101111'     ; "9"   -|G|F|-|D|C|B|A           |B0
;
;  K8LH DelayCy() subsystem 16-bit timing subroutine
;
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract "loop" cycle time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  DelayHi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0
 
        end
See it works
[video=youtube_share;30jcRxCZAY8]http://youtu.be/30jcRxCZAY8[/video]

Stop repeating that.. please :) It haunts me at nights.
 
If you construct the circuit on the breadboard with real hardware then it wouldn't blink. This is due to the simulator is not simualting fast enough so the whole thing looks like slow motion on the proteus.

Allen
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top