Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

timer circuit

Status
Not open for further replies.
alamy said:
pls comment my program flow..


read input (set 31 as setpoint ; branch to TurnOn/TurnOff) and i'll have two table ....


Code:
Read	Movf       PORTB,w
                Subwf     SP,w  ; where SP define as 31 (b’11111’)
                Btfss       STATUS,C  ; I’m not sure use this one….
                Call        TurnOn
                Call        TurnOff

There are a couple of problems here, firstly why the SUBWF?, secondly 'Call TurnOff' will always execute because 'Call TurnOn' will return from it's subroutine and execute the next line.

How about this:

Code:
Read	Movf       PORTB,w
                movwf    TempW
                Btfss       TempW, 5  ; test bit 5
                Call        TurnOn
                Btfsc       TempW, 5
                Call        TurnOff
                Goto       Read

This assumes you wanted TurnOn and TurnOff as subroutines, because you used 'CALL'. If you used 'GOTO' instead you could remove the BTFSC line. I notice that your TurnOn and TurnOff routines don't have RETURN or RETLW at the end so you mustn't use CALL to run them, you must use GOTO instead - or add RETURN at the end of each.

The routine with GOTO then becomes:

Code:
Read	Movf       PORTB,w
                movwf    TempW
                Btfss       TempW, 5  ; test bit 5
                Goto        TurnOn
                Goto        TurnOff

Another way of doing it, would be to use the full 64 byte table, but for the second half of the table have bit 7 set in the entries, then after reading the table test bit 7, and turn On or OFF accordingly - remembering to mask off bit 7 before calling the delay

i've no idea on this...

If you don't understand it, just ignore it and use the existing way, it's just a variation on the same theme.
 
Nigel how about my TableOn?…after test bit 5, it will go to TurnON or TurnOff, then in my TurnON subroutine, I include TableOn which start from 32 up to 63(?), but how do modified my table ?..in my TableOff, there’re only 32 bytes(am I right?)

My code:

Code:
;********************************************************************** 


   list      p=16F84A            ; list directive to define processor 
   #include <p16F84A.inc>        ; processor specific variable definitions 

   __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC 

cblock    
d1    
d2    
d3    
d4    
count1    
endc 

; '__CONFIG' directive is used to embed configuration data within .asm file. 
; The lables following the directive are located in the respective .inc file. 
; See respective data sheet for additional information on configuration word. 

;###############################################
; CIRCUIT FUNCTION
; to implement the inference engine for digital fuzzy controller to control
; the compressor action.
; single means - off, low , medium or high
;###############################################

;***** VARIABLE DEFINITIONS 
STATUS     EQU     03h      ; variable used for context saving 
TRISA      EQU      85h        ; variable used for context saving 
PORTA      EQU      05H 
TRISB      EQU      86h 
PORTB      EQU      06h 
TempW	   EQU      1	

;********************************************************************** 
      ORG     0x000             ; processor reset vector 
      goto    main              ; go to beginning of program 

      ORG     0x004             ; interrupt vector location 

main    bsf     STATUS,5         ; bank 0 -----> bank 1 
	    movlw   b'00000000'       ; set the port a as outputs 
	    movwf   TRISA             ; 
	    movlw   b'00111111'       ; set the port b as inputs 
	    movwf   TRISB    
	    bcf     STATUS,5         ; bank 1 -----> bank 0 

Read    movf    PORTB,w                 
	    movwf   TempW                 
	    Btfss   TempW, 5  ; test bit 5                 
	    Goto    TurnOn                 
        Goto    TurnOff 

TurnOn 	andlw 	b'00011111'; should i change to b'00111111', 32 or 64 bytes?
	   	Call 	TableOn
	   	Call 	DelayW
		bcf  	PORTA
		Goto 	Read

TurnOff andlw 	b'00011111
        Call 	TableOff
	   	Call 	DelayW
		bsf  	PORTA
        Goto 	Read
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
; Delay = 300 seconds 
; Clock frequency = 4 MHz 
; Actual delay = 300 seconds = 300000000 cycles 
; Error = 0 %    

DelayW  movwf   count1 
Delay5          ;299999995 cycles  
 	    movlw   0x54    
	    movwf   d1    
		movlw   0xA1    
		movwf   d2    
		movlw   0xFD    
		movwf   d3    
		movlw   0x02    
		movwf   d4 
Delay_0    
		decfsz   d1, f    
		goto   $+2    
		decfsz   d2, f    
		goto   $+2    
		decfsz   d3, f    
		goto   $+2    
		decfsz   d4, f    
		goto   Delay_0          ;5 cycles    
		goto   $+1    
		goto   $+1    
		nop       
		decfsz   count1   ,f       
		goto   Delay5       
		retlw   0x00 
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
TableOff Addwf PCL,f
	   	Retlw  1	;0
	   	Retlw  1	;1
	   	Retlw  2	;2
	   	Retlw  1	;3
	   	Retlw  3	;4	
	   	Retlw  1	;5
	   	Retlw  1	;6
	   	Retlw  2	;7
	   	Retlw  1	;8
	   	Retlw  3	; 9	
		Retlw  1	;10
	   	Retlw  1	;11
	   	Retlw  2	;12
	   	Retlw  1	;13
	   	Retlw  3	;14
	   	Retlw  1	;15
	   	Retlw  1	;16
	   	Retlw  2	;17
	   	Retlw  1	;18
	   	Retlw  3	;19
	   	Retlw  1	;20
	   	Retlw  1	;21
	   	Retlw  2	;22
	   	Retlw  1	;23
	   	Retlw  3	;24
	   	Retlw  1	;25
	   	Retlw  1	;26
	   	Retlw  2	;27
	   	Retlw  1	;28
	   	Retlw  3	;29
	   	Retlw  1	;30
	   	Retlw  3	;31
	
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
TableOn Addwf PCL,f
	   	Retlw  2	;32
	   	Retlw  2	;33
	   	Retlw  2	;34
	   	Retlw  2	;35
	   	Retlw  3	;36
	   	Retlw  3	;37
	   	Retlw  2	;38
	   	Retlw  2	;39
	   	Retlw  1	;40
	   	Retlw  3	;41	
		Retlw  3	;42
	   	Retlw  2	;43
	   	Retlw  2	;44
	   	Retlw  1	;45
	   	Retlw  3	;46
	   	Retlw  1	;47
	   	Retlw  2	;48
	   	Retlw  2	;49
	   	Retlw  1	;50
	   	Retlw  3	;51
	   	Retlw  1	;52
	   	Retlw  1	;53
	   	Retlw  2	;54
	   	Retlw  1	;55
	   	Retlw  3	;56
	   	Retlw  2	;57
	   	Retlw  2	;58
	   	Retlw  2	;59
	   	Retlw  1	;60
	   	Retlw  3	;61
	   	Retlw  1	;62
	   	Retlw  2	;63
	

      END                     ; directive 'end of program'

And I get this message

Code:
Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F84A "delay.asm" /l"delay.lst" /e"delay.err" Warning[205] I:\PROGRAMMING\DELAY.ASM 9 : Found directive in column 1. (cblock) Message[313] I:\PROGRAMMING\DELAY.ASM 9 : CBLOCK constants will start with a value of 0. Warning[205] I:\PROGRAMMING\DELAY.ASM 15 : Found directive in column 1. (ENDC) Message[302] I:\PROGRAMMING\DELAY.ASM 44 : Register in operand not in bank 0.  Ensure that bank bits are correct. Message[302] I:\PROGRAMMING\DELAY.ASM 46 : Register in operand not in bank 0.  Ensure that bank bits are correct. Error[128]   I:\PROGRAMMING\DELAY.ASM 58 : Missing argument(s) Warning[209] I:\PROGRAMMING\DELAY.ASM 61 : Missing quote Error[128]   I:\PROGRAMMING\DELAY.ASM 64 : Missing argument(s) Halting build on first failure as requested. BUILD FAILED: Wed Sep 29 10:58:09 2004

An error occurred at bcf and bsf line….WHY?

pls advice...
thanks in advance
 
i'm sorry the message should be like this

Code:
Clean: Deleting intermediary and output files. 
Clean: Done. 
Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F84A "delay.asm" /l"delay.lst" /e"delay.err" 
Warning[205] I:\PROGRAMMING\DELAY.ASM 9 : Found directive in column 1. (cblock) 
Message[313] I:\PROGRAMMING\DELAY.ASM 9 : CBLOCK constants will start with a value of 0. 
Warning[205] I:\PROGRAMMING\DELAY.ASM 15 : Found directive in column 1. (ENDC) 
Message[302] I:\PROGRAMMING\DELAY.ASM 44 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
Message[302] I:\PROGRAMMING\DELAY.ASM 46 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
Error[128]   I:\PROGRAMMING\DELAY.ASM 58 : Missing argument(s) 
Warning[209] I:\PROGRAMMING\DELAY.ASM 61 : Missing quote 
Error[128]   I:\PROGRAMMING\DELAY.ASM 64 : Missing argument(s) Halting build on first failure as requested.
 
alamy said:
Nigel how about my TableOn?…after test bit 5, it will go to TurnON or TurnOff, then in my TurnON subroutine, I include TableOn which start from 32 up to 63(?), but how do modified my table ?..in my TableOff, there’re only 32 bytes(am I right?)

You need to add an extra line to the beginning of Table OFF:

Code:
ANDLW  b'00011111'

To mask off the extra bit.

An error occurred at bcf and bsf line….WHY?

Because you haven't got enough arguments in it!. You need to specify the PIN which you are switching, like this:

Code:
bsf PortA, 1

The error message about CBLOCK is simple, you need to tab it over to the second column - the first column is reserved for labels.
 
alamy said:
Code:
Warning[205] I:\PROGRAMMING\DELAY.ASM 9 : Found directive in column 1. (cblock)
you need a tab before the cblock, to move it to the second column

alamy said:
Code:
Message[313] I:\PROGRAMMING\DELAY.ASM 9 : CBLOCK constants will start with a value of 0.
You need a value behind cblock to set the data's start address. For the 'F84 that would be 0x0C

alamy said:
Code:
Message[302] I:\PROGRAMMING\DELAY.ASM 44 : Register in operand not in bank 0.  Ensure that bank bits are correct. 
Message[302] I:\PROGRAMMING\DELAY.ASM 46 : Register in operand not in bank 0.  Ensure that bank bits are correct.
Not an error, but a warning. You're using a variable wich is not in bank 0, the compiler warns you to check you switched to the correct bank.
You can supress these errors by adding 'ERRORLEVEL -302' to the top of your code.

Nigel already explained the BSF and BCF errors.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top