The reason why it is not working, is because it is the exact same listing as you posted initially...with a few highlights.
Have you figured out why it is not working yet?
Anyway, this has been bugging me for a few days. Up until now, I have been mainly playing with blinking LED's and doing 'Knightrider' type projects for friends etc....not really getting into the deeper workings of PIC's, so I have this opportunity to do something bigger to thank you for.
To start with, you need to have the datasheet for the PIC the program was originally written for, along with the datasheet for the intended PIC you wish to use.
Be sure you have enough I/O and the same functions on the target PIC, as defined on the original.
Datasheets for both PIC's in this case:
16F818 - ww1.microchip.com/downloads/en/devicedoc/39598e.pdf
16F676 - ww1.microchip.com/downloads/en/devicedoc/40039c.pdf
16F818, used in the original example, has 18 pins in a DIP package.
16F676, used as the target, has 14 pins in a DIP package.
Looking at the configuration section for both PIC's shows a few differences when setting up the ADCON0 & ADCON1 registers, along with the use of ANSEL on the '676. I think bank selection also caused a bit of confusion.
After having more than a few head-scratching moments, reading datasheets, some more scratching & reading, the code below runs in Oshonsoft Sim (I have neither the '818 or '676, so I can't verify anything will work in real life)
Input is on RA2, output to 8 X LED's are on RC0:RC5 and RA4:RA5.
The clock frequency in the original example is ignored and just uses the '676 internal 4Mhz oscillator.
The rest is up to you:
Code:
;************************************************************************
; Voltage indicator, program solution.
; HEAD818A.ASM is altered to produce the program VOLTIND.ASM for the
; Voltage Indicator Circuit. (For 16F676)
;
; VOLTIND.ASM.
;
;**********************************************************************
; EQUATES SECTION
ZEROBIT EQU 2 ;ZEROBIT is bit 2.
ADRES EQU 1EH ;A/D Result register.
CARRY EQU 0 ;CARRY is bit 0.
;*********************************************************
;Preprocessor Directives
LIST P = PIC16F676 ;Declares the chip to be used
#INCLUDE "P16F676.INC" ;Includes for resolving the
;SFR locations of the particular chip
errorlevel -302 ;Eliminate bank select warning messages
;*********************************************************
; Configuration Bits
__config 0x31C4 ;See datasheet for breakdown.
ORG 0 ;the start address in memory is 0
GOTO Main ;goto OSCCAL calibration
;*********************************************************
; Internal oscillator calibration section
Main ;COMMENT OUT THE NEXT FOUR LINES IF USING A SIMULATOR!
bsf STATUS,RP0 ;set file register bank to 1
call 3FFh ;retrieve factory calibration value
movwf OSCCAL ;update register with factory cal value
bcf STATUS,RP0 ;set file register bank to 0
GOTO START ;goto start!
;*********************************************************
;CONFIGURATION SECTION.
START
BSF STATUS,RP0 ;Turns to Bank1.
MOVLW b'00000100' ;VDD as ref, AN2 as analogue input,
MOVWF ANSEL ;A2D function turned on.
MOVLW b'00000100' ;RA2 (AN2) as input, rest
MOVWF TRISA ;are outputs.
MOVLW b'00000000' ;All of PORTC are outputs
MOVWF TRISC ;
MOVLW b'00000000' ;Bits 6:4 select Fosc clock
MOVWF ADCON1 ;
BCF STATUS,RP0 ;Return to Bank0.
CLRF PORTA ;Clear PORTA
CLRF PORTC ;Clear PORTC
MOVLW b'00001001' ;Turns on A/D converter,
MOVWF ADCON0 ;selecting channel AN2 as input.
;RA0 (AN0) & RA1 (AN1) left clear,
;for ICSP connections.
;*********************************************************
;Program starts now.
BEGIN BSF ADCON0,1 ;Take Measurement.
WAIT BTFSC ADCON0,1 ;Wait until reading done.
GOTO WAIT ;
MOVF ADRES,W ;Move A/D Result into W
CLRF PORTA ;Clear PORTA.
CLRF PORTC ;Clear PORTC.
SUBLW .26 ;26-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 526
GOTO BEGIN ;W is 526 (0.5v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,0 ;Turn on RC0.
SUBLW .51 ;51-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 551
GOTO BEGIN ;W is 551 (1.0v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,1 ;Turn on RC1.
SUBLW .77 ;77-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 577
GOTO BEGIN ;W is 577 (1.5v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,2 ;Turn on RC2.
SUBLW .102 ;102-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5102
GOTO BEGIN ;W is 5102 (2.0v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,3 ;Turn on RC3.
SUBLW .128 ;128-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5128
GOTO BEGIN ;W is 5128 (2.5v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,4 ;Turn on RC4.
SUBLW .153 ;153-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5153
GOTO BEGIN ;W is 5153 (3.0v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTC,5 ;Turn on RC5.
SUBLW .179 ;179-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5179
GOTO BEGIN ;W is 5179 (3.5v)
MOVF ADRES,W ;Move A/D Result into W
BSF PORTA,4 ;Turn on RA4.
SUBLW .204 ;204-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5204
GOTO BEGIN ;W is 5204 (4.0v)
BSF PORTA,5 ;Turn on RA5.
GOTO BEGIN ;
END
Hope this is something like what you were looking for.....please let us know if it works out for you.
Regards.