Hello All.
My goal is to make a 4 digit 7 Segment voltage display. I have learnt several things so far, A/D, Delays, Tables, flash leds, read ports etc...
This is the route I wish to take to learn along the way.
1 Get 7 seg display to count 0-9 in on sec increments.
2 Get 7 seg display to go 0-9 with pot on A/D
3 Get 7 seg display to count 0-99 using an interrupt
And continue along the way until I have the code for a volt meter.
But my code for step one does not work, and I can not work out what is wrong with it.
Please could you have a look and advise.
My goal is to make a 4 digit 7 Segment voltage display. I have learnt several things so far, A/D, Delays, Tables, flash leds, read ports etc...
This is the route I wish to take to learn along the way.
1 Get 7 seg display to count 0-9 in on sec increments.
2 Get 7 seg display to go 0-9 with pot on A/D
3 Get 7 seg display to count 0-99 using an interrupt
And continue along the way until I have the code for a volt meter.
But my code for step one does not work, and I can not work out what is wrong with it.
Please could you have a look and advise.
Code:
;******************************************************************************
; *
; Filename: 7 Seg Count.asm *
;******************************************************************************
; Segment 1 Enable (RA2) 1 18 (RA1) _A_ *
; Segment 2 Enable (RA3) 2 17 (RA0) F| | B *
; (RA4) 3 16 (RA7) F|_G_| B *
; (RA5) 4 15 (RA6) E| | C *
; (VSS) 5 14 (VDD) E|_ _| C *
; Seg G (RB0) 6 13 (RB7) Seg DP D
; Seg F (RB1) 7 12 (RB6) Seg A
; Seg E (RB2) 8 11 (RB5) Seg B
; Seg D (RB3) 9 10 (RB4) Seg C
;******************************************************************************
; *
; Revision History: 0.1 *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST p=16F88 ; list directive to define processor
#INCLUDE <P16F88.INC> ; processor specific variable definitions
ERRORLEVEL 0, -302 ;suppress bank selection messages
;------------------------------------------------------------------------------
; CONFIGURATION WORD SETUP
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_OFF & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
CBLOCK 0x20 ;GPR variable registers allocated contiguously
Ones
Tens
d1
d2
d3
ENDC
RESET ORG 0x0000 ; processor reset vector
movlw 0x07
movwf CMCON ;turn comparators off
bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movlw b'01100000' ;Set up clock speed mhz4
movwf OSCCON ;
movlw b'11110011' ;set ra2&3 to digital
movwf ANSEL
movlw b'11110011' ;set RA2&3 to output
movwf TRISA
bcf STATUS, RP0
clrf PORTB
clrf PORTA
bsf PORTA,2
goto START ; go to beginning of program
START
Count Call Delay
One incf Ones,f ;increment file Ones (add 1 to file Ones)
movfw Ones ;Move file Ones to W register
Call Table
movwf PORTB
sublw .10 ;Subtract '0x0A' '.10' '1010' from W register
btfss STATUS,Z ;Check If 0. If Z=1 Skip next instruction. If Z=0 continue
goto Count ;Result is not 0 goto one
clrf Ones ;File Ones has reached 10, Clear file to 0
;Ten incf Tens,f ;increment file Tens (add 1 to file Tens)
; movfw Tens ;Move file Ones to W register
; sublw .10 ;Subtract '0x0A' '.10' '1010' from W register
; btfss STATUS,Z ;Check If 0. If Z=1 Skip next instruction. If Z=0 continue
; goto Count ;
; clrf Tens ;File Tens has reached 10, Clear file to 0
goto Count ;
Table ADDWF PCL, f ;data table for bit pattern
retlw b'01111110' ;0
retlw b'10110000' ;1
retlw b'01101101' ;2
retlw b'11111001' ;3
retlw b'00110011' ;4
retlw b'11011011' ;5
retlw b'01011111' ;6
retlw b'11110000' ;7
retlw b'01111111' ;8
retlw b'11110011' ;9
return
Delay ;999990 cycles
movlw .7
movwf d1
movlw .47
movwf d2
movlw .3
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;6 cycles
goto $+1
goto $+1
goto $+1
;4 cycles (including call)
return
GOTO$
END