PIC newbie - took ages to program and i still have bugs


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    12

    Default PIC newbie - took ages to program and i still have bugs

    Heres the error log
    Code:
    Clean: Deleting intermediary and output files. 
    Clean: Deleted file "C:\Documents and Settings\\My Documents\speedtemp.mcs". 
    Clean: Done. 
    Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "SPEED254.ASM" /l"SPEED254.lst" /e"SPEED254.err" 
    Warning[207] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 140 : Found label after column 1. (SVNSEG) Warning[207] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 167 : Found label after column 1. (INTER) Error[113]   C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 319 : Symbol not previously defined (z) Error[113]   
    C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 323 : Symbol not previously defined (z) Error[113]   
    C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 362 : Symbol not previously defined (c) Error[113]   
    C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 373 : Symbol not previously defined (c) Message[302] 
    C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 501 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 503 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 505 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 707 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 709 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Error[113]   C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 729 : Symbol not previously defined (z) Error[113]   C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 732 : Symbol not previously defined (z) Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 953 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 955 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 957 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 958 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 960 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 961 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 963 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 968 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Message[302] C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 970 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
    Error[113]   C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 975 : Symbol not previously defined (z) Error[113]   C:\DOCUMENTS AND SETTINGS\\MY DOCUMENTS\SPEED254.ASM 1045 : Symbol not previously defined (c) Halting build on first failure as requested. 
    BUILD FAILED: Tue Sep 25 12:53:21 2007
    and my code's attached

    Programming language: ASM PIC instruction set
    PIC: PIC16F84

    Any help would be greatly appreciated
    Attached Files Attached Files
    Last edited by Trickae; - 25th September 2007 at 04:04. Reason: spacing

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Zip ?

    Hi Trickae,
    Welcome, looks like you just joined today, Not too many people will open a zip file from someone they do not know well, so how about you break up that program and let us look at it in pieces if you cannot post it all in one without zipping it.
    JS
    Last edited by Archangel; - 25th September 2007 at 05:14.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    >>took ages to program and i still have bugs

    Interesting .... I found your code here with google

    http://www.siliconchip.com.au/cms/at...month=November
    Last edited by paul borgmeier; - 25th September 2007 at 06:29.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    Sep 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    you've got me -

    the code is legit no malware

    the code is available with current kit based speed alert devices but I need to modify it for a personal project. I just Downloaded MPLAB today and ran the first couple of instructions and found a list of errors. I was expecting everything to be in order:

    Heres the code in full:

    part 1:
    Code:
    ; File SPEED254.ASM changes from SPEED.ASM to allow speed readings up to 254km/h
    ; Uses assembly code for PIC16F84 microcontroller
    ; This program is for a car speed alarm. It utilises three 7-segment displays
    ; which show the set speed. The speed setting can be altered with up and down pushbutton 
    ; switches from 0 to 255km/h in 5km/h steps. When the speed of the vehicle reaches the set speed,
    ; the alarm sounds and an LED lights up. The alarm is a short beep beep sound while the LED 
    ; remains lit until the speed is reduced below the alarm speed or the alarm speed is increased 
    ; above the vehicles speed.
    ;
    ; A rotating magnet or magnets installed on the vehicles tail shaft or drive shaft
    ; trigger an inductive (coil) sensor to detect vehicle speed and this signal is detected via
    ; an interrupt in the processor.
    ;
    ; Calibration can be made by setting an alarm speed on the display and then bringing the 
    ; vehicle speed up to the alarm speed as shown on the vehicles speedometer. 
    ; The Calibrate switch is then pressed. The display will show CAL until
    ; calibrated. Display will show Err (error) if too few pulses or none are present while calibrating.  
    ; No calibration allowed in speedometer mode. 
    ;
    ; Each pressing the Mode switch will cycle between alarm speed indication, speedometer
    ; and off which disables the speed alarm. 
    ;
    ; Alarm indication occurs for speedometer and alarm speed modes. 
    ;
    ; Pressing the Up switch at power up will set the speed alarm for either a
    ; repeat warning of overspeed or single alarm. The repeat alarm will produce a tone every 
    ; 10-seconds until the speed goes below the setting or the speed setting is increased above
    ; the speed.
    ; 
    ; When pressing the Up switch at power up, a 'r' on the right display indicates repeat 
    ; alarm and a '-' indicates no-repeat alarm option.
    ;
    ; Pressing the Mode switch at power up will toggle the speed alarm with the speedometer on or off
    ; If the display shows an 'S' then the speedometer function will operate and a '-' indicates that
    ; the speedometer is off.
    ;
    ; Pressing the Down switch at power up will set the speed alarm threshold point either high or
    ; low. The low threshold means that the alarm will sound at the set speed and switch off
    ; when the speed goes 1km/h or less below this speed. The high threshold will set the alarm 
    ; when the speed is 1km/h or more above the set speed and go off for speeds at or below the 
    ; set speed. A high setting will be indicated by an 'H' and a low setting by an 'L'as shown during
    ; power up with the down switch pressed.
    ;  
    ; Processor pin allocations are as follows:
    ; RA0 Output disp1 driving transistor for common anode display
    ; RA1 Output disp2
    ; RA2 Output disp3
    ; RA3 Output for alarm
    ; RA4 Input from switches
    
    ; RB0 Input for wheel sensor (interrupt)
    ; RB1 c segment drive for seven segment LED display
    ; RB2 d segment drive
    ; RB3 e segment drive
    ; RB4 f segment drive
    ; RB5 a segment drive
    ; RB6 b segment drive
    ; RB7 g segment drive
    
    ; CPU configuration
    ; 	
    	list P=16F84
    	#include "p16f84.inc"
    	__config _XT_OSC & _WDT_OFF & _PWRTE_ON
    
    ; Define variables at memory locations
    
    ; EEPROM DATA
    
    EEPROM1		equ	H'00'	; non-volatile storage for display1
    EEPROM2		equ	H'01'	; non-volatile storage for display2
    EEPROM3		equ	H'02'	; non-volatile storage for display3
    EEPROM4		equ	H'03'	; non-volatile storage to toggle repeat alarm feature and mode
    EEPROM5		equ	H'04'	; non-volatile storage of LS byte of calibration number
    EEPROM6		equ	H'05'	; non-volatile storage of MS byte of calibration number
    
    ; RAM
    
    DISP1		equ	H'0C'	; working storage for Display1 value alarm speed mode
    DISP2		equ	H'0D'	; working storage for Display2 value alarm speed mode
    DISP3		equ	H'0E'	; working storage for Display3 value alarm speed mode
    STATUS_TMP 	equ H'0F'	; temp storage for status during interrupt
    W_TMP		equ	H'10'	; temporary storage for w during interrupt
    VALUE_1		equ H'11'	; delay value storage			
    VALUE_2		equ	H'12'	; delay value storage
    FLAG_1		equ	H'13'	; flag, bit 0 = flag for closed switch, bit 1 for interrupt indicator
    						; bit 2 for alarm tone required, bit 3 for tone duty cycle,
    						; bit 4 alarm off, bit 5 overspeed, bit 6 EEPROM 
    						; write repeat number, bit 7 for calibrate flag
    FLAG_2		equ	H'14'	; alarm tone period settable from 00-FE 
    FLAG_3		equ	H'15'	; alarm tone sequence 00000000=on,00000001=off,00000010=on >=00000011 off, 
    						; use a more significant bit to set reocurrence, bit 6 or 7
    REPEAT		equ	H'16'	; bit 0 working store repeat alarm flag stored in EEPROM4, bit 1 on/off flag
    						; bit 1 on/off flag, bit 2 speedo/alarm select flag, bit 3 speedo on/off flag
    						; bit 4 alarm threshold 
    SPEED_EQV	equ	H'17'	; storage for speed equivalent (value of 5 per 5km/h) 160km/h=160
    TEMP_1		equ	H'18'	; temporary working storage
    TEMP_2		equ	H'19'	; temp storage
    TIME_CNT1	equ	H'1A'	; counter for pulse count period
    TIME_CNT2	equ	H'1B'	; counter for pulse count period
    TIME_CNT3	equ	H'1C'	; working lsb calibration number stored in EEPROM5
    TIME_CNT4	equ	H'1D'	; working msd calibration number stored in EEPROM6
    PULSE_CNT	equ	H'1E'   ; counter for speed pulses compared with speed_eqv 
    ERR_FLG		equ	H'1F'	; bit 0 is error flag for counter overrange during calibration
    SPEEDO		equ	H'20'	; latched value for speedometer obtained from PULSE_CNT
    SPEED1		equ	H'21'	; display1 value during speedometer mode
    SPEED2		equ	H'22'	; display2 value during speedometer mode
    SPEED3		equ	H'23'	; display3 value during speedometer mode
    TEMP		equ	H'24'	; temporary register for BCD conversion
    BCD_0		equ	H'25'	; decimal value MSD
    BCD_1		equ	H'26'	; decimal packed BCD LS digits
    BIN_0		equ	H'27'	; binary value for BCD conversion
    CNT_8		equ	H'28'   ; counter for BCD conversion
    TEMP_X		equ	H'29'	; temporary register for speed equivalent calculation
     
    ; preprogram EEPROM DATA
    	
    	ORG     2100
    	DE	0x00, 0x06, 0x00	; preset EEPROM1-EEPROM3 ( initial speed setting is 60)
    		DE	0x03			; set EEPROM4 (repeat alarm on bit 0 and set to on/off bit 1)
    							; bit 2 speedo/set bit to set alarm mode, bit 3 speedo on
    							; bit 4 alarm threshold low
    		DE	0xB3, 0x11		; set calibration EEPROM5 & EEPROM6 (set to 100Hz = 160km/h
    ; calibration calculated out at 1.6s update time 160km/h = 160 pulses counted.
    ; 3.579545MHz/4/2/(256-100+2) = 353.1175us and require 4531Decimal for 1.6 sec or 11B3Hex 
    
    ; Program begins
    
    ; define reset and interrupt vector start addresses
    
    	org	0			  	; start at address 0000h
    	goto	MAIN		; normal service routines from Reset vector
    	org     4			; interrupt vector 0004h, start interrupt routine here
    	goto	INTER		; go to start of interrupt routine, bypass subroutines
    
    ; subroutine to get seven segment display data. (This is placed at front of programm to prevent computed
    ; goto crossing 256 bit boundary. *PCL control only over least significant 8-bits*) 
     
    	SVNSEG	andlw	0x0F; remove most significant bits if present prevents value >16h
    	addwf	PCL,f		; add value of display to program counter
    	retlw 	B'10000000'	; 7-segment code 0 
    	retlw 	B'10111100'	; 7-segment code 1
    	retlw 	B'00010010'	; 7-segment code 2
    	retlw 	B'00011000'	; 7-segment code 3
    	retlw 	B'00101100'	; 7-segment code 4
    	retlw 	B'01001000'	; 7-segment code 5
    	retlw 	B'01000000'	; 7-segment code 6
    	retlw 	B'10011100'	; 7-segment code 7
    	retlw 	B'00000000'	; 7-segment code 8
    	retlw 	B'00001000'	; 7-segment code 9
    
    ;*******************************************************************************************
    - if need be i'll contact the developers website on why their code is ridden with bugs. Thanks for look at it.

  5. #5
    Join Date
    Sep 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Part 2
    Code:
    ; INTERRUPT
    ; interrupt from counter used to multiplex display
    ; this sucessively switches on Disp1, Disp2, Disp3 in sequence plus 
    ; blanking leading zeros on display for Disp2 and Disp3 for either 
    ; speedometer or set alarm speed modes
    ; uses internal timer to initiate display update
    ; also updates time period counters which set period of speed pulse counting
    ; checks speed against alarm setting
    ; speed sensor update
    
    ; start interrupt by saving w and status registers before altered by interrupt routine
    
    	INTER	movwf	W_TMP	; w to w_tmp storage
    	swapf	STATUS,w		; status to w
    	movwf	STATUS_TMP		; status in status_tmp  
    
    ; which interrupt (INT or TMRO)
    
    	btfsc	INTCON,T0IF		; TMRO overflow interrupt flag then goto litchk
    	goto	LITCHK			; TMRO overflow so multiplex display
    SENSOR	btfsc	INTCON,INTF	; INT interrupt flag set then goto speed
    	goto	SPEED			; speed sensor signal update 
    	goto	RECLAIM			; end of interrupt reclaim w and status
    
    ; multiplex display routine
    
    LITCHK	btfsc	REPEAT,1	; check if speed alarm unit on or off
    	goto	ALM_BY			; on so skip resetting alarm (alarm bypass)
    
    ; reset alarm function
    
    	clrf	PULSE_CNT	; clear pulse counter so no alarm
    	clrf	TIME_CNT1	; clear time counter 1
    	clrf	TIME_CNT2	; clear time counter 2 	
    ALM_BY	bcf	STATUS,RP0	; select bank 0
    	movlw	D'100'		; speed up multiplex rate for suitable tone in piezo alarm (100
    						; is used in calibration number calculation and for output freq)	
    						; freq is 3.579545MHz/2/4/(256-100+2)/2 = 1.4159kHz
    	addwf	TMR0,f		; add to timer registerand takes 2 cycles to start counting
    	bcf	INTCON,T0IF		; clear TMRO interrupt flag
    	bsf	FLAG_1,0		; indicate another interrupt has occurred
    	btfsc	REPEAT,2	; check if speedometer or alarm speed mode
    	goto 	SPD_LTE		; display update in speedometer mode 
    	btfss	PORTA,0		; skip if display 1 not lit
    	goto	LIT1		; display 1 lit
    	btfss	PORTA,1		; skip if display 2 not lit
    	goto	LIT2		; display 2 lit
    	btfss	PORTA,2		; skip if display 3 not lit				
    	goto	LIT3		; display 3 lit
    	movlw	B'11111110'	; seven segments off
    	movwf	PORTB
    	bcf	PORTA,2			; no displays lit so set disp3 (used if error in output)
    	goto 	LITCHK		; goto check which is lit now
    LIT1	bsf	PORTA,0		; disp1 off
    	movf	DISP3,w		; look at display3
    	xorlw	0x00		; compare display3 with 0
    	btfss	STATUS,Z	; skip if zero
    	goto	NOBLNK		; do not blank display2
    	movf	DISP2,w		; look at display2
    	xorlw	0x00		; compare disp2 with 0
    	btfss	STATUS,Z	; skip if 0
    	goto	NOBLNK		; do not blank disp2
    	movlw	B'11111110'	; 7-segment display off
    	goto	BLANK		; blank disp2 when disp2 and disp3 = 0
    NOBLNK	movf	DISP2,w		; disp2 to w
    	call 	SVNSEG		; goto subroutine to get seven segment code 
    BLANK	btfss	ERR_FLG,0	; calibrate error
    	goto	CAL_M		; mid display
    	movlw	B'10000110'	; set display for 'r' (Err)
    	goto	LIT_r		; light an r
    CAL_M	btfsc	FLAG_1,7	; calibrate flag skip if clear
    	movlw	B'00000100'	; set display to show an A (for CAL) 
    	btfss	REPEAT,1	; is speed alarm unit on or off, 1 is on 0 is off
    	movlw	B'01111110'	; set 'g' segment on display 
    LIT_r	movwf	PORTB		; seven segment value to portB
    	bcf	PORTA,1		; disp2 powered
    	goto	TIMECNT		; end of multiplex
    LIT2	bsf	PORTA,1		; disp2 off
    	movf	DISP3,w		; disp3 to w
    	xorlw	0x00		; compare with 0
    	btfss	STATUS,Z	; skip if zero
    	goto 	SHOW		; show digit on disp3
    	movlw	B'11111110'	; 7-segment display off
    	goto	BLNK		; value to blank display
    SHOW	movf	DISP3,w		; look at display3
    	call	SVNSEG		; get 7-segment value
    BLNK	btfss	ERR_FLG,0	; calibrate error
    	goto	CAL_L		; Left display
    	movlw	B'01000010'	; set display for 'E' (Err)
    	goto	LIT_E		; light an E
    CAL_L	btfsc	FLAG_1,7	; calibrate flag skip if clear
    	movlw	B'11000010'	; set display to show a C (for CAL) 
    	btfss	REPEAT,1	; is speed alarm unit on or off, 1 is on 0 is off
    	movlw	B'01111110'	; set 'g' segment on display 
    LIT_E	movwf	PORTB		; portB has seven-segment code 
    	bcf	PORTA,2		; disp3 powered
    	goto	TIMECNT		; end of multiplex
    LIT3	bsf	PORTA,2		; disp3 off
    	movf	DISP1,w		; disp1 to w
    	call	SVNSEG
    	btfss	ERR_FLG,0	; calibrate error
    	goto	CAL_R		; Right display
    	movlw	B'10000110'	; set display for 'r' (Err)
    	goto	LIT_rr		; light an r
    CAL_R	btfsc	FLAG_1,7	; calibrate flag skip if clear
    	movlw	B'11100010'	; set display to show an L (for CAL) 
    	btfss	REPEAT,1	; is speed alarm unit on or off, 1 is on 0 is off
    	movlw	B'01111110'	; set 'g' segment on display 
    LIT_rr	movwf 	PORTB
    	bcf	PORTA,0		; disp1 powered
    	goto	TIMECNT
    
    ; display update for speedometer mode
    
    SPD_LTE btfss	PORTA,0	; skip if display 1 not lit
    	goto	SPD_LT1		; display 1 lit
    	btfss	PORTA,1		; skip if display 2 not lit
    	goto	SPD_LT2		; display 2 lit
    	btfss	PORTA,2		; skip if display 3 not lit				
    	goto	SPD_LT3		; display 3 lit
    	movlw	B'11111110'	; seven segments off
    	movwf	PORTB
    	bcf	PORTA,2			; no displays lit so set disp3 (used if error in output)
    	goto 	SPD_LTE		; goto check which is lit now
    SPD_LT1	bsf	PORTA,0		; disp1 off
    	movf	SPEED3,w	; look at display3
    	xorlw	0x00		; compare display3 with 0
    	btfss	STATUS,Z	; skip if zero
    	goto	NOBLNK1		; do not blank display2
    	movf	SPEED2,w	; look at display2
    	xorlw	0x00		; compare disp2 with 0
    	btfss	STATUS,Z	; skip if 0
    	goto	NOBLNK1		; do not blank disp2
    	movlw	B'11111110'	; 7-segment display off
    	goto	BLANK1		; blank disp2 when disp2 and disp3 = 0
    NOBLNK1	movf	SPEED2,w	; disp2 to w
    	call 	SVNSEG		; goto subroutine to get seven segment code 
    BLANK1	movwf	PORTB		; seven segment value to portB
    	bcf	PORTA,1		; disp2 powered
    	goto	TIMECNT		; end of multiplex
    SPD_LT2	bsf	PORTA,1		; disp2 off
    	movf	SPEED3,w	; disp3 to w
    	xorlw	0x00		; compare with 0
    	btfss	STATUS,Z	; skip if zero
    	goto 	SHOW1		; show digit on disp3
    	movlw	B'11111110'	; 7-segment display off
    	goto	BLNK1		; value to blank display
    SHOW1	movf	SPEED3,w	; look at display3
    	call	SVNSEG		; get 7-segment value
    BLNK1	movwf	PORTB		; portB has seven-segment code 
    	bcf	PORTA,2		; disp3 powered
    	goto	TIMECNT		; end of multiplex
    SPD_LT3	bsf	PORTA,2		; disp3 off
    	movf	SPEED1,w	; disp1 to w
    	call	SVNSEG
    	movwf 	PORTB
    	bcf	PORTA,0		; disp1 powered
    
    ; update time period counters for speed pulse counter
    
    TIMECNT	btfsc	FLAG_1,7	; calibrate flag skip if clear (no calibrate)
    	goto	CALBRAT		; calibrate switch pressed so do calibration
    	movf	TIME_CNT4,w	; MS Byte of calibration value to w
    	xorwf	TIME_CNT2,w	; compare MS Byte counter with calibration
    	btfss	STATUS,z	; skip if equal
    	goto	INC_CT1		; 
    	movf	TIME_CNT3,w	; LS Byte of calibration value
    	xorwf	TIME_CNT1,w	; compare LS byte counter with calibration
    	btfss	STATUS,z	; skip if equal
    	goto	INC_CT1		; 
    	clrf	TIME_CNT1	; clear timer counter 1
    	clrf	TIME_CNT2	; and timer 2
    	movf	PULSE_CNT,w	; look at pulse counter value
    	movwf	SPEEDO		; speedometer value latched pulse counter value

  6. #6
    Join Date
    Sep 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    part 3
    Code:
    ; routine to convert speedo memory to speed 1, 2 & 3 display memory
    	
    	sublw	0xFF		; compare with maximum value (255km/h)
    	btfsc	STATUS,Z	; is it at maximum
    	goto	LIMIT		; maximum of 255 on display 
    
    ; convert speedo to BCD place in Speed 3,Speed 2 and Speed1	
    
    	movf	SPEEDO,w	; look at speedo value
    	movwf	BIN_0		; to binary register
    	call	BCD		; convert to BCD
    	movf	BCD_0,w		; ms digit
    	movwf	SPEED3		; display MSD
    	movf	BCD_1,w		; LS Digits
    	andlw	0x0F		; mask bits 7-4
    	movwf	SPEED1		; ls digit
    	swapf	BCD_1,w		; look at ms nibble
    	andlw	0x0F
    	movwf	SPEED2		; middle digit
    	goto	CK_SPD
    
    LIMIT	movlw	0x08		; place 8 in speed1-3 memory so display -
    	movwf	SPEED1		; - shows 888 for overrange speedometer
    	movwf	SPEED2
    	movwf	SPEED3
    	
    ; check speed against alarm setting
    
    CK_SPD	movf	SPEED_EQV,w	; speed equivalent value to w 
    	btfsc	REPEAT,4	; skip if alarm threshold low
    	addlw	0x01		; increase speed equiv by hysteresis value
    	subwf	PULSE_CNT,w	; subtract speed equivalent from pulse counter	
    	btfsc	STATUS,c	; if positive or zero (c=1) then sound overspeed alarm	
    	goto 	SETALM
    	
    ; add hysteresis (addition of 1 to pulse counter gives 1km/h hysteresis)
    
    	movf	PULSE_CNT,w	; pulse counter value
    	btfss	REPEAT,4	; skip if alarm threshold high
    	addlw	0x01		; increase by factor for hysteresis (on to off alarm speed)
    	movwf	PULSE_CNT
    	movf	SPEED_EQV,w
    	subwf	PULSE_CNT,w	; subtract speed equivalent from new pulse counter value
    	btfsc	STATUS,c	; if positive or zero (c=1) then leave set alarm on
    	goto	ALM_CL		; continue alarm
    	goto	CLRALM		; clear alarm as below overspeed 
    	
    INC_CT1 incfsz	TIME_CNT1,f	; increase counter 1 skip if overflowed
    	goto 	ALARM
    	incf	TIME_CNT2,f	; increase counter 2 when counter 1 overflows
    	goto 	ALARM
    
    ; calibrate time counters
    
    CALBRAT	incfsz	TIME_CNT1,f	; increase counter 1 skip if overflowed
    	goto	CMP_PLS
    	incfsz	TIME_CNT2,f	; increase counter 2 on overflow skip if overflowed
    	goto	CMP_PLS		; not overrange so compare pulse count with speed equiv
    	bsf	ERR_FLG,0	; error flag set as counter 2 has overranged
    	bcf	FLAG_1,7	; calibrate off flag
    	goto	C_ALM
    CMP_PLS	movf	PULSE_CNT,w	; pulse counter to w
    	xorwf	SPEED_EQV,w	; compare pulse counter with speed equivalent (display value)	
    	btfss	STATUS,Z	; skip if equal
    	goto 	C_ALM
    	
    ; store time counters TIME_CNT1 & 2 into TIME_CNT3 & 4 and into EEPROM5 & 6 - new calibration 
    
    	movf	TIME_CNT1,w	; time counter 1 to w
    	movwf	TIME_CNT3	; time counter 3 = 1
    	movf	TIME_CNT2,w	; time counter 2 to w
    	movwf	TIME_CNT4	; time counter 2 = 4
    	bcf	FLAG_1,7	; calibrate flag clear, calibrate off
    	
    ; clear alarm
    	
    CLRALM	clrf	PULSE_CNT	; clear pulse counter for recount
    	clrf	TIME_CNT1	; clear time counter 1
    	clrf	TIME_CNT2	; clear time counter 2 	
    C_ALM	bcf	FLAG_1,5	; overspeed flag
    	bcf	FLAG_1,4	; clear alarm off flag
    	bsf	PORTA,3		; alarm output high 
    	goto	ALARM		; continue program
    
    ; set alarm
    
    SETALM	clrf	PULSE_CNT	; clear pulse counter for recount
    	clrf	TIME_CNT1	; clear time counter 1
    	clrf	TIME_CNT2	; clear time counter 2 	
    	btfsc	FLAG_1,5	; is overspeed flag set. Skip if not
    	goto	ALARM		; set so skip setting alarm again, wait till cleared
    	bsf	FLAG_1,5	; overspeed flag
    	bsf	FLAG_1,2	; set alarm tone flag
    	bsf	FLAG_1,4	; set alarm off flag
    	clrf	FLAG_2		; alarm tone period
    	bcf	FLAG_1,3	; clear on off flag
    	clrf	FLAG_3		; alarm tone sequence
    
    ; alarm tone routine generates a beep beep tone for over-speed 	
    
    ALM_CL	clrf	PULSE_CNT
    	clrf	TIME_CNT1	; clear time counter 1
    	clrf	TIME_CNT2	; clear time counter 2 	
    ALARM	btfss	FLAG_1,4	; alarm off flag
    	goto	SENSOR		; alarm not required 
    	incf	FLAG_2,f	; alarm tone period
    	btfss	FLAG_1,2	; skip if alarm tone required	
    	goto	RDFLG_2		; no alarm go to check sensor interrupt
    	btfsc	FLAG_1,3	; alternate on and off flag for tone 
    	goto	SET_OUT		; if flag set then stop tone on RA3 output
    	btfsc	PORTA,3		; is alarm out low 
    	goto	SET_OUT
    	bsf	PORTA,3		; alarm out pin high 
    	goto	CNT_SEQ
    SET_OUT	bcf	PORTA,3		; alarm out pin low 
    CNT_SEQ	bcf 	FLAG_1,3
    	btfss	FLAG_3,0	; read alarm tone sequence (bit 0 low then alarm tone)
    	goto	RDFLG_2	
    	bsf	FLAG_1,3	; no tone
    	bsf	PORTA,3		; alarm output high
    	btfss	FLAG_3,1	; check count
    	goto 	RDFLG_2
    	bcf	FLAG_1,2	; alarm off
    	bcf	PORTA,3		; alarm out low 
    	goto 	SENSOR	
    RDFLG_2	movf	FLAG_2,w	; read alarm tone period counter
    	sublw	0xFE		; alarm tone on-time (FE = max) (00 = min)
    	btfss	STATUS,C	; skip if less than on-time
    	goto	SET_FLG
    	goto 	SENSOR	
    SET_FLG incf	FLAG_3,f	; next sequence
    	clrf	FLAG_2		; start period count
    	btfss	FLAG_3,7	; look at bit for repeat tone period, 7 is longest interval, 6 half the period etc
    	goto	SENSOR		; if bit set then repeat alarm
    	btfss	REPEAT,0	; skip if repeat flag set
    	goto	SENSOR
    	bsf	FLAG_1,2	; allow alarm again
    	clrf	FLAG_3		; clear repeat bit 
    	goto	SENSOR
    
    ; speed sensor update
    
    SPEED	bcf	INTCON,INTF	; clear INT flag
    	incfsz	PULSE_CNT,f	; increase pulse counter value for each speed sensor input
    	goto	RECLAIM
    	movlw	0xFF		; max value
    	movwf	PULSE_CNT	; place max count in pulse counter do not allow overrange	
    	
    ; end of interrupt reclaim w and status 
    
    RECLAIM	swapf	STATUS_TMP,w	; status temp storage to w
    	movwf	STATUS		; w to status register
    	swapf	W_TMP,f		; swap upper and lower 4-bits in w_tmp
    	swapf   W_TMP,w		; swap bits and into w register
    	retfie			; return from interrupt

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts