;************************************************************************
; Voltage indicator, program solution
; [COLOR="red"]HEAD818A.ASM[/COLOR] is altered to produce the program VOLTIND.ASM for the
; Voltage Indicator Circuit.
; VOLTIND.ASM. This sets PORTA as analogue/digital
; INPUTs. PORTC is an OUTPUT.
; Internal oscillator of 31.25kHz chosen
; The OPTION register is set to /256 giving timing ;pulses 32.768ms.
; 1second and 0.5 second delays are includedthe
; ubroutine section.
;**********************************************************************
; EQUATES SECTION
TMR0 EQU 1 ;means TMR0 is file 1.
STATUS EQU 3 ;means STATUS is file 3.
PORTA EQU 5 ;means PORTA is file 5.
PORTC EQU 7 ;means PORTC is file 6.
ZEROBIT EQU 2 ;means ZEROBIT is bit 2.
ADCON0 EQU 1FH ;A/D Configuration reg.0
ADCON1 EQU 9FH ;A/D Configuration reg.1
ADRES EQU 1EH ;A/D Result register.
CARRY EQU 0 ;CARRY IS BIT 0.
TRISA EQU 85H ;PORTA Configuration Register
TRISC EQU 87H ;PORTC Configuration Register
OPTION_R EQU 81H ;Option Register
OSCCON EQU 8FH ;Oscillator control register.
COUNT EQU 20H ;COUNT a register to count events
;*********************************************************
;Preprocessor Directives
[COLOR="red"]LIST P = PIC16F676[/COLOR] ;declares the chip to be used
[COLOR="red"]#INCLUDE "P16F676.INC"[/COLOR] ;Includes for resolving the
errorlevel -302 ;Eliminate bank warning ;SFR locations of this particular chip
;*********************************************************
; Configuration Bits
__config 0x31C4
;__config 0x3F10 ;sets INTRC-A6 is port I/O, WDT off, PUT on,
;MCLR tied to VDD A5 is I/O
;BOD off, LVP disabled, EE protect disabled,
;Flash Program Write disabled,
;Background Debugger Mode disabled, CCP
;function on B2,
;Code Protection disabled.
ORG 0 ;the start address in memory is 0
GOTO START ;goto start!
;*********************************************************
;CONFIGURATION SECTION.
START
BSF STATUS,5 ;Turns to Bank1.
MOVLW b'00011111' ;5bits of PORTA reI/Pb'00010000'
MOVWF TRISA
MOVLW b'00000011' ;A0, A1 are analogue
MOVWF ADCON1 ;A2, A3 are digital I/P.
MOVLW b'00000000'
MOVWF TRISC ;PORTC is OUTPUT
BCF STATUS,5 ;Return to Bank0.
MOVLW b'00000001' ;Turns on A/D converter,
MOVWF ADCON0 ;and selects channel AN0
CLRF PORTA ;Clears PortA.
CLRF PORTC ;Clears PORTC.
MOVWF 0x19
BSF STATUS , RP0
;*********************************************************
;Program starts now.
BEGIN
BSF ADCON0,2 ;Take Measurement.
WAIT BTFSC ADCON0,2 ;Wait until reading done.
GOTO WAIT
MOVF ADRES,W ;Move A/D Result into W
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 B0.
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 B1.
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 B2.
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 B3.
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 B4.
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 B5.
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
[COLOR="red"]BSF PORTC,6 ;Turn on B6.[/COLOR]
SUBLW .204 ;204-,W. W is altered
BTFSC STATUS,CARRY ;Is W4 or 5204
GOTO BEGIN ;W is 5204 (4.0v)
[COLOR="red"]BSF PORTC,7 ;Turn on B7.[/COLOR]
GOTO BEGIN
END
not working. What is wrong with my 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
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.
it not worked. pl help me
[I]Main [B];COMMENT OUT THE NEXT FOUR LINES IF USING A SIMULATOR![/B]
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![/I]
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!
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?