Hello again, the code below works on isis and it displays 0000 to 1023 depending on the voltage input of RA4 0-5v
However when I test it on my breadboard the ADC result displayed remains fixed i.e.
When I release from reset and RA4 is at 0v is will show 0000.
If I change the RA4 input to 5v (via pot) nothing happens unless I reset again and 1023 is shown.
Please point me in the right direction. (the connection on the breadboard are all ok)
Once again many thanks
However when I test it on my breadboard the ADC result displayed remains fixed i.e.
When I release from reset and RA4 is at 0v is will show 0000.
If I change the RA4 input to 5v (via pot) nothing happens unless I reset again and 1023 is shown.
Please point me in the right direction. (the connection on the breadboard are all ok)
Once again many thanks
Code:
;******************************************************************************
; *
; Filename: 7 Seg ADC 10-Bit Multiplex.asm *
;******************************************************************************
; (RA2)1 18(RA1)Display 1 Enable _A_ *
; (RA3)2 17(RA0)Display 2 Enable F| | B *
; ADC Input (RA4)3 16(RA7)Display 3 Enable F|_G_| B *
; 10k to Vdd (RA5)4 15(RA6)Display 4 Enable 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: 1.0 *
; Read 10bit of ADC convert to decimal and display 0-1023 using TMR0 *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; 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
;------------------------------------------------------------------------------
#Define DispThou PORTA,1
#Define DispHund PORTA,0
#Define DispTens PORTA,7
#Define DispOnes PORTA,6
__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
W_Temp ;Temporay files for Interrupt
S_Temp
PC_Temp
NumH
NumL
TenK
Thou
Hund
Tens
Ones
ThouData
HundData
TensData
OnesData
disp
endc
RESET ORG 0x0000 ; processor reset vector
goto Main
ORG 0x0004
INTR movwf W_Temp ;Copy W to TEMP register
swapf STATUS, w ;Swap status to be saved into W
clrf STATUS ;bank 0, regardless of current bank, Clears IRP,RP1,RP0
movwf S_Temp ;Save status to bank zero STATUS_TEMP register
movf PCLATH, w ;Only required if using page 1
movf PC_Temp ;Save PCLATH into W
clrf PCLATH ;Page zero, regardless of current page
bcf INTCON,2 ;Reset TMR0 Overflow Flag
btfsc DispOnes
goto Dis1
btfsc DispTens
goto Dis4
btfsc DispHund
goto Dis3
btfsc DispThou
goto Dis2
Dis1
clrf PORTA
movfw ThouData
movwf PORTB
bsf DispThou
goto Exit
Dis2
clrf PORTA
movfw HundData
movwf PORTB
bsf DispHund
goto Exit
Dis3
clrf PORTA
movfw TensData
movwf PORTB
bsf DispTens
goto Exit
Dis4
clrf PORTA
movfw OnesData
movwf PORTB
bsf DispOnes
goto Exit
Exit movf PC_Temp, w ;Restore PCLATH
movwf PCLATH ;Move W into PCLATH
swapf S_Temp, w ;Swap STATUS_TEMP register into W
movwf STATUS ;Move W into STATUS register
swapf W_Temp, f ;Swap W_TEMP
swapf W_Temp, w ;Swap W_TEMP into W
retfie
Main bcf STATUS,RP0 ;setbank0
clrf PORTA ;set PORTB ouputs low
clrf PORTB ;set PORTA ouputs low
CLRF OnesData
clrf TensData
clrf HundData
clrf ThouData
bsf STATUS,RP0 ;setbank1
movlw b'11010010'
movwf OPTION_REG
movlw 0x07
movwf CMCON ;turn comparators off (WAS NOT INSIDE BANK 1)
movlw b'01100000' ;Set up clock speed mhz4
movwf OSCCON
movlw b'00010000' ;set RA4 to analog 1=analog 0=digital
movwf ANSEL
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movlw b'00010000' ;set port A inputs/outputs 1=input 0=output
movwf TRISA
movlw b'10100000' ;set up interrupt
movwf INTCON
movlw b'10000000'
movwf ADCON1 ;set ADC Res format
bcf STATUS,RP0 ;setbank0
movlw b'01100001' ; set ADC to RA4 enable ADC 8Tosc for TAD
movwf ADCON0
goto START ; go to beginning of program
START
call ReadADC
movf Thou, W
call Table
movwf ThouData
movf Hund, W
call Table
movwf HundData
movf Tens, W
Call Table
movwf TensData
movf Ones, W
call Table
movwf OnesData
goto START
;Table Data for 7 seg displays
Table ADDWF PCL, f ;data table for bit pattern
retlw b'01111110' ;0 -|A|B|C|D|E|F|-
retlw b'00110000' ;1 -|-|B|C|-|-|-|-
retlw b'01101101' ;2 -|A|B|-|D|E|-|G
retlw b'01111001' ;3 -|A|B|C|D|-|-|G
retlw b'00110011' ;4 -|-|B|C|-|-|F|G
retlw b'01011011' ;5 -|A|-|C|D|-|F|G
retlw b'01011111' ;6 -|A|-|C|D|E|F|G
retlw b'01110000' ;7 -|A|B|C|-|-|-|-
retlw b'01111111' ;8 -|A|B|C|D|E|F|G
retlw b'01110011' ;9 -|A|B|C|D|E|F|-
return
Convert: ; Takes number in NumH:NumL
; Returns decimal in
; TenK:Thou:Hund:Tens:Ones
swapf NumH, w
iorlw B'11110000'
movwf Thou
addwf Thou,f
addlw 0XE2
movwf Hund
addlw 0X32
movwf Ones
movf NumH,w
andlw 0X0F
addwf Hund,f
addwf Hund,f
addwf Ones,f
addlw 0XE9
movwf Tens
addwf Tens,f
addwf Tens,f
swapf NumL,w
andlw 0X0F
addwf Tens,f
addwf Ones,f
rlf Tens,f
rlf Ones,f
comf Ones,f
rlf Ones,f
movf NumL,w
andlw 0X0F
addwf Ones,f
rlf Thou,f
movlw 0X07
movwf TenK
movlw 0X0A
Lb1:
addwf Ones,f
decf Tens,f
btfss 3,0
goto Lb1
Lb2:
addwf Tens,f
decf Hund,f
btfss 3,0
goto Lb2
Lb3:
addwf Hund,f
decf Thou,f
btfss 3,0
goto Lb3
Lb4:
addwf Thou,f
decf TenK,f
btfss 3,0
goto Lb4
retlw 0x00
ReadADC
movf ADRESH,w
movwf NumH
bsf STATUS,RP0
movf ADRESL,w
bcf STATUS,RP0
movwf NumL
call Convert
bsf ADCON0,2
return
END