Hey, I'm really new to this programming stuff and I have been asked to adapt the code below. It currently takes potentiometer values and counts up in binary with the LEDs between 0 and 5V over all 8 LEDs. However, I would like it to just count up sequentially with the LEDs using the first 5 LEDs. so for 1 volt, 1 LED is on, 2 volts 2 LEDs etc.
This is used in conjunction with a PIC demo Board.
Can anyone help please?
This is what I have:
list p=16f917 ; list directive to define processor
#include <p16f917.inc> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _FCMEN_ON & _IESO_ON & _CP_OFF & _WDT_OFF & _BOD_OFF & _MCLRE_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0,1,2, and 3. Each Bank contains
; Special Function Registers, General Purpose Registers, and Access RAM
;
;------------------------------------------------------------------------------
CBLOCK 0x20 ; Define GPR variable register locations
MYVAR1 ; User variables allocated contiguously
MYVAR2 ;
MYVAR3 ;
RESULTHI;
RESULTLO;
ENDC
W_TEMP EQU 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP EQU 0x7F ; context saving of PC (ACCESS)
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F917 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------
DATAEE ORG 0x2100
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; When using debug header, first inst.
; may be passed over by ICD2.
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ORG 0x0004
; Interrupt context saving
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into w register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Interrupt context restoring
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
;**************************************************************************************************
;Connect a potentiometer to RA0, convert the analogue signal into digital value, and send it to PORTB,
;by adjusting potentiometer, LEDs that are driven by the digital value should flash.
;**************************************************************************************************
START
bsf STATUS, RP0 ;select bank 1
movlw 0xf0 ;set PortB <7:4> 4 inputs, <3:0> 4 outputs. 11110000--> w--> TRISB
movwf TRISB
bcf STATUS, RP0 ;select bank 0
clrf PORTB ;set all outputs low
;********PORTA, A/D****************
bsf STATUS, RP0 ;choose bank1
bcf STATUS, RP1
movlw 0x07 ;PORTA Comparator off
movwf CMCON0
movlw 0x50 ;A/D clock Fosc/16
movwf ADCON1
bsf TRISA, 0 ;Set RA0 to input
bsf ANSEL, 0 ;Set RA0 to analog
bcf STATUS, RP0 ;Bank 0
movlw 0x01 ;result left shifted, Vdd Vref, AN0
movwf ADCON0
;
Loop
;----------check A/D results------------------
banksel ADCON0
bsf ADCON0, GO ;Start conversion
btfsc ADCON0, GO ;Is conversion done?
goto $-1 ;No, test again
movf ADRESH, W ;Read upper 2 bits
movwf RESULTHI
movwf PORTB ;send A/D result high 8 bits to PORTB (LEDs change with analogue signal)
bsf STATUS,RP0 ;Bank 1
movf ADRESL,W ;Read lower 8 bits
movwf RESULTLO
goto Loop
end
This is used in conjunction with a PIC demo Board.
Can anyone help please?
This is what I have:
list p=16f917 ; list directive to define processor
#include <p16f917.inc> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _FCMEN_ON & _IESO_ON & _CP_OFF & _WDT_OFF & _BOD_OFF & _MCLRE_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0,1,2, and 3. Each Bank contains
; Special Function Registers, General Purpose Registers, and Access RAM
;
;------------------------------------------------------------------------------
CBLOCK 0x20 ; Define GPR variable register locations
MYVAR1 ; User variables allocated contiguously
MYVAR2 ;
MYVAR3 ;
RESULTHI;
RESULTLO;
ENDC
W_TEMP EQU 0x7D ; w register for context saving (ACCESS)
STATUS_TEMP EQU 0x7E ; status used for context saving (ACCESS)
PCLATH_TEMP EQU 0x7F ; context saving of PC (ACCESS)
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F917 has 256 bytes of non-volatile EEPROM, starting at address 0x2100
;
;------------------------------------------------------------------------------
DATAEE ORG 0x2100
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; When using debug header, first inst.
; may be passed over by ICD2.
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ORG 0x0004
; Interrupt context saving
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into w register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Interrupt context restoring
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
;**************************************************************************************************
;Connect a potentiometer to RA0, convert the analogue signal into digital value, and send it to PORTB,
;by adjusting potentiometer, LEDs that are driven by the digital value should flash.
;**************************************************************************************************
START
bsf STATUS, RP0 ;select bank 1
movlw 0xf0 ;set PortB <7:4> 4 inputs, <3:0> 4 outputs. 11110000--> w--> TRISB
movwf TRISB
bcf STATUS, RP0 ;select bank 0
clrf PORTB ;set all outputs low
;********PORTA, A/D****************
bsf STATUS, RP0 ;choose bank1
bcf STATUS, RP1
movlw 0x07 ;PORTA Comparator off
movwf CMCON0
movlw 0x50 ;A/D clock Fosc/16
movwf ADCON1
bsf TRISA, 0 ;Set RA0 to input
bsf ANSEL, 0 ;Set RA0 to analog
bcf STATUS, RP0 ;Bank 0
movlw 0x01 ;result left shifted, Vdd Vref, AN0
movwf ADCON0
;
Loop
;----------check A/D results------------------
banksel ADCON0
bsf ADCON0, GO ;Start conversion
btfsc ADCON0, GO ;Is conversion done?
goto $-1 ;No, test again
movf ADRESH, W ;Read upper 2 bits
movwf RESULTHI
movwf PORTB ;send A/D result high 8 bits to PORTB (LEDs change with analogue signal)
bsf STATUS,RP0 ;Bank 1
movf ADRESL,W ;Read lower 8 bits
movwf RESULTLO
goto Loop
end