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.

7 segment display

Status
Not open for further replies.

Chrysostomos

New Member
Hey,
I am using PIC16F84A micro controller. I am trying to program a 7 segment display to count until 9. The code in assembly I wrote for that is as follows: Its not working and i dont know why. Can anyone help me pls ? its quite simple example
#include P16F84A.INC
__config _XT_OSC & _WDT_OFF & _PWRTE_ON

DELAY_COUNT1 EQU H'21'
DELAY_COUNT2 EQU H'22'
DELAY_COUNT3 EQU H'23'
COUNT EQU H'24'



ORG h'0'

clrf PORTA ;clear output latches
clrf PORTB ;

bsf STATUS,5 ;select bank1
movlw B'00000000'
movwf TRISB
movlw D'0' ; setting count value as 9
movwf COUNT
bcf STATUS,5 ;select bank 0


loop
movlw B'11111111'
movlw COUNT
call counter
goto loop

counter
incf COUNT,0
call conversion
movwf PORTB
return

delay
;initialise delay counters
movlw H'FF'
movwf DELAY_COUNT1
movlw H'FF'
movwf DELAY_COUNT2
movlw H'05'
movwf DELAY_COUNT3

delay_loop
decfsz DELAY_COUNT1,F ; inner most loop
goto delay_loop ; decrements and loops until delay_count1=0
decfsz DELAY_COUNT2,F ; middle loop
goto delay_loop
decfsz DELAY_COUNT3,F ; outer loop
goto delay_loop
return

conversion
addwf PCL
retlw B'01000001' ;0
retlw B'11110011' ;1
retlw B'00100101' ;2
retlw B'00001101' ;3
retlw B'00011011' ;4
retlw B'10001001' ;5
retlw B'10000001' ;6
retlw B'01011101' ;7
retlw B'00000001' ;8
retlw B'00011000' ;9
end
 
The code has quite a few issues. So here's a rewrite that replaces the original 'loop' and 'counter' routines.. Not tested but seems ok.

Code:
loop;
movf COUNT,w ;               get pointer
call conversion;             convert to 7 seg bits
movwf PORTB;                 drive 7 seg display
call delay_loop;            make it visible.
incf COUNT,f ;              increment pointer
movf COUNT,w ;               into wreg
sublw .9 ;                   compare to 9 decimal.
skpz ;                       skip next if = to .9, else
goto loop;                   continue counting up
clrf COUNT;                reset pointer/counter if 9 count was reached
goto loop;                 continue display.
 
Status
Not open for further replies.

Latest threads

Back
Top