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.

Help to convert to Anode Display for a 50 V DC Panel Meter...

Status
Not open for further replies.
Hello All

I got this code from internet. Its a good volt meter circuit, I tested. Simple and Locally avilable components. But the code for the Common Cathod Display. Can you someone help to convert it to Common Anode?

And this is the code...


Code:
;==================================================
; 18/01/2013
; Çàãîëîâîê ê ïðîãðàììå òðåõñåãìåíòíîãî àìïåð/âîëüòìåòðà
; ñ âíåøíèì ïåïåêëþ÷àòåëåì ðåæèìà èçìåðåíèÿ.
;==================================================
;
Dev_Freq   EQU   D'4000000'   ; Device Frequency is 4 MHz
;
RESET_V       EQU   0x0000   ; Address of RESET Vector
ISR_V       EQU   0x0004   ; Address of Interrupt Vector
PMEM_END   EQU   0x03FF   ; Last address in Program Memory
;
#define   SKIP_IF_ZERO   btfss   STATUS,Z
#define   SKIP_IF_NOZERO   btfsc   STATUS,Z
#define   SKIP_IF_POSITIVE   btfss   STATUS,C
#define   SKIP_IF_NEGATIVE   btfsc   STATUS,C
;======== ÎÏÐÅÄÅËÅÍÈß =====================
;
;#define       k   .49   ;çíà÷åíèå êîððåêöèè Ò0 äëÿ F=50 Ãö
#define       k   .153   ;çíà÷åíèå êîððåêöèè Ò0 äëÿ F=100 Ãö

;
;ÍÀÇÍÀ×ÅÍÈß ÄËß ÏÎÐÒÎÂ: RA0-âõîä ÀÖÏ; RA3-âõîä ñ ïåðåêëþ÷àòåëÿ
;âñå îñòàëüíûå - âûõîäû, ïîäòÿæêè âûêëþ÷åíû.
;Ïðè íàçíà÷åíèè ïîðòà RC2 êàê âõîä - òî÷êà ãàñèòñÿ
;Ðåçóëüòàò ÀÖÏ - 2-áàéòíûé
#define TRIS_A       b'00001001'   ;
#define TRIS_C_dot_ON   b'00000000'
#define TRIS_C_dot_OFF   b'00000100'
;
#define SW_SENSE   PORTA,3   ;âõîä ïåðåêëþ÷àòåëÿ ðîäà ðàáîò
#define DIGIT_1       PORTC,4   ;êàòîä ñòàðøåãî ðàçðÿäà èíäèêàòîðà
#define DIGIT_2       PORTC,3   ;êàòîä ñðåäíåãî ðàçðÿäà èíäèêàòîðà
#define DIGIT_3       PORTC,2   ;êàòîä ìëàäøåãî ðàçðÿäà èíäèêàòîðà
;
;============ ÏÅÐÅÌÅÍÍÛÅ =========================================
;
   cblock   0x020
   TEMP       ; TEMPorary register
   COUNTER       ;îáùèé ñ÷åò÷èê
   COUNT       ;ñ÷åò÷èêè çàäåðæåê
   COUNT1       ;
;
   CCOUNTER   ;ñ÷åò÷èê ïðåðûâàíèé
;
   D1   ;Ðàçðÿäû èíäèêàòîðà
   D2
   D3
;ðåãèñòðû äëÿ äâîè÷íî-äåñÿòè÷íîãî ïðåîáðàçîâàíèÿ
   DH   ;÷èñëî äëÿ ïðåáîðàçîâàíèÿ bin2bcd
   DL
   ADD_L   ;íàêîïèòåëü ñóììû
   ADD_H
   LED0   ;ðåçóëüòàò ïðåîáðàçîâàíèÿ
   LED1       
   LED2       
   LED3
   LED4
;       
   INDEX   ;óêàçàòåëü äëÿ èíäèêàöèè
;
   WREG_TEMP   ;storage for WREG during interrupt
   STATUS_TEMP   ;storage for STATUS during interrupt
   PCLATH_TEMP   ;storage for PCLATH during interrupt
   FSR_TEMP   ;storage for FSR during interrupt
;
   FLAGS       ;ôëàãè îáùèå
   endc
;
;
#define   mode   FLAGS,0   ;,áèò ðåæèìà ðàáîòû U=1, I=0
;------------------------------------------------------------
;ÎÏÐÅÄÅËÅÍß ÄËß ÈÍÄÈÊÀÖÈÈ
;------------------------------------------------------------
;Ñîîòâåòñòâèå ñåãìåíòàì: PORTA '--ABiCGi'; PORTC '--F123ED'
#define coma   PORTC,2   ;áèò âêëþ÷åíèÿ çàïÿòîé
;
;=======================
;**** Ì À Ê Ð Î Ñ Û ****
;=======================
;------------------------------------------------------------
;Ìàêðîñ ïðîèçâîäèò èíêðåìåíò äâóõáàéòîâîãî ÷èñëà NH,NL
;------------------------------------------------------------
INC2B   MACRO   NH,NL   ;ñòàðøèé áàéò, ìëàäøèé áàéò
   clrf   TEMP   ;èíêðåìåíò
   movlw   1   ;2-õ áàéòîâîãî
   addwf   NL,F   ;÷èñëà
   rlf   TEMP,W   ;
   addwf   NH,f   ;
   ENDM
;------------------------------------------------------------
Bank0       MACRO           ;macro to select data RAM bank 0
       bcf   STATUS,RP0
       ENDM

Bank1       MACRO           ;macro to select data RAM bank 1
       bsf   STATUS,RP0
       ENDM
;------------------------------------------------------------


[end code]

Thanking you ....
 

Attachments

  • avmeter.asm
    10.8 KB · Views: 180
I thought you were done.....

I just success in compilation only. But its only common cathod. its working good.

But I need to do with common Anode display. I try much times..

I just change to -

Code:
       retlw   b'11101011'   ;   ( b'00010100' ; for 1 : this is the original code)

[code end]

I just invert all binary number like that...

But nothing in the display (display OFF.

any other change I can do?
 
schematic?
s96400272.jpg
 
I just invert the avmeter.asm and avmeter.h files. (Invert all the binary number. is it okey or can I do change in the opcode too?
 
The schematic helps a lot... Thank you.

I believe these are the relevant code sections for the 3-digit display;
Code:
LEDTABLE_A
        addwf   PCL,F           ;    --AB-CG- on PORTA
        retlw   b'00110100'     ; 0  --AB-C--
        retlw   b'00010100'     ; 1  ---B-C--
        retlw   b'00110010'     ; 2
        retlw   b'00110110'     ; 3
        retlw   b'00010110'     ; 4
        retlw   b'00100110'     ; 5
        retlw   b'00100110'     ; 6
        retlw   b'00110100'     ; 7
        retlw   b'00110110'     ; 8
        retlw   b'00110110'     ; 9
        retlw   b'00000010'     ;'-'

LEDTABLE_C
        addwf   PCL,F           ;    --F---ED on PORTB
        retlw   b'00100011'     ; 0  --F---ED
        retlw   b'00000000'     ; 1  --------
        retlw   b'00000011'     ; 2
        retlw   b'00000001'     ; 3
        retlw   b'00100000'     ; 4
        retlw   b'00100001'     ; 5
        retlw   b'00100011'     ; 6
        retlw   b'00000000'     ; 7
        retlw   b'00100011'     ; 8
        retlw   b'00100001'     ; 9
        retlw   b'00000000'     ;'-'
Code:
DISPLAY
        movlw   b'00011100'     ; cathodes K1(RC4),K2(RC3),K3(RC2) off
        movwf   PORTC           ; segments D(RC0),E(RC1),F(RC5) off
        clrf    PORTA           ; segments G(RA1),C(RA2),B(RA4),A(RA5) off
        Bank1                   ;
        movlw   TRIS_C_dot_OFF  ;
        movwf   TRISC           ; K3/DP pin (RC2) off (hi-z input)
        Bank0                   ;
;
; ïðîâåðÿåì èíäåêñ èíäèêàòîðîâ
; INDEX=0 - ìëàäøèé ðàçðÿä, ïîðò À
; INDEX=1 - ìëàäøèé ðàçðÿä, ïîðò Ñ
; .......
; INDEX=6 - ïåðåãðóçêà ñ÷åò÷èêà
;
        movf    INDEX,W         ; LEDIndex -> W
        sublw   .5              ; in range, 0 <= index <= 5?
        skpc                    ; yes, skip, else
        clrf    INDEX           ; reset index to 0
;-----------
sel_cathode:                    ; âûáîð îòîáðàæàåìîãî ðàçðÿäà
        movlw   b'00000100'     ;
        andwf   INDEX,W         ; index 4 or 5?
        skpz                    ; no, skip, else
        goto    sel_MSD         ; display most significant digit
        movlw   b'00000010'     ;
        andwf   INDEX,W         ; index 2 or 3?
        skpz                    ; no, skip, else
        goto    sel_CSD         ; display middle digit
sel_LSD
        Bank1                   ; index 0 or 1
        movlw   TRIS_C_dot_ON   ;
        movwf   TRISC           ; make K3/DP (RC2) pin output
        Bank0                   ;
        bcf     DIGIT_3         ; active lo DIGIT_3 (RC2) on
        goto    fire_LSD        ; çàæå÷ü ñåãìåíòû ìëàäøåãî ðàçðÿäà
sel_CSD
        bcf     DIGIT_2         ; active lo DIGIT_2 (RC3) on
        goto    fire_CSD        ; çàæå÷ü ñåãìåíòû ñðåäíåãî ðàçðÿäà
sel_MSD
        bcf     DIGIT_1         ; active lo DIGIT_1 (RC4) on
        goto    fire_MSD        ; çàæå÷ü ñåãìåíòû ñòàðøåãî ðàçðÿäà
;-----------
;
; çàæèãàíèå ñåãìåíòîâ èíäèêàòîðà
;
fire_LSD
        btfss   INDEX,0        ; âûáîð ÷åòâåðêè ñåãìåíòîâ äëÿ îòîáðàæåíèÿ
        goto    fire_LSD_A     ;
fire_LSD_C
        movf    D3,W           ; digit 3, 0..9
        call    LEDTABLE_C     ; get segments D/E/F
        iorwf   PORTC,F        ; put on RC0/RC1/RC5
        goto    display_end    ;
fire_LSD_A
        movf    D3,W           ; digit 3, 0..9
        call    LEDTABLE_A     ; get segments G/C/B/A
        movwf   PORTA          ; put on RA1/RA2/RA4/RA5
        goto    display_end    ;
;
fire_CSD
        btfss   INDEX,0        ; âûáîð ÷åòâåðêè ñåãìåíòîâ äëÿ îòîáðàæåíèÿ
        goto    fire_CSD_A     ;
fire_CSD_C
        movf    D2,W           ; digit 2, 0..9
        call    LEDTABLE_C     ; get segments D/E/F
        iorwf   PORTC,F        ; put on RC0/RC1/RC5
        btfss   mode           ; display decimal point? yes, skip, else
        goto    display_end    ; branch (finish up)
        Bank1                  ; äà, çàñâå÷èâàåì òî÷êó âî 2-ì ðàçðÿäå
        movlw   TRIS_C_dot_ON  ; display decimal point
        movwf   TRISC          ; K3/DP pin (RC2) on (output)
        Bank0                  ;
        bsf     coma           ; turn on K3/DP (RC2) anode
        goto    display_end    ; branch (finish up)
fire_CSD_A
        movf    D2,W           ; digit 2, 0..9
        call    LEDTABLE_A     ; get segments G/C/B/A
        movwf   PORTA          ; put on RA1/RA2/RA4/RA5
        goto    display_end    ; 

fire_MSD
        btfss   INDEX,0        ; âûáîð ÷åòâåðêè ñåãìåíòîâ äëÿ îòîáðàæåíèÿ
        goto    fire_MSD_A     ;
fire_MSD_C
        movf    D1,W           ; digit 1, 0..9
        call    LEDTABLE_C     ; get segments D/E/F
        iorwf   PORTC,F        ; put on RC0/RC1/RC5
        btfsc   mode           ; display decimal point? yes, skip, else
        goto    display_end    ; branch (finish up)
        Bank1                  ; äà, çàñâå÷èâàåì òî÷êó âî 2-ì ðàçðÿäå
        movlw   TRIS_C_dot_ON  ; display decimal point
        movwf   TRISC          ; K3/DP pin (RC2) on (output)
        Bank0                  ;
        bsf     coma           ; turn on K3/DP (RC2) anode
        goto    display_end    ;
fire_MSD_A
        movf    D1,W           ; digit 1, 0..9
        call    LEDTABLE_A     ; get segments G/C/B/A
        movwf   PORTA          ; put on RA1/RA2/RA4/RA5
        goto    display_end    ;
;
display_end
        incf    INDEX,F        ; bump index 0..5 -> 1..6
        RETLW   0              ;
Quite a few changes are necessary. I have not looked at the single digit LED 'A' / 'V' display, yet. More later...

Cheerful regards, Mike
 
Last edited:
Here's my untested first attempt (below). Caveat... There may be errors... I have not had a chance to see if it even assembles correctly.

All of the changes are in the "DISPLAY" section (the two LED segment tables are unchanged).

More later. Mike...
Code:
;
;  display refresh function for Common Anode displays
;
DISPLAY
        movlw   b'00100011'     ; anodes K1(RC4),K2(RC3),K3(RC2) off
        movwf   PORTC           ; segments D(RC0),E(RC1),F(RC5) off
        movlw   b'00110110'     ;
        movwf   PORTA           ; segments G(RA1),C(RA2),B(RA4),A(RA5) off
        movlw   TRISC           ;
        movwf   FSR             ; setup indirect access to TRISC
        movlw   b'00000100'     ; K3/DP pin (RC2) off (hi-z)      |b0
        movwf   INDF            ; trisc = '00000100' RC2 input    |b0
;
;  select and display digit 1, 2, or 3 based on INDEX 0..5
;
        movf    INDEX,W         ; LEDIndex -> W                   |b0
        sublw   .5              ; in range, 0 <= index <= 5?      |b0
        skpc                    ; yes, skip, else                 |b0
        clrf    INDEX           ; reset index to 0                |b0

        btfsc   INDEX,2         ; index 4 or 5? no, skip, else    |b0
        goto    sel_MSD         ; display digit 1                 |b0
        btfsc   INDEX,1         ; index 2 or 3? no, skip, else    |b0
        goto    sel_CSD         ; display digit 2                 |b0

sel_LSD
        movlw   b'00000000'     ; K3/DP (RC2) pin 'output'        |b0
        movwf   INDF            ; trisc = '00000000' RC2 output   |b0
        bsf     DIGIT_3         ; active hi DIGIT_3 (RC2) 'on'    |b0
        btfss   INDEX,0         ;
        goto    fire_LSD_A      ;
fire_LSD_C
        movf    D3,W            ; digit 3, 0..9                   |b0
        call    LEDTABLE_C      ; get segments D/E/F              |b0
        xorwf   PORTC,F         ; clr active lo D/E/F segments    |b0
        goto    display_end     ;
fire_LSD_A                      ;
        movf    D3,W            ; digit 3, 0..9                   |b0
        call    LEDTABLE_A      ; get segments G/C/B/A            |b0
        xorwf   PORTA,F         ; clr active lo G/C/B/A segments  |b0
        goto    display_end     ;

sel_CSD
        bsf     DIGIT_2         ; active hi DIGIT_2 (RC3) 'on'    |b0
        btfss   INDEX,0         ;
        goto    fire_CSD_A      ;
fire_CSD_C                      ;
        movf    D2,W            ; digit 2, 0..9                   |b0
        call    LEDTABLE_C      ; get segments D/E/F              |b0
        xorwf   PORTC,F         ; clr active lo D/E/F segments    |b0
        btfsc   mode            ; dec pt? no, skip, else          |b0
        bcf     INDF,2          ; trisc = '00000000' RC2 output   |b0
        goto    display_end     ; branch (finish up)
fire_CSD_A
        movf    D2,W            ; digit 2, 0..9                   |b0
        call    LEDTABLE_A      ; get segments G/C/B/A            |b0
        xorwf   PORTA,F         ; clr active lo G/C/B/A segments  |b0
        goto    display_end     ;

sel_MSD
        bsf     DIGIT_1         ; active hi DIGIT_1 (RC4) 'on'    |b0
        btfss   INDEX,0         ;
        goto    fire_MSD_A      ;
fire_MSD_C                      ;
        movf    D1,W            ; digit 1, 0..9                   |b0
        call    LEDTABLE_C      ; get segments D/E/F              |b0
        xorwf   PORTC,F         ; clr active lo D/E/F segments    |b0
        btfss   mode            ; dec pt? no, skip, else          |b0
        bcf     INDF,2          ; trisc = '00000000' RC2 output   |b0
        goto    display_end     ;
fire_MSD_A
        movf    D1,W            ; digit 1, 0..9                   |b0
        call    LEDTABLE_A      ; get segments G/C/B/A            |b0
        xorwf   PORTA,F         ; clr active lo G/C/B/A segments  |b0

display_end
        incf    INDEX,F         ; bump index 0..5 -> 1..6
        retlw   0               ;
 

Attachments

  • avmeter(ca).asm
    14 KB · Views: 161
Last edited:
Thanks MIKE...

Its really amaze me... Thank you so much.

Your code working very correct.. Thanks for the complete code.. I will study your code for my future use.... Thanks again.... Chears..
 
Last edited:
Good. Happy to help. Please post a picture of your project and don't be afraid to hit the 'like' button on my post...

Cheerful regards, Mike

<added>
I combined the <avmeter.h> and the <avmeter(ca).asm> files into a single file called AVMeter_CA.asm, attached below...
 

Attachments

  • AVMeter_CA.asm
    19.4 KB · Views: 164
Last edited:
Mike One problem, I detect..

In your programme, Last Digit, segment 'd' and 'f' have some error.. But Proteus simulation is 100% OK....

Please check your code again...

Thanks you..
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top