Is one number bigger than another?..MPASM

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
treez
Posts: 161
Joined: Sat Dec 27, 2008 8:39 am

Is one number bigger than another?..MPASM

Post by treez » Sat Oct 11, 2014 1:26 am

Hello,
I am coding in MPASM (microchip) for PIC18F65K22.

I have numbers contained in two registers,
One is called ana8, the other is called max_led_temp.

I wish to find out if the value in ana8 is greater than the value in max_led_temp.
Can I do this by subtracting ana8 from max_led_temp and checking if the Carry flag of the status register is set?…eg

(the numbers in either register may be between 0 and 255)

Here is the code...

Code: Select all

;Code for 3 channel led driver on the updated 550587 PCB
;REMEMBER RESET ADDRESS
;WE ARE TRUNCATING THE ADC REGISTER SO JUST USE UPPER 8 BITS

; XXX DIPSWITCH POLARITY:- XXX
;DIP 1...ON = EXTERNAL CONNECTOR CONTROL
;DIP 2...ON = LOGIC HIGH (note 'ON' gives a low input)
;DIP 3...ON = LOGIC HIGH
;DIP 4...OFF = 10V is for max current
;DIP 5...OFF = 80degC, ON = 90degC
;DIP 6... UNUSED
;DIP 7... UNUSED
;DIP 8...ON = NO FAN FITTED, OFF = FAN FITTED

; XXX  EXTERNAL CONTROL CONNECTOR POLARITY:- XXX
;CLEAR = ACTIVE HIGH
;RESET = ACTIVE HIGH
;CH1...HIGH = ON, LOW = OFF
;CH2...HIGH = ON, LOW = OFF
;CH3...HIGH = ON, LOW = OFF

;List of input ports:
; ************** DIPSWITCH INPUTS:
;DIP1 = RB0
;DIP2 = RB1
;DIP3 = RB2
;DIP4 = RB3
;DIP5 = RB4
;DIP6 = RB5
;DIP7 = RC5
;DIP8 = RE6

;************* External connector INPUTS:
;clear =       RC1
;ch3 on/off =  RC7
;RESET =       RD5
;CH1 on/off =  RD6
;ch2 on/off =  RD7

;Other inputs (DIGITAL I/O
;Fan tacho = RG2
;mclr =      RG5

;Inputs that are ADC inputs:
;RA2 = AN2
;RA3 = AN3
;RA5 = AN4 ADCON0=0x10
;RF1 = AN6
;RF2 = AN7
;RF3 = AN8
;RF4 = AN9
;RF5 = AN10 ADCON0=0x28
;RF6 = AN11 ADCON0=0x2C
;RF7 = AN5  ADCON0=0x1C

;**********ADC INPUTS:
;AN0 = NC
;AN1 = NC
;AN2 = VREF- (0V)
;AN3 = VREF+ (3V)
;AN4 = Therm ch1
;AN5 = I_CH1
;AN6 = 0-10V control input
;AN7 = PCB thermistor
;AN8 = I_ch2
;AN9 = I_ch3
;AN10 = Therm-ch2
;AN11 = Therm-ch3

;OOOOOOOOOOO LIST OF OUTPUTS:
;Trip =          RA4
;Indicator LED = RC2
;MCP4013_CS =    RC3
;MCP4013_UD =    RC4
;Shutdown-Ch2 =  RE0
;Shutdown-Ch1 =  RE1
;Fancon PWM =    RE2
;Shutdown-Ch3 =  RG0

;NCNCNCNCNCNCNCNCNC LIST OF NON CONNECTED PINS:
;RA0
;RA1
;RA6
;RA7
;    RB6  = PGC
;    RB7  = PGD
;RC0
;RC6
;    RD0
;    RD1
;    RD2
;    RD3
;    RD4
;RE3
;RE4
;RE5
;RE7
;    RG1
;    RG3
;    RG4

#include "p18F65K22.inc"
 list p=18f65k22       	  ;list directive to define processor
; CONFIG1L
  CONFIG  RETEN = OFF           ; VREG Sleep Enable bit (Disabled - Controlled by SRETEN bit)
  CONFIG  INTOSCSEL = HIGH      ; LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
  CONFIG  SOSCSEL = HIGH        ; SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
  CONFIG  XINST = ON            ; Extended Instruction Set (Enabled)

; CONFIG1H
  CONFIG  FOSC = INTIO1         ; Oscillator (Internal RC oscillator, CLKOUT function on OSC2)
  CONFIG  PLLCFG = OFF          ; PLL x4 Enable bit (Disabled)
  CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor (Disabled)
  CONFIG  IESO = OFF            ; Internal External Oscillator Switch Over Mode (Disabled)

; CONFIG2L
  CONFIG  PWRTEN = OFF          ; Power Up Timer (Disabled)
  CONFIG  BOREN = SBORDIS       ; Brown Out Detect (Enabled in hardware, SBOREN disabled)
  CONFIG  BORV = 0              ; Brown-out Reset Voltage bits (3.0V)
  CONFIG  BORPWR = ZPBORMV      ; BORMV Power level (ZPBORMV instead of BORMV is selected)

; CONFIG2H
  CONFIG  WDTEN = OFF           ; Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
  CONFIG  WDTPS = 1048576       ; Watchdog Postscaler (1:1048576)

; CONFIG3L
  CONFIG  RTCOSC = SOSCREF      ; RTCC Clock Select (RTCC uses SOSC)

; CONFIG3H
  CONFIG  CCP2MX = PORTC        ; CCP2 Mux (RC1)
  CONFIG  MSSPMSK = MSK7        ; MSSP address masking (7 Bit address masking mode)
  CONFIG  MCLRE = OFF           ; Master Clear Enable (MCLR Disabled, RG5 Enabled)

; CONFIG4L
  CONFIG  STVREN = ON           ; Stack Overflow Reset (Enabled)
  CONFIG  BBSIZ = BB2K          ; Boot Block Size (2K word Boot Block size)

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protect 00800-01FFF (Disabled)
  CONFIG  CP1 = OFF             ; Code Protect 02000-03FFF (Disabled)
  CONFIG  CP2 = OFF             ; Code Protect 04000-05FFF (Disabled)
  CONFIG  CP3 = OFF             ; Code Protect 06000-07FFF (Disabled)

; CONFIG5H
  CONFIG  CPB = OFF             ; Code Protect Boot (Disabled)
  CONFIG  CPD = OFF             ; Data EE Read Protect (Disabled)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Table Write Protect 00800-017FF (Disabled)
  CONFIG  WRT1 = OFF            ; Table Write Protect 01800-03FFF (Disabled)
  CONFIG  WRT2 = OFF            ; Table Write Protect 04000-05FFF (Disabled)
  CONFIG  WRT3 = OFF            ; Table Write Protect 06000-07FFF (Disabled)
; CONFIG6H
  CONFIG  WRTC = OFF            ; Config. Write Protect (Disabled)
  CONFIG  WRTB = OFF            ; Table Write Protect Boot (Disabled)
  CONFIG  WRTD = OFF            ; Data EE Write Protect (Disabled)
; CONFIG7L
  CONFIG  EBRT0 = OFF           ; Table Read Protect 00800-017FF (Disabled)
  CONFIG  EBRT1 = OFF           ; Table Read Protect 01800-03FFF (Disabled)
  CONFIG  EBRT2 = OFF           ; Table Read Protect 04000-05FFF (Disabled)
  CONFIG  EBRT3 = OFF           ; Table Read Protect 06000-07FFF (Disabled)
; CONFIG7H
  CONFIG  EBRTB = OFF           ; Table Read Protect Boot (Disabled)

;DEFINE OUTPUTS
#define ch1bit     LATE,LATE1
#define ch2bit     LATE,LATE0
#define ch3bit     LATG,LATG0
#define ind_ledbit LATC,LATC2
#define fanconbit LATE,LATE2
#define tripbit    LATA,LATA4
#define mcp4013_csbit  LATC,LATC3
#define mcp4013_udbit  LATC,LATC4

;*** TURN LEDS ON AND OFF
#define ON1     bsf LATE,LATE1  ;Turn on chan1
#define OFF1    bcf LATE,LATE1  ;Turn off chan1
#define ON2     bsf LATE,LATE0  ;Turn on chan2
#define OFF2    bcf LATE,LATE0  ;Turn off chan2
#define ON3     bsf LATG,LATG0  ;Turn on chan2
#define OFF3    bcf LATG,LATG0  ;Turn off chan2
;DEFINE INPUTS FROM DIPSWITCH
;Note that the new board has pullups on the dipswitch,
;whereas 550587 PCB had pull downs, thus logic is reversed.
#define modebit     dip8,0  ;low = external connector sets power via 0-10V
#define LSBbit      dip8,1  ;00 -> 3.52A, 01 -> 2.64A, 10 -> 1.76A, 11 -> OFF
#define MSBbit      dip8,2
#define polaritybit dip8,3  ;high = 10V gives max current
#define t80t90bit   dip8,4  ;high = 80degC, low=90degC
#define fanbit      dip8,8  ;high = fan fitted, low = no fan fitted
;DEFINE INPUTS FROM EXTERNAL CONNECTOR
#define re_setbit  ext_in,0
#define ch1_extbit ext_in,1
#define ch2_extbit ext_in,2
#define ch3_extbit ext_in,3
#define clearbit   ext_in,4

temp1     equ	0x20         ;register for HOLDING ch 1 temperature
temp2     equ	0x21         ;register for holding ch 2 temperature
temp3     equ	0x22         ;register for holding ch 3 temperature
tempb     equ	0x23         ;register for holding board temperature
ana8     equ   0x25         ;holds ADC reading converted to 8 bit from 12 bit
ana_hi    equ   0x26         ;holds the ADRESH register
ana_lo    equ   0x27         ;holds the ADRESL register
ext_in    equ   0x28         ;holds the external connector inputs
del1        equ     0x29         ;Delay register
del2        equ     0x2A         ;Delay register

max_temp    equ     0x2F        ;Holds the max temp
current     equ     0x30        ;Holds the current level bits (bits 0=0 to 3)
count       equ     0x35            ;count
iset_mcp4013    equ     0x36    ;Holds the set current value in mcp4013 steps
iset_mcp4013_A  equ     0x37    ;
max_led_temp    equ     0x38        ;Holds the max temp
max_pcb_temp    equ     0x39        ;Holds the max temp
dip8            equ   0x4A            ;holds dipswitch settings
dip8_init       equ 0x4B
dip8_init_therm     equ 0x4C
dip8_init_current   equ 0x4D
dip8_init_mode      equ 0x4E
dip8_therm          equ 0x4F
dip8_mode           equ 0x50
dip8_current        equ 0x51
overtemp_flags      equ 0x52    ;bit0=1ot,1open....pcbot,pcbopen.(1 = bad)
board_90C   equ     0x2B         ;HOLDS 90C VALUE FOR BOARD
board_80C   equ     0x2C        ;HOLDS 80C VALUE FOR BOARD
led_90C     equ     0x2D        ;HOLDS 90C VALUE FOR LEDS
led_80C     equ     0x2E        ;HOLDS 80C VALUE FOR LEDS
ledtherm_open   equ 0x05        ;hOLDS -13DEGC FOR THERMIST OPEN
pcbtherm_open   equ 0x06        ;holds pcb open


; *** DECLARE MACRO'S ***
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

; ********  Read dipswitchs into dip8 register ********
;Remember that the new PCB has pullups, wheras 550587 PCB had pull downs
;..thus logic in the program is reversed
read_dips_m   macro
    clrf    dip8
    btfsc   PORTB,RB0        ;DIPSWITCH 1 = MODE
    bsf dip8,0
    btfsc   PORTB,RB1        ;DIPSWITCH 2, Power bit 0
    bsf dip8,1
    btfsc   PORTB,RB2        ;DIPSWITCH 3, power bit 1
    bsf dip8,2
    btfsc   PORTB,RB3        ;DIPSWITCH 4, polarity of 0-10V
    bsf dip8,3
    btfsc   PORTB,RB4        ;DIPSWITCH 5, Temp threshold = 80c or 90c
    bsf dip8,4
    btfsc   PORTB,RB5        ;DIPSWITCH 6, unused
    bsf dip8,5
    btfsc   PORTC,RC5        ;DIPSWITCH 7, unused
    bsf dip8,6
    btfsc   PORTE,RE6        ;DIPSWITCH 8, fan or no fan
    bsf dip8,7
    endm
;-----------------------------------------------
;****** READ EXTERNAL CONNECTOR DIGITAL INPUTS *******
read_ext_conn_m   macro
    clrf    ext_in
    btfsc   PORTD,RD5   ;extconn PIN 3; RESET
    bsf ext_in,0
    btfsc   PORTD,RD6   ;extconn PIN 4; CH1_ON/OFF
    bsf ext_in,1
    btfsc   PORTD,RD7   ;extconn PIN 5; CH2_ON/OFF
    bsf ext_in,2
    btfsc   PORTC,RC7   ;extconn PIN 6; CH3_ON/OFF
    bsf ext_in,3
    btfsc   PORTC,RC1   ;extconn PIN 10; CLEAR
    bsf ext_in,4
    endm
; *****************************************
; **** output a tripped signal ****
output_trip_m macro
    bsf tripbit
    endm
; *****output a non-tripped signal ****
no_output_trip_m macro
    bcf tripbit
    endm
;***** Make ADC reading 8 bit from 12 bit ***********
ana_to_8bit_m    macro
    movf    ADRESH,w
    movwf   ana8
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
;SET UP THE ADC
setupADC_m    macro
    movlw   0x00
    movwf   ADCON0  ;channel select, godone, ADON
    movlw   0x10
    movwf   ADCON1  ;vref
    movlw   0x3E
    movwf   ADCON2  ;Right justified, acquisition time
    endm
; ************ Define analog pins ***********8
ana_pins_m    macro
    movlw   0xFC    ;
    movwf  ANCON0
    movlw   0x0F    ;
    movwf  ANCON1
    movlw   0x00    ;
    movwf   ANCON2
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Disable the comparators
comparator_off_m    macro
    movlw   0x00
    movwf   CM1CON
    movlw   0x00
    movwf   CM2CON
    movlw   0x00
    movwf   CM3CON
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Disable interrupts
no_interrupts_m   macro
    clrf    INTCON
    movlw   0x80
    movwf   INTCON2
    clrf    INTCON3
    clrf        PIE1
    clrf        PIE2
    clrf        PIE3
    clrf        PIE4
    clrf        PIE5
    clrf        PIE6
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; Disable pullups
no_pullups_m  macro
    clrf    PADCFG1
    endm
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; disable open drain outputs
no_opendrain_m    macro
    clrf    ODCON1
    clrf    ODCON2
    clrf    ODCON3
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;set up ports as inputs or outputs
setup_ports_m    macro
    movlw   0x2C
    movwf   TRISA
    movlw   0x3F
    movwf   TRISB
    movlw   0xA2
    movwf   TRISC
    movlw   0xD0
    movwf   TRISD
    movlw   0x40
    movwf   TRISE
    movlw   0xFE
    movwf   TRISF
    movlw   0x24
    movwf   TRISG
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXX
define_temps_m   macro
    movlw   0xA8        ;80  DEGC
    movwf   board_80C
    movlw   0xB8        ;90  DEGC
    movwf   board_90C
    movlw   0xA8        ;80  DEGC
    movwf   led_80C
    movlw   0xC9        ;90  DEGC
    movwf   led_90C
    movlw   0x05        ;-13 degC (OPN THERMISTOR)
    movwf   ledtherm_open
    movlw   0x0A        ;-13DEGC (OPEN THERMISTOR)
    movwf   pcbtherm_open
    endm
;XXXXXXXXXXXXXXXXXXXXXXXXXX
;Make all NC pins low (they are already made to outputs)
;They are outputs for noise immunity reasons
NC_pins_low_m macro
    bcf LATA,LATA0
    bcf LATA,LATA1
    bcf LATA,LATA6
    bcf LATA,LATA7

    bcf LATB,LATB6  ;PGC
    bcf LATB,LATB7  ;PGD

    bcf LATC,LATC0
    bcf LATC,LATC6

    bcf LATD,LATD0
    bcf LATD,LATD1
    bcf LATD,LATD2
    bcf LATD,LATD3
    bcf LATD,LATD4

    bcf LATE,LATE3
    bcf LATE,LATE4
    bcf LATE,LATE5
    bcf LATE,LATE7

    bcf LATG,LATG1
    bcf LATG,LATG3
    bcf LATG,LATG4

;    bcf PORTF,RF0
    endm
;INITIALISE OUTPUTS THAT ARE CONNECTED
    org 0x04
start
Main	movlw	b'01010000'		; set internal osc to 4 mhz
		movwf	OSCCON
;SETUP JOBS
    setup_ports_m
    no_pullups_m
    no_opendrain_m
    NC_pins_low_m
    ana_pins_m
    comparator_off_m
    setupADC_m
    no_interrupts_m
; >>>>>>>>>>>>>>>>>>>>> PROGRAM STARTS <<<<<<<<<<<<<<<<<<<<<<<<<<<
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;OOOOOOOOOOOOOOOOOOOOOOOOOO        OOOOOOOOOOOOOOOOOOOOOOOOOOO
;8888888888888888888888                88888888888888888888888888
begin
;Turn LEDs off
    OFF1
    OFF2
    OFF3
    call    delay_ms
;load temperature maximums.
    define_temps_m  ;load the max temperature values
;Read the dipswitchs
    read_dips_m
    movf    dip8,w
    movwf   dip8_init   ;load the 'comparison' dips register
    call    load_temps_c
;Find the maximum current level
    call    set_current_reg_c
;see if in shutdown
    btfsc   current,0
    goto    shutdown_g    ;bit 0 of 'current' register was set, so in shutdown

;see if in overtemp....load overtemp_flags (eight of them)
    call    load_overtemp_flags_c

    


    goto    step_stone_g


step_stone_g
;Find whether need internal  or external mode.
    btfss   modebit
    goto    EXTMODE_g
    goto    INTMODE_g

;Load the maximum temperature registers




EXTMODE_g     ;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
ext1
    nop
    goto    ext1
;EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE


INTMODE_g     ;IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
int1
    call    zero_mcp4013_c    ;zero the mcp4013 (zero volts out)
    call    set_mcp4013_c     ;Set the led driver current with MCP4013

int2    ;have the dipswitchs been changed?...
    read_dips_m
    movf    dip8,w
    bcf     STATUS,Z
    xorwf   dip8_init,w
    btfss   STATUS,Z    ;skip if the registers are the same
    goto    dipchange_int_g   ;dips changed in internal mode

;check temperature too hot
;Read temperture LED1.
    movlw   0x10
    movwf   ADCON0      ;Select AN4 for therm CH1
    movlw   0x11
    movwf   ADCON0      ;Enable ADC
    bsf     ADCON0,1    ;start ADC conversion
int3
    btfsc   ADCON0,1    ;check for ADC done
    goto    int3
;IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII


   goto    int2

 


    goto    begin
; ***** END OF MAIN LOOP *******

;------------------------------------------------
; FUNCTIONS   FUNCTIONS    FUNCTIONS    FUNCTIONS
;------------------------------------------------


;????????????????????????????????????????????????????????????????vvvvv
dipchange_int_g   ;what to do if dips changed in int mode^.NOT A CALLED FUNCTION
;check if temp has changed
    movlw   0x10        ;mask to isolate the temp bit (others made zero)
    andwf   dip8_init,w
    movwf   dip8_init_therm ;just the therm bit
    movlw   0x10
    andwf   dip8,w
    movwf   dip8_therm  ;just the therm bit
    movf    dip8_therm,w
    bcf     STATUS,Z
    xorwf   dip8_init_therm,w   ;now check if they are the same
    btfss   STATUS,Z
    call    load_temps_c
;check if MODE has changed
    movlw   0x01    ;mask to isolate the MODE bit (others zeroed)
    andwf   dip8_init,w
    movwf   dip8_init_mode
    movlw   0x01
    andwf   dip8,w
    movwf   dip8_mode
    movf    dip8_mode,w
    bcf     STATUS,Z
    xorwf   dip8_init_mode,w
    btfss   STATUS,Z
    goto    mode_change_g     ;change of mode
;CHECK If current has changed
      movlw   0x06    ;mask to isolate the MODE bit (others zeroed)
      andwf dip8_init,w
      movwf dip8_init_current
      movlw 0x06
      andwf dip8,w
      movwf dip8_current
      movf  dip8_current,w
      bcf   STATUS,Z
      xorwf dip8_init_current,w
      btfss STATUS,Z
      goto  current_change_g
;??????????????????????????????????????????^^^^^^^^^^^^^^^^^^^^^^

;*************************************************

set_current_reg_c
    clrf    current     ;clear current reg prior to loading
    btfsc   MSBbit
    call    a0_or_a1_c    ;set relevant bit in 'çurrent' register
    btfss   MSBbit
    call    a2_or_a3_c    ;set relevant bit in 'çurrent' register
;Load the iset_mcp4013 level register with relevant no of pulses
    btfsc   current,1
    call    a1p76_c       ;1.76A = 33 PULSES to mcp4013
    btfsc   current,2   ;2.64A = 47 PULSES to mcp4013
    call    a2p64_c
    btfsc   current,3   ;3.52A = 61 pulses to mcp4013
    call    a3p52_c
    retlw   0x00

;reset dip8_init to what it is now



dipchange_ext_g   ;what to do if dips changed in ext mode

load_temps_c
;Load the maximum temperatures (either 80C or 90C)
    movf    led_80C,w
    movwf   max_led_temp
    btfss   t80t90bit
    movf    led_90C,w
    movwf   max_led_temp    ;max led temp loaded
    movf    board_80C,w
    movwf   max_pcb_temp
    btfss   t80t90bit
    movf    board_90C,w
    movwf   max_pcb_temp    ;MAX pcb temp loaded
    retlw   0x00

current_change_g

mode_change_g     ;
    read_dips_m
    movf    dip8,w
    movwf   dip8_init
    btfss   modebit
    goto    EXTMODE_g
    goto    INTMODE_g

; **** LOAD THE CURRENT REGISTER LOWER 4 BITS ****
a0_or_a1_c    ;Find out if its 0a or 1a
    btfsc   LSBbit
    bsf     current,0   ;indicate 0 amps set
    btfss   LSBbit
    bsf     current,1   ;indicate 1.76 amps set
    retlw   0x00
a2_or_a3_c    ;Find out if its 2a or 3a
    btfss   LSBbit
    bsf     current,3   ;indicate 3.52 amps set
    btfsc   LSBbit
    bsf     current,2   ;indicate 2.64 amps set
    retlw   0x00
; ***************************************************
;xxxxxx Load set current level ((no of pulses to mcp4013)  xxxxxxxxxxxx
shutdown_g    ;MSB and LSB bits were 0,0
    bcf     ch1bit
    bcf     ch2bit
    bcf     ch3bit
    read_dips_m         ;check to see if MSB,LSB not give zero current
    movf    dip8,w
    bcf     STATUS,Z
    andwf   06,w
    btfsc   STATUS,Z
    goto    shutdown_g  ;result was zero, so its still in shutdown
    goto    begin
    

    goto    begin

a1p76_c       ;MSBbit = 1, LSBbit = 0
    movlw   0x21        ;33 pulses for 1A76
    movwf   iset_mcp4013
    retlw   0x00
a2p64_c       ;MSBbit = 0, LSBbit = 1
    movlw   0x2F        ;47 pulses for 2A64
    movwf   iset_mcp4013
    retlw   0x00
a3p52_c
    movlw   0x3D        ;61 pulses for 3A52
    movwf   iset_mcp4013
    retlw   0x00
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

zero_mcp4013_c        ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    bsf     mcp4013_csbit   ;disable mcp4013
    bcf     mcp4013_udbit   ;prep for decrement
    movlw   0x42            ;enough to decrement to zero volts
    movwf   count           ;
    call    delay_1ms
    bcf     mcp4013_csbit   ;enable mcp4013
mcp1
    bsf     mcp4013_udbit   ;do a decrement
    nop
    bcf     mcp4013_udbit
    nop
    decfsz  count,1
    goto    mcp1
    bsf     mcp4013_udbit   ;disbale change of mcp4013
    retlw   0x00
;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

set_mcp4013_c     ;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    movf    iset_mcp4013,w
    movwf   iset_mcp4013_A
    bsf     mcp4013_csbit   ;disable mcp4013
    bsf     mcp4013_udbit   ;prep for increment
    call    delay_1ms
    bcf     mcp4013_csbit   ;enable mcp4013
    call    delay_1ms
set1
    bcf     mcp4013_udbit
    nop
    bsf     mcp4013_udbit
    nop
    decfsz  iset_mcp4013_A,f
    goto    set1
    bsf     mcp4013_csbit   ;disable change of mcp4013
    call    delay_1ms
    retlw   0x00

;TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
load_overtemp_flags_c
    clrf    overtemp_flags
    movlw   0x10        ;Read temperture LED1 (AN4).
    movwf   ADCON0      ;Select AN4 for therm CH1
    movlw   0x11
    movwf   ADCON0           ;Enable ADC
    bsf     ADCON0,GO/DONE    ;start ADC conversion
tem1
    btfsc   ADCON0,GO/DONE    ;check for ADC done
    goto    tem1
    ana_to_8bit_m            ;put ADRESH in ana8
    movf    ana8,w
    bcf STATUS,C
    subwf   max_led_temp,w
    btfsc   STATUS,C
    bsf overtemp_flags,0        ;ch1 led = overtemp
;SEE IF CH1 OPEN THERMISTOR...
    movf    ledtherm_open,w
    bcf     STATUS,C
    subwf   ana8,w
    btfsc   STATUS,C
    bsf     overtemp_flags,1    ;ch1 led = open therm

    movlw   0x28        ;Read temperture LED2 (AN10).
    movwf   ADCON0      ;Select AN10 for therm CH2
    movlw   0x29
    movwf   ADCON0           ;Enable ADC
    bsf     ADCON0,GO/DONE    ;start ADC conversion
tem2
    btfsc   ADCON0,GO/DONE    ;check for ADC done
    goto    tem2
    ana_to_8bit_m            ;put ADRESH in ana8
    movf    ana8,w
    bcf STATUS,C
    subwf   max_led_temp,w
    btfsc   STATUS,C
    bsf overtemp_flags,2        ;ch2 led = overtemp
;SEE IF CH1 OPEN THERMISTOR...
    movf    ledtherm_open,w
    bcf     STATUS,C
    subwf   ana8,w
    btfsc   STATUS,C
    bsf     overtemp_flags,3    ;ch2 led = open therm

    movlw   0x2C        ;Read temperture LED3 (AN11).
    movwf   ADCON0      ;Select AN11 for therm CH3
    movlw   0x2D
    movwf   ADCON0           ;Enable ADC
    bsf     ADCON0,GO/DONE    ;start ADC conversion
tem3
    btfsc   ADCON0,GO/DONE    ;check for ADC done
    goto    tem3
    ana_to_8bit_m            ;put ADRESH in ana8
    movf    ana8,w
    bcf STATUS,C
    subwf   max_led_temp,w
    btfsc   STATUS,C
    bsf overtemp_flags,4        ;ch3 led = overtemp
;SEE IF CH1 OPEN THERMISTOR...
    movf    ledtherm_open,w
    bcf     STATUS,C
    subwf   ana8,w
    btfsc   STATUS,C
    bsf     overtemp_flags,5    ;ch3 led = open therm

    movlw   0x1C        ;Read temperture PCB (AN7).
    movwf   ADCON0      ;Select AN7 for therm PCB
    movlw   0x1D
    movwf   ADCON0           ;Enable ADC
    bsf     ADCON0,GO/DONE    ;start ADC conversion
tem4
    btfsc   ADCON0,GO/DONE    ;check for ADC done
    goto    tem4
    ana_to_8bit_m            ;put ADRESH in ana8
    movf    ana8,w
    bcf STATUS,C
    subwf   max_pcb_temp,w
    btfsc   STATUS,C
    bsf overtemp_flags,6        ;PCB = overtemp
;SEE IF CH1 OPEN THERMISTOR...
    movf    pcbtherm_open,w
    bcf     STATUS,C
    subwf   ana8,w
    btfsc   STATUS,C
    bsf     overtemp_flags,7    ;PCB = open therm
    retlw   0x00        ;overtemp_flags now tell all!

 






; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
delay_1ms
    movlw   0x05
    movwf   del1
b1
    movlw   0xFF
    movwf   del2
a1
    decfsz  del2,f
    goto    a1
    decfsz  del1,f
    goto    b1
    retlw   0x00

delay_10ms
    movlw   0x0A
    movwf   del1
b10
    movlw   0xFF
    movwf   del2
a10
    decfsz  del2,f
    goto    a10
    decfsz  del1,f
    goto    b10
    retlw   0x00


delay_ms
    movlw   0xFF
    movwf   del1
zzz
    movlw   0xFF
    movwf   del2
yyy
    decfsz  del2,f
    goto    yyy
    decfsz  del1,f
    goto    zzz
    retlw   0x00


    end

jremington
Support Volunteer
Posts: 2342
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: Is one number bigger than another?..MPASM

Post by jremington » Sat Oct 11, 2014 10:46 am

In the MPLAB IDE, navigate to Help>Topics>MPASM Assembler click "OK" and type "compare" in the search box.

User avatar
phalanx
Non-SFE Guru
Posts: 1991
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Is one number bigger than another?..MPASM

Post by phalanx » Mon Oct 13, 2014 11:16 am

In at least one of your threads, I've referred you to the datasheet for the PIC you are using. Have you looked at it yet? I have no idea if you have or not because you don't respond to your own threads to let us know how you're doing. Amazingly enough, there are specific instructions in the PIC18 that make the process you listed more efficient. Sure enough, they can be found in the DATASHEET (emphasized due to its importance). Unless you do this on a regular basis and have the instruction set memorized, I would expect the average person to have the list of instructions readily available while laying out their code. If you don't know the instruction set and you haven't read through the datasheet, how have you gotten this far?

-Bill

Post Reply