Counter PIC16F84

xshax

Junior member
  • Mar 9, 2008
    321
    13
    18
    38
    Sri lanka
    ;*****Define Registers*****

    PC equ 02h
    STATUS equ 03h
    PORTA equ 05h
    PORTB equ 06h
    TRISA equ 85h
    TRISB equ 86h
    CounterL equ 0Dh
    CounterH equ 0Eh
    Digit1 equ 10h
    Digit2 equ 11h

    ;*****initialization*****

    bsf STATUS,5 ;Switch to Bank 1
    movlw b’00111001'
    movwf TRISA ;RA0 I/P RA1,2 O/P
    clrf TRISB ;PORT B output
    bcf STATUS,5 ;Switch to Bank 0
    clrf Digit1 ;initilize to zero
    clrf Digit2 ;initilize to zero
    ;**display the first digit**
    Loop bcf PORTA,2 ;disable digit2
    movf Digit1,0 ;get digit1 value
    call Table ;Look Up Table
    movwf PORTB ;Writ the number
    bsf PORTA,1 ;enable digit1

    ;**small delay to display digit1**

    Delay1 decfsz CounterL,1
    goto Delay1

    ;**display the second digit**

    bcf PORTA,1 ;disable digit1
    movf Digit2,0 ;get digit2 value
    call Table ;Look Up Table
    movwf PORTB ;Writ the number
    bsf PORTA,2 ;enable digit2

    ;**small delay to display digit2**

    Delay2 decfsz CounterL,1
    goto Delay2
    btfss PORTA,0 ;Button pressed?
    goto Countup ;If yes Count up
    goto Loop ;else back to Loop

    ;**Update Digit1 and Digit2**

    Countup incf Digit1,1 ;increase Digit1
    movlw D’10' ;load w with ten
    xorwf Digit1,0 ;compare with 10
    btfss STATUS,2 ;if equal result 0
    goto Loop ;else back to Loop
    clrf Digit1 ;make Digit1 = 0
    incf Digit2,1 ;increase Digit1
    movlw D’10' ;load w with ten
    xorwf Digit2,0 ;compare with 10
    btfsc STATUS,2 ;if equal result 0
    clrf Digit1 ;make Digit2 = 0
    goto Loop ;back to Loop

    ;****Look Up Table for bit patterns****

    Table addwf PC,1
    retlw b’00111111' ;Number 0
    retlw b’00000110' ;Number 1
    retlw b’01011011' ;Number 2
    retlw b’01001111' ;Number 3
    retlw b’01100110' ;Number 4
    retlw b’01101101' ;Number 5
    retlw b’01111101' ;Number 6
    retlw b’00000111' ;Number 7
    retlw b’01111111' ;Number 8
    retlw b’01100111' ;Number 9
    end






    vidusara eke giya counter eka hari kamam ne asm kara ganna widihak......?
     

    Attachments

    • counter.jpg
      counter.jpg
      90.9 KB · Views: 65

    electris1

    Member
    Apr 23, 2012
    58
    1
    0
    ;*****Define Registers*****

    PC equ 02h
    STATUS equ 03h
    PORTA equ 05h
    PORTB equ 06h
    TRISA equ 85h
    TRISB equ 86h
    CounterL equ 0Dh
    CounterH equ 0Eh
    Digit1 equ 10h
    Digit2 equ 11h

    ;*****initialization*****

    bsf STATUS,5 ;Switch to Bank 1
    movlw b’00111001'
    movwf TRISA ;RA0 I/P RA1,2 O/P
    clrf TRISB ;PORT B output
    bcf STATUS,5 ;Switch to Bank 0
    clrf Digit1 ;initilize to zero
    clrf Digit2 ;initilize to zero
    ;**display the first digit**
    Loop bcf PORTA,2 ;disable digit2
    movf Digit1,0 ;get digit1 value
    call Table ;Look Up Table
    movwf PORTB ;Writ the number
    bsf PORTA,1 ;enable digit1

    ;**small delay to display digit1**

    Delay1 decfsz CounterL,1
    goto Delay1

    ;**display the second digit**

    bcf PORTA,1 ;disable digit1
    movf Digit2,0 ;get digit2 value
    call Table ;Look Up Table
    movwf PORTB ;Writ the number
    bsf PORTA,2 ;enable digit2

    ;**small delay to display digit2**

    Delay2 decfsz CounterL,1
    goto Delay2
    btfss PORTA,0 ;Button pressed?
    goto Countup ;If yes Count up
    goto Loop ;else back to Loop

    ;**Update Digit1 and Digit2**

    Countup incf Digit1,1 ;increase Digit1
    movlw D’10' ;load w with ten
    xorwf Digit1,0 ;compare with 10
    btfss STATUS,2 ;if equal result 0
    goto Loop ;else back to Loop
    clrf Digit1 ;make Digit1 = 0
    incf Digit2,1 ;increase Digit1
    movlw D’10' ;load w with ten
    xorwf Digit2,0 ;compare with 10
    btfsc STATUS,2 ;if equal result 0
    clrf Digit1 ;make Digit2 = 0
    goto Loop ;back to Loop

    ;****Look Up Table for bit patterns****

    Table addwf PC,1
    retlw b’00111111' ;Number 0
    retlw b’00000110' ;Number 1
    retlw b’01011011' ;Number 2
    retlw b’01001111' ;Number 3
    retlw b’01100110' ;Number 4
    retlw b’01101101' ;Number 5
    retlw b’01111101' ;Number 6
    retlw b’00000111' ;Number 7
    retlw b’01111111' ;Number 8
    retlw b’01100111' ;Number 9
    end






    vidusara eke giya counter eka hari kamam ne asm kara ganna widihak......?
    ithin oya tiyenne. oka tamai asm file eka
     

    electris1

    Member
    Apr 23, 2012
    58
    1
    0
    eke mokak hari aulak wage bn.mplabide eke quick build dnnahama errors godak pennanewane........

    ok.mama menna hex file eka damma.oya FUSE set kerala program kera balanna harida kiyala.

    ** mama oya dapu asm file ekamai oya compile kerala tiyenne.wada keranawada nadda kiyala mama danne naha.hari nam kiyanna.waradi nam eth kiyanna mokada kiyala?niwadu welawaka hadala denna balannam.
     

    Attachments

    • counter.zip
      451 bytes · Views: 137