my program will assemble but wont output anything onto pickit3 with pic18f45k20 - Page 1
Forum section: electronics / general

author: marsal
author_rank: Newbie
timestamp: March 28, 2014, 08:31:01 pm
content: my project is to find the average min and max of a list of several values and then convert it into bcd and display it on the LED of the pickit3, it will build and debug on the simulator however when i connect it to the pickit i receive no output please help here is my code:list p=18f45k20#include p18f45k20.inc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;HI_SUM EQU 0X01 ;USED TO FIND AVERAGELO_SUM EQU 0X02 ;USED TO FIND AVERAGECPFLAG EQU 0X00 ;BIT 0 IN STATUS REGISTERCOUNTER EQU 0X03 ;SET REGISTER 3 AS A COUNTERAVERAGE EQU 0X04 ;AVERAGE VALUE WILL BE STORED HEREMAX EQU 0X05 ;MAX WILL BE STORED HEREMAX1 EQU 0X12MIN EQU 0X06 ;MIN WILL BE STORED HEREMIN1 EQU 0X13BUFF0 EQU 0X07 ;BCD ;BCD0BUFF1 EQU 0X08 ;BCD ;BCD1NUMS EQU 0X09 ;TEMPORARY STORE NUMBERSBUFFER EQU 0X10 ;BEGGINING OF VALUE ADDRESSES IN DATA MEMREG0 EQU 0X30 ;DELAY REGREG1 EQU 0X31 ;DELAY REGREG2 EQU 0X32 ;DELAY REGREG3 EQU 0X33REG4 EQU 0X34INNER_LOOP EQU D'110'OUTTER_LOOP EQU D'220'ORG 0X400 ;WHERE VALUES WILL BE STORED IN PROGRAM MEMNUMBERS DB 0X01, 0X08, 0X07, 0X1A, 0X0C, 0X04, 0XFFORG 0X20 ; PROGRAM WILL BE ASSEMBLED AT REG 20GOTO MAIN;TRANSFERING DATA FROM PM TO DMDATACOPYLFSR FSR0, BUFFERMOVLW UPPER NUMBERSMOVWF TBLPTRUMOVLW HIGH NUMBERSMOVWF TBLPTRHMOVLW LOW NUMBERSMOVWF TBLPTRLLOOP: TBLRD*+MOVFF TABLAT, WREGMOVWF POSTINC0CPFSEQ 0XFFBRA LOOPRETURN;FIND AVERAGEAVG: MOVLW D'6' ; NUMBER OF VALUESMOVWF COUNTERLFSR FSR0, BUFFER ;Set up FSR0 as pointer for data registersCLRF WREG,0CLRF LO_SUMCLRF HI_SUMSUM: ADDWF POSTINC0,0,0 ;Get data byte in WREGBTFSC STATUS,CINCF HI_SUM ;Is byte = 0? If yes, data string is finishedDECF COUNTER,1,0BNZ SUMMOVWF LO_SUMAVG2: CLRF AVERAGEDIVIDE: MOVLW D'6'INCF AVERAGESUBWF LO_SUMBTFSC STATUS, 0GOTO DIVIDEDECF HI_SUMBTFSC STATUS, 0GOTO DIVIDEDECF AVERAGERETURN;FIND MAXMAXIMUM: MOVLW D'6'MOVWF COUNTERMOVFF BUFFER, MAXLFSR FSR0, MAX1NEXT: MOVWF POSTINC0, 0BZ FINISHBTFSC WREG, 6BRA NEXTCPFSLT MAX, 0BRA NEXTMOVWF MAXFINISH: RETURN;FIND MIN:MINIMUM: MOVLW D'6'MOVWF COUNTERMOVFF BUFFER, MINLFSR FSR0, MIN1NEXT1: MOVWF POSTINC0, 0BZ FINISH1BTFSC WREG, 6BRA NEXT1CPFSLT MIN, 0BRA NEXTMOVWF MINFINISH1: RETURN;CONVERT TO BCD:BCDBINBCD: CLRF BUFF0CLRF BUFF1MOVWF NUMSLFSR FSR0, BUFF1MOVLW D'10'RCALL DIVISIONLFSR FSR0, BUFF0MOVFF NUMS, BUFF0DIVISION:INCF INDF0SUBWF NUMSBTFSC STATUS, CGOTO DIVISIONADDWF NUMS, 1DECF INDF0RETURN;DELAY CODE:DELAYDELAY50MS: MOVLW D'166'MOVWF REG3LOOP1: DECF REG3BNZ LOOP1DECF REG4, 1BNZ DELAY50MSRETURN;CODE FOR BLINKING:BLINKINGSTART1: MOVLW B'10101100' ;load binary valueMOVWF TRISD ; define Port D as outputMOVWF REG0ONOFF: MOVFF REG0, PORTD ;set clock speedMOVLW INNER_LOOP ;first loop = 110MOVWF REG1 ;load reg2 with 110MOVLW OUTTER_LOOP ;second loop = 220MOVWF REG2 ;load loop 2 value into reg 3LOOP3: DECF REG1, 1 ;decrease reg2 by 1BNZ LOOP3 ; check reg2 = 0DECF REG2, 1 ;decrease reg3 by 1BNZ LOOP3 ;check reg 3 = 0COMF REG0 ,1 ; compliment reg1BRA ONOFF ; branch if command mentSLEEP;MAIN ASSEMBLY CODE:MAINMOVLW 0X00MOVWF TRISD ; PORT D AS OUTPUTCALL BLINKINGCLRF PORTDCALL DELAYCALL DATACOPYCALL AVERAGEMOVFF AVERAGE, WREGCALL BCDCALL DELAYCALL MINIMUMMOVFF MIN, WREGCALL BCDCALL DELAYCALL MAXIMUMCALL BCDCALL DELAYCALL BLINKINGCLRF PORTDSLEEPEND

author: dannyf
author_rank: Super Contributor
timestamp: March 28, 2014, 08:49:00 pm
content: QuoteWhat is "average min" and "average max"?

author: marsal
author_rank: Newbie
timestamp: March 28, 2014, 08:50:24 pm
content: average of the values, the min is the lowest value from the list and the max is the highest value of the list

author: dannyf
author_rank: Super Contributor
timestamp: March 28, 2014, 09:06:39 pm
content: Save yourself the pain and suffering and learn C.

author: Unknown
author_rank: Unknown
timestamp: March 28, 2014, 09:25:06 pm
content: Hi, where are your config settings? why did you chose to write it in assembler?

author: David_AVD
author_rank: Super Contributor
timestamp: March 28, 2014, 09:49:12 pm
content: Have you tried some simple blinking LED code to make sure the config is correct and the hardware is good?

author: marsal
author_rank: Newbie
timestamp: March 28, 2014, 10:32:21 pm
content: i would use c but assembly lang was a requirement for this projectmy congif settings are:;//** C O N F I G U R A T I O N B I T S ***********/CONFIG FOSC = INTIO67 ; INTIO67 Note that if it is HS it will not work!CONFIG LVP = OFFCONFIG PWRT = ONCONFIG FCMEN = OFFCONFIG IESO = OFF ;// CONFIG1HCONFIG BOREN = SBORDISCONFIG BORV = 30 ;// CONFIG2LCONFIG WDTEN = OFFCONFIG WDTPS = 32768 ;// CONFIG2HCONFIG MCLRE = OFFCONFIG LPT1OSC = OFFCONFIG PBADEN = ONCONFIG CCP2MX = PORTC ;// CONFIG3HCONFIG STVREN = ON;CONFIG XINST = OFF ;// CONFIG4LCONFIG CP0 = OFFCONFIG CP1 = OFFCONFIG CP2 = OFFCONFIG CP3 = OFF ;// CONFIG5LCONFIG CPB = OFFCONFIG CPD = OFF ;// CONFIG5HCONFIG WRT0 = OFFCONFIG WRT1 = OFFCONFIG WRT2 = OFFCONFIG WRT3 = OFF ;// CONFIG6LCONFIG WRTB = OFFCONFIG WRTC = OFFCONFIG WRTD = OFF ;// CONFIG6HCONFIG EBTR0 = OFFCONFIG EBTR1 = OFFCONFIG EBTR2 = OFFCONFIG EBTR3 = OFF ;// CONFIG7LCONFIG EBTRB = OFF

author: westfw
author_rank: Super Contributor
timestamp: March 28, 2014, 11:12:14 pm
content: No RETURN in Blinking?

author: JTR
author_rank: Regular Contributor
timestamp: March 30, 2014, 09:21:00 am
content: As above PlusSince when has the reset vector for a PIC18F45K20 been at 0x20?LOOP: TBLRD*+MOVFF TABLAT, WREGMOVWF POSTINC0CPFSEQ 0XFF <- Are you kidding? Read the data sheet.

author: marsal
author_rank: Newbie
timestamp: March 31, 2014, 01:32:21 am
content: The last value will be 0xFF, indicating the end of the data (0xFF is not counted in the summation calculation).

author: JTR
author_rank: Regular Contributor
timestamp: March 31, 2014, 09:29:56 am
content: CPFSEQ 0XFFPlease, please, please... READ THE DATA SHEET!

author: westfw
author_rank: Super Contributor
timestamp: April 01, 2014, 03:43:12 pm
content: CPFSEQ compares W against a file register's contents, not against a constant.