Форум Микро-Чип
Поиск и заказ электронных компонентов
 

Вернуться   Форум Микро-Чип > Продукция MICROCHIP

Продукция MICROCHIP Технические вопросы по всей продукции Microchip

Ответ
 
Опции темы Опции просмотра
Старый 24.12.2011, 12:47   #1
zaman
Member
 
Регистрация: 05.09.2009
Возраст: 29
Сообщений: 62
Вес репутации: 100/39
zaman will become famous soon enoughzaman will become famous soon enough
По умолчанию PIC16F628 F-meter

Помогите поправить код для счета частоты с внешним делителем на 256 и временем измерения 0,1с

Код:
; Pic Counter
; Version: 2.1(10MHz)
; This version for the PIC16F628(A) (and probably PIC16F627)
; Clock frequency 10.000000MHz 
; Instruction cycle time = 0.400000 microseconds. (1/10)*4

;This code is licenced under the GNU GENERAL PUBLIC LICENSE version 2. 
;See the text file 'COPYING' for details.

;*********************************************************************
;Changes  
; First release 21 Jul 2006

;10 Oct. 2006
;Fix annoying 'not in bank0' warning message.
;Slight mod to avoid PIC interrupt vector (0x05).

;12 Oct. 2006
;Increase delay after CLEAR and HOME. To allow sluggish- 
;display modules to catch up

;23 Nov. 2007 
;Modifications for RadCom Homebrew Jan. 2008
;
;Changed count gate mechanism 
;Bumped version number to 2.0 
;
;Added 100ms gate time option

;8 Dec. 2007
;Extensive rewrite. Added input A/B switching and four 
;gate time options

;15 Dec. 2008
;Changed gate time routines to work with 10.000MHz clock. 
;*********************************************************************



    ERRORLEVEL -302        ;Get rid of annoying 'not in bank0' warning
    LIST    P=16f628
        
    __CONFIG    _HS_OSC & _PWRTE_ON & _WDT_OFF & _LVP_OFF
    
    include p16f628.inc
    
count1    equ    0x20
count2    equ    0x21
count3    equ    0x22
count4    equ    0x23
byte0    equ    0x24
byte1    equ    0x25
byte2    equ    0x26
byte3    equ    0x27
r0    equ    0x28
r1    equ    0x29
r2    equ    0x2a
r3    equ    0x2b
r4    equ    0x2c
chr    equ    0x2d
temp    equ    0x2e
count    equ    0x2f
rs    equ    1
ena    equ    0
LED    equ    2
gate    equ    3
gatesel equ    0
inp_sel    equ    3
on_sec    equ    1





;******** MAIN PROGRAM *********

    org    0x00        ;Start here.
    goto    Start
    
Start    org    0x05
    movlw    0x07
    movwf    CMCON        ;Comparator - i/o pin setup     
    bsf    3,5        ;Switch to f register page 1     
    movlw    0xf0        ;Configure PIC I/O pins
    movwf    PORTA        ;PORTA 0,1,2  outputs
    movlw    0x0f        ;PORTB 4 to 7 = outputs            
    movwf    PORTB

    movlw    0x67
    movwf    OPTION_REG    ;Prescaler /256, PORTB pull up dis.
    bcf    3,5        ;Switch to f register page 0    
    clrf    PORTA
    clrf    PORTB
    
    
    call    lcdinit        ;Initialise LCD module


cnt_agn    bcf    PORTA,2        ;Close counter gate. D flip-flop Clear pin.
    
    clrf    byte3        ;Reset count registers. This resets the -
    clrf    byte2        ;counter to zero before the next count begins.
    clrf    byte1
    clrf    byte0
    
    bcf    INTCON,T0IF    ;Reset timer0 overflow/interrupt flag. This flag -
                ;shows when the timer/counter overflows. 
                
    clrf    TMR0        ;Reset timer0 (including prescaler)
    

    btfss    PORTB,on_sec
    goto    ONSEC


;********* THE COUNT **********
;=========   prescaler 256  ================================
BIGP   






    goto    cnt_agn        ;all done, start again

;------------------------------------------------------------------------------

HFfast    bsf    3,5        ;Switch to f register page 1
    bsf    PORTA,gate    ; Make misnamed pin an input!
    bcf    3,5        ;Back to page 0    
 
    bsf    PORTA,2        ;Disable 74F74 clear pin to open gate
    nop
    

    call    tenth 
    call    tenth
    call    tenth
    call    tenth
    movlw    0x01
    movwf    count1
lp201    decfsz    count1,f
    goto    lp201
    nop
    nop


    bcf    PORTA,2        ;Close gate at precisely 400mS.

    bsf    3,5        ;Switch to f register page 1
    bcf    PORTA,gate    ;Make misnamed pin an output!!!
    bcf    3,5        ;Back to page 0    


    call    getcnt        ;Get count result (including PIC prescaler)
    call    b2_bcd        ;Convert count to packed BCD
    
    movlw    0x30        
    movwf    temp        ;Amount to add to convert to ascii
    
                ;As all numbers are BCD (1 to 9),
                ;they can be converted to ASCII by 
                ;simply adding 0x30 to each digit. 
                
    movf    r4,w        ;Check the first digit for a leading zero
    andlw    0x0f
    btfss    STATUS,Z
    goto    digi1        ;No LZ, display full freq.
    swapf    r3,w        ;Check the second digit for leading zero.
    andlw    0x0f
    btfss    STATUS,Z
    goto    digi2
    goto    digi3
    
digi1    movf    r4,0        ;Get first bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit'    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

digi2    swapf    r3,0        ;Get 2nd bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

digi3    movf    r3,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

    
    swapf    r2,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    
    movlw    '.'        ;Decimal point.
    call    display    

    movf    r2,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display

    swapf    r1,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r1,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display
    
    movlw    '.'
    call    display    
    

    swapf    r0,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r0,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display        ;Display last digit (1hz)
    
    movlw    ' '        ;Write MHz after freq.
    call    display
    movlw    'M'
    call    display
    movlw    'H'
    call    display
    movlw    'z'
    call    display
    movlw    ' '        
    call    display
    movlw    ' '
    call    display
    
    
    call    line2        ;Move to second line of LCD.
    movlw    'G'
    call    display
    movlw    'T'
    call    display
    movlw    '='
    call    display
    movlw    '0'
    call    display
    movlw    '.'
    call    display
    movlw    '4'
    call    display
    movlw    ' '
    call    display
    movlw    ' '
    call    display
    movlw    'P'
    call    display
    movlw    'S'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    ':'
    call    display
    movlw    '4'
    call    display
    call    home    
    goto    cnt_agn        ;all done , start again


;=====================================================================
UHF    btfsc    PORTB,gatesel
    goto    UHFlong

    bsf    3,5        ;Switch to f register page 1
    bsf    PORTA,gate    ; Make misnamed pin an input!
    bcf    3,5        ;Back to page 0    
 
    call    one28 

    movlw   2        ;Correct for slight error
    movwf    count1
lp51    decfsz    count1,f
    goto    lp51
    nop

    bcf    PORTA,2        

    bsf    3,5        ;Switch to f register page 1
    bcf    PORTA,gate    ;Close gate at precisely 1.280 seconds.
    bcf    3,5        ;Back to page 0
    
    call    getcnt    ;Get count result (including prescaler). 
    call    b2_bcd        ;Convert count to packed BCD.
    
    movlw    0x30
    movwf    temp        ;Amount to add to convert to ascii
    
    movf    r4,w        ;Check the first digit for a leading zero
    andlw    0x0f
    btfss    STATUS,Z
    goto    di1a        ;No LZ, display full freq.
    swapf    r3,w        ;Check the second digit for leading zero.
    andlw    0x0f
    btfss    STATUS,Z
    goto    di2a
    movf    r3,w        ;Check third digit for lz.
    andlw    0x0f
    btfss    STATUS,Z
    goto    di3a
    swapf    r2,w        ;And so on......
    andlw    0x0f
    btfss    STATUS,Z
    goto    di4a
    goto    di5a
    
di1a    movf    r4,0        ;Get first bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit'    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

di2a    swapf    r3,0        ;Get 2nd bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

di3a    movf    r3,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it
    
di4a    swapf    r2,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    
di5a    movf    r2,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display
    
    movlw    '.'        ;Decimal point.
    call    display

    swapf    r1,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it

    movf    r1,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display
    

    swapf    r0,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it

    movlw    '.'        ;Decimal point.
    call    display    

    movf    r0,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display        ;Display last digit (1hz)
    
    movlw    ' '        ;Write MHz after freq.
    call    display
    movlw    'M'
    call    display
    movlw    'H'
    call    display
    movlw    'z'
    call    display
    movlw    ' '        
    call    display
    movlw    ' '
    call    display
    

    
    call    line2        ;Move to second line of LCD.
    movlw    'G'
    call    display
    movlw    'T'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    '.'
    call    display
    movlw    '2'
    call    display
    movlw    '8'
    call    display
    movlw    ' '
    call    display
    movlw    'P'
    call    display
    movlw    'S'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    '2'
    call    display
    movlw    '8'
    call    display
    call    home    
    goto    cnt_agn        ;all done, start again

;=====================================================================
UHFlong bsf    3,5        ;Switch to f register page 1
    bsf    PORTA,gate    ;Gate open.
    bcf    3,5        ;Back to page 0    
    
    movlw    0x0A
    movwf    temp
ten    call    one28
    decfsz    temp,f
    goto    ten
    movlw    0x1C
    movwf    count1
lp307    decfsz    count1,f
    goto    lp307
    nop
    bsf    3,5        ;Switch to f register page 1
    bcf    PORTA,gate    ;Gate closed at 12.8S
    bcf    3,5        ;Back to page 0
    
    call    getcnt    ;Get count result (including prescaler). 
    call    b2_bcd        ;Convert count to packed BCD.
    
    movlw    0x30        
    movwf    temp        ;Amount to add to convert to ascii
    
                ;As all numbers are BCD (1 to 9),
                ;they can be converted to ASCII by 
                ;simply adding 0x30 to each digit. 
                
    movf    r4,w        ;Check the first digit for a leading zero
    andlw    0x0f
    btfss    STATUS,Z
    goto    dt1        ;No LZ, display full freq.
    swapf    r3,w        ;Check the second digit for leading zero.
    andlw    0x0f
    btfss    STATUS,Z
    goto    dt2
    goto    dt3
    
dt1    movf    r4,0        ;Get first bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit'    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

dt2    swapf    r3,0        ;Get 2nd bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

dt3    movf    r3,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

    
    swapf    r2,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    
    movlw    '.'        ;Decimal point.
    call    display    

    movf    r2,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display

    swapf    r1,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r1,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display
    
    movlw    '.'        
    call    display        
    

    swapf    r0,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r0,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display        ;Display last digit (1hz)
    
    movlw    ' '        ;Write MHz after freq.
    call    display
    movlw    'M'
    call    display
    movlw    'H'
    call    display
    movlw    'z'
    call    display
    movlw    ' '        
    call    display
    movlw    ' '
    call    display
    
    
    call    line2        ;Move to second line of LCD.
    movlw    'G'
    call    display
    movlw    'T'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    '2'
    call    display
    movlw    '.'
    call    display
    movlw    '8'
    call    display
    movlw    ' '
    call    display
    movlw    'P'
    call    display
    movlw    'S'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    '2'
    call    display
    movlw    '8'
    call    display
    call    home    
    goto    cnt_agn        ;all done , start again    


;=====================================================================

ONSEC:    bsf    3,5        ;Switch to f register page 1
    bsf    PORTA,gate    ;open gate, start counting ......
    bcf    3,5        ;Back to page 0    
    
    call    onesec 
    
    bsf    3,5        ;Switch to f register page 1
    bcf    PORTA,gate    ;Close gate at precisely one second.
    bcf    3,5        ;Back to page 0    
    


    movf    TMR0,w        ;Get the value in TMR0
    movwf    byte1        ;Store it
    
                        ;Now for the trickery    
                
    clrf    temp
    
clk_agn1    incf    temp,f          ;Increase pulse count
    bsf    PORTA,gate    ;Send clock pulse to TMR0 -
    nop            ; input (pin 3)
    bcf    PORTA,gate
    movf    TMR0,w        ;Get the value in TMR0
    subwf    byte1,w        ;Check if it has changed as a 
    btfsc    STATUS,Z    ;result of the clock pulse
    goto    clk_agn1        ;No change, try again......
    comf    temp,f        ;Yes, the prescaler has overflowed.
    incf    temp,w        ;Negate the pulse count and -        
    movwf    byte0        ;store it in byte0
    
done    call    b2_bcd        ;Convert count to bcd     
    
    call    home        ;'Home' display before writing. 
    
    
    movlw    0x30        
    movwf    temp        ;Amount to add to convert to ascii
    
                ;As all numbers are BCD (1 to 9),
                ;they can be converted to ASCII by 
                ;simply adding 30HEX to each digit. 
                
    movf    r4,w        ;Check the first digit for a leading zero
    andlw    0x0f
    btfss    STATUS,Z
    goto    dig11        ;No LZ, display full freq.
    swapf    r3,w        ;Check the second digit for leading zero.
    andlw    0x0f
    btfss    STATUS,Z
    goto    dig21
    goto    dig31
    
dig11    movf    r4,0        ;Get first bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit'    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

dig21    swapf    r3,0        ;Get 2nd bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit    
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

dig31    movf    r3,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w        ;Convert to ascii (add 0x30)
    call    display        ;Display it

    movlw    '.'        ;Decimal point.
    call    display    
    
    swapf    r2,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r2,0        ;Get other bcd digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display

    swapf    r1,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    
    movlw    ','        ;Ok John
    call    display        ;I'll stick in a comma. 

    movf    r1,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display
    

    swapf    r0,0        ;Get next digit
    andlw    0x0f        ;Mask off other packed bcd digit
    addwf    temp,w
    call    display        ;Display it
    

    movf    r0,0        ;Get other bcd digit
    andlw    0x0f
    addwf    temp,w
    call    display        ;Display last digit (1hz)
    
    movlw    ' '        ;Write MHz after freq.
    call    display
    movlw    ' '
    call    display
    movlw    'H'
    call    display
    movlw    'z'
    call    display
    movlw    ' '        
    call    display
    movlw    ' '
    call    display
    
    call    line2        ;Move to second line of LCD.
    movlw    'G'
    call    display
    movlw    'T'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    '.'
    call    display
    movlw    '0'
    call    display
    movlw    ' '
    call    display
    movlw    ' '
    call    display
    movlw    'P'
    call    display
    movlw    'S'
    call    display
    movlw    '='
    call    display
    movlw    '1'
    call    display
    movlw    ':'
    call    display
    movlw    '1'
    call    display
    
    call    home


    goto    cnt_agn        ;all done , start again    

;***********************************************
;****** Subroutines begin here *****************
;********* This subroutine recovers and stores the full 32 bit count ********** 
getcnt    movf    TMR0,w        ;Get the value in TMR0
    movwf    byte1        ;Store it
                
    clrf    temp
    
clk_agn    incf    temp,f          ;Increase pulse count
    bsf    PORTA,gate    ;Send clock pulse to TMR0 -
    nop            ; input (pin 3)
    bcf    PORTA,gate
    movf    TMR0,w        ;Get the value in TMR0
    subwf    byte1,w        ;Check if it has changed as a 
    btfsc    STATUS,Z    ;result of the clock pulse
    goto    clk_agn        ;No change, try again......
    comf    temp,f        ;Yes, the prescaler has overflowed.
    incf    temp,w        ;Negate the pulse count and -        
    movwf    byte0        ;store it in byte0
    return            ;* The full 32 bit count result is now stored in -
                ; byte0, byte1, byte2 and byte3. 


;******** DELAY LOOP 1 SECOND ***********
onesec    movlw    0x07            ;1S delay loop        
    movwf    count1                       
c1    movlw    0x60                   
    movwf    count2                  
c2    movlw    0xE8
    movwf    count3 
c3    call    ovcount            ;Count number of rtcc overflows                 
    decfsz    count3,1
    goto    c3
    decfsz    count2,1
    goto    c2
    decfsz    count1,1
    goto    c1
    movlw    0xAF
    movwf    count1
c4    call    ovcount
    decfsz    count1,1
    goto    c4
        return
;****************************************        

    
    
;******** DELAY LOOP 1.28 SECOND ***********
one28    movlw    0x07            ;1.28S delay loop        
    movwf    count1                       
a1    movlw    0x7C                   
    movwf    count2                  
a2    movlw    0xE6
    movwf    count3 
a3    call    ovcount            ;Count number of rtcc overflows                 
    decfsz    count3,1
    goto    a3
    decfsz    count2,1
    goto    a2
    decfsz    count1,1
    goto    a1
    movlw    0x8C
    movwf    count1
a4    call    ovcount
    decfsz    count1,1
    goto    a4
    nop
    nop
        return
;****************************************

;******** DELAY LOOP 0.1 SECOND ***********
tenth    movlw    0x07            ;0.1S delay loop        
    movwf    count1                       
b1    movlw    0x3D                   
    movwf    count2                  
b2    movlw    0x24
    movwf    count3 
b3    call    ovcount            ;Count number of rtcc overflows                 
    decfsz    count3,1
    goto    b3
    decfsz    count2,1
    goto    b2
    decfsz    count1,1
    goto    b1
    movlw    0x8F
    movwf    count1
b4    call    ovcount
    decfsz    count1,1
    goto    b4
    movlw    0x05
    movwf    count1
b5    decfsz    count1,1
    goto    b5
    return
;****************************************

;********* COUNT RTCC OVERFLOWS *** 11 CYCLES  ***********
ovcount    btfsc    INTCON,T0IF    ; RTCC overflow flag
    goto    ov1
    nop            ; No overflow.
    nop            ; Lets waste some time.......
    nop
    nop
    nop
    nop
    nop    
    return    
    
ov1    incf    byte2,f    ; RTCC overflow, add 1 to highest byte
    btfsc    STATUS,Z    ; Has h_byte overflowed
    goto    ov2
    bcf    INTCON,T0IF    ; Reset flag
    nop
    nop
    return
    
ov2    incf    byte3,f    ; Add 1 to highest byte
    bcf    INTCON,T0IF
    return
    
;********************************************************************

    
    
    
    
;******** DELAY LOOP ********
; **** Calls ms100 **********

deci    movwf    count4        ;Delay 100mS x contents of W
nxt6    call    ms100
    decfsz    count4,1
    goto    nxt6
    return
;*****************************    
    
    
    
;******** DELAY LOOP 100MS ***********
ms100    movlw    0x09            ;100 mS delay loop        
    movwf    count1                ;including call/return
l1    movlw    0x50                    ;10.240MHz
    movwf    count2                  
l2    movlw    0x75
    movwf    count3                  
l3    decfsz    count3,1
    goto    l3
    decfsz    count2,1
    goto    l2
    decfsz    count1,1
    goto    l1
    movlw    0x77
    movwf    count1
lp99    decfsz    count1,1
    goto    lp99
    nop
        return
;****************************************    



;******** DELAY LOOP 200 MICRO SEC. *************
delay    movlw   0xa9         ; Delay loop 200 microsec
        movwf   count1         ; including call/return
nxt5    decfsz  count1,1    ; 10.240MHz
        goto    nxt5   
        return
;*************************************************

;*********** DELAY LOOP 2mS ***********************
ms2    movlw    0x0c         ; Delay 2mS
    movwf    count1
lp15    movlw    0x8c
    movwf    count2
lp16    decfsz    count2,1
    goto    lp16
    decfsz    count1,1
    goto    lp15
    return           
;**************************************************
    

    
;*********** INITIALISE LCD MODULE 4 BIT MODE *******************
lcdinit    call    ms100        ;wait for lcd module hardware reset
    bcf    PORTA,rs        ;register select low
    bcf    PORTA,ena        ;enable line low
    
    movlw    0x30
    movwf    PORTB        ;8 bit mode
    bsf    PORTA,ena       ;ena high
    nop
    nop                     ;more than 470 ns
    bcf    PORTA,ena    ;ena low
    call    ms100           ;wait for display to catch up


    movlw    0x30
    movwf    PORTB        ;8 bit mode
    bsf    PORTA,ena       ;ena high
    nop
    nop                     ;more than 470 ns
    bcf    PORTA,ena    ;ena    low
    call    delay           ;wait for display to catch up

    movlw    0x30
    movwf    PORTB        ;8 bit mode
    bsf    PORTA,ena       ;ena high
    nop                     ;more than 470 ns
    nop
    bcf    PORTA,ena    ;ena    low
    call    delay           ;wait for display to catch up


    movlw    0x20
    movwf    PORTB        ;4 bit mode
    bsf    PORTA,ena       ;ena high
    nop                     ;more than 470 ns
    nop
    bcf    PORTA,ena    ;ena    low
    call    delay           ;wait for display

    movlw    0x0c        ;display on
    call    comd
    call    delay        
    
    movlw    0x06        ;entry mode set
    call    comd
    call    delay

    movlw    0x01        ;clear display
    call    comd
    call    ms2
    call    home
    return
;**********************************************************
    
    
;******* comd/display  ******************
; Sends data to LCD display (4 BIT MODE)   

comd    bcf    PORTA,rs    ;Send command to LCD module
    goto    cm
display    bsf    PORTA,rs    ;Send character to LCD module
cm    movwf    chr        ;store char to display
    andlw    0xf0        ;mask off lower 4 bits
    movwf    PORTB        ;send data to display        
    bsf    PORTA,ena    ;ena high
    nop            
    bcf    PORTA,ena    ;ena low 

    movlw   0xaa        ;delay loop
        movwf   count1     
dl3        decfsz  count1,1
        goto    dl3    

    movf    chr,0        ;get char again 
    andlw    0xf0        ;mask off lower 4 bits
    swapf    chr,0           ;swap upper and lower nibbles (4 bit mode)
    movwf    PORTB        ;send data to display    
    bsf    PORTA,ena    ;ena high
    nop            
    bcf    PORTA,ena    ;ena low

    movlw   0xaa         ;delay loop
        movwf   count1     
dl4        decfsz  count1,1
        goto    dl4      
    return    
;********************************************************************

;************ MOVE TO START OF LINE 2 *****************
line2    movlw    0xc0        ;Address for second line of display
    call    comd
    call    delay
    return
;******************************************************

              

;************ CLEAR DISPLAY ***************************

clear    movlw    0x01        ;Command to clear display
    call    comd
    call    ms2        ;Longer delay needed when clearing display
    call    ms2
    return
;******************************************************    


;*********** MOVE TO HOME *****************************
home    movlw    0x02        ;Command to 'home' display.
    call    comd
    call    ms2
    call    ms2
    return
;******************************************************


;******* CONVERT 24 BIT BIN TO PACKED BCD **********

b2_bcd    bcf    STATUS,C
    movlw    0x20
    movwf    count
    clrf    r0
    clrf    r1
    clrf    r2
    clrf    r3
    clrf    r4
loop16    rlf    byte0,f
    rlf    byte1,f
    rlf    byte2,f
    rlf    byte3,f
    rlf    r0,f
    rlf    r1,f
    rlf    r2,f
    rlf    r3,f
    rlf    r4,f

    decfsz    count,1
    goto    adjdec
    retlw    0 

adjdec    movlw    r4
    movwf    FSR 
    call    adjbcd
    
    movlw    r3
    movwf    FSR 
    call    adjbcd

    movlw    r2
    movwf    FSR 
    call    adjbcd

    movlw    r1
    movwf    FSR
    call    adjbcd

    movlw    r0
    movwf    FSR
    call    adjbcd

    goto    loop16

adjbcd    movlw    0x03
    addwf    0,w
    movwf    temp
    btfsc    temp,3
    movwf    0
    movlw    0x30
    addwf    0,w
    movwf    temp
    btfsc    temp,7
    movwf    0
    return    

;****************************************
    
    
    end
zaman вне форума   Ответить с цитированием
Старый 24.12.2011, 13:02   #2
kazbek
Member
 
Аватар для kazbek
 
Регистрация: 30.09.2011
Сообщений: 59
Вес репутации: 126/31
kazbek will become famous soon enoughkazbek will become famous soon enough
По умолчанию Re: PIC16F628 F-meter

А приаттачить нельзя было исходник ?
kazbek вне форума   Ответить с цитированием
Старый 26.12.2011, 09:52   #3
Sameman
Banned
 
Регистрация: 23.06.2011
Сообщений: 82
Вес репутации: 22/0
Sameman is on a distinguished road
Question Re: PIC16F630 F-meter, разделка майна в Си.

Хоть и не очень понимаю в этой программе, но скоро придёться заняться подобным. А никак нельзя подобную(на С) разделить на части? Чтобы ввод-вывод в одном файле, математика, временные интервалы, LCD-дисплей в других? А в майне их собрать, как надо?
Sameman вне форума   Ответить с цитированием
Ответ


Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 
Опции темы
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Электронный калькулятор на PIC16f628. Это ведь так просто. dj_topper Вопросы начинающих 10 19.04.2009 18:35
Запись мелодий в PIC16f628 vanish Продукция MICROCHIP 23 18.12.2008 23:10
Помогите не могу прошить PIC16F628 программатор WILLEPROM FARGYS Продукция MICROCHIP 13 02.07.2008 15:46
Помогите с PWM на pic16f628 djdiablo Продукция MICROCHIP 22 24.01.2008 15:00
переход с PIC16F628 на pic16F628A jkobi Продукция MICROCHIP 11 22.07.2007 16:07


Часовой пояс GMT +3, время: 04:38.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd. Перевод: zCarot