Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 25th September 2004, 06:44 AM   (permalink)
Default

Quote:
Originally Posted by alamy
My system have 6 inputs and 1 output (on-off) …variable time delays.

My pic have the 64 possibilities input value which produce 6 or more type of output that is time delay for ON (5,15,30 minutes) and also time delay for OFF (5,15,30 minutes). For input range (possibilities value) 0-32 …my pic will OFF with certain period (5,15,30 minutes) and 33-63 it will ON (5,15,30 minutes) .

My program flow will be like this:--


then for the read routine :
Code:
read  movf   PORTB,w          ; read input from port B       
andlw   b'00111111'             ; mask of bits      
call   table                          ; refer to table, compare with inputs       
call   DelayW                      ; delay W number of times
After you've read the port and applied 'ANDLW' you have a 6 bit number in W - I would suggest you store it in a temporary register.

Code:
movwf Temp
You can then check bit 5 to see if it's '1' or not, and the program can branch accordingly - to routines to either turn ON or turn OFF then delay the amount of time set.

You then only need a 32 byte table (because bit 5 isn't part of the table), so you should 'ANDLW b'00011111' before calling the table.

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.

The first way would be shorter, because you half the size of the table.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 25th September 2004, 10:50 PM   (permalink)
Default

alamy Can you use two ' ORG ' statements like that..??
how is the assembler going to handle two ORG statements?
this is the code...i have never tried it though..


Code:
;***** 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 

;********************************************************************** 
      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
williB is offline  
Old 26th September 2004, 11:28 AM   (permalink)
Default

Quote:
Originally Posted by williB
alamy Can you use two ' ORG ' statements like that..??
how is the assembler going to handle two ORG statements?
this is the code...i have never tried it though..

Code:
 
      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

That's EXACTLY the way to use ORG statements, you can use as many as you want - it just moves the current address for the assembler. If I was ading data statements I would add an ORG for that address, or add another ORG in order to place a table at the start of a 256 byte boundary.

The only problem I have with the code is that 'main' is sat on the interrupt vector address, I would use a different address to free up the interrupt vector - or simply start from 0x000 if you're not using interrupts at all.
Like this:

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


      ORG     0x004             ; interrupt vector location
      RETFIE                       ; return from interrupt (just in case!)
                                       ; main now at 0x0005 
main  bsf      STATUS,5         ; bank 0 -----> bank 1
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 26th September 2004, 03:33 PM   (permalink)
Default

i did not know that..thanks for the explanation..
williB is offline  
Old 28th September 2004, 04:47 AM   (permalink)
Default

pls comment my program flow..


Quote:
You can then check bit 5 to see if it's '1' or not, and the program can branch accordingly - to routines to either turn ON or turn OFF then delay the amount of time set.
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

TurnOn 	andlw      b’00011111’
               	Call         TableOn
	Call         DelayW
	Bcf          PORTA
           	Goto        Read

TurnOff 	andlw      b’00011111’
               	Call         TableOff
	Call         DelayW
	 Bsf         PORTA
           	 Goto       Read

TableOn 	Addwf pcl,f
	Retlw  1
	Retlw  1
	Retlw  2
	Retlw  1
	Retlw  3
	     :
	     :
	Retlw  1

TableOff 	Addwf pcl,f
	Retlw  1
	Retlw  1
	Retlw  2
	Retlw  1
	Retlw  3
	     :
	     :
	Retlw  1
modified(nigel) version of time delay

Code:
Delay = 300 seconds 
; Clock frequency = 4 MHz 

; Actual delay = 300 seconds = 300000000 cycles 
; Error = 0 % 

   cblock 
   d1 
   d2 
   d3 
   d4 
   count1 
   endc 

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

pls advice..

Quote:
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...
Attached Images
File Type: jpg flow1.jpg (21.1 KB, 187 views)
alamy is offline  
Old 28th September 2004, 07:01 AM   (permalink)
Default

Quote:
Originally Posted by alamy
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
Quote:

Quote:
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 30th September 2004, 06:37 AM   (permalink)
Default

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
alamy is offline  
Old 30th September 2004, 06:41 AM   (permalink)
Default

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 is offline  
Old 30th September 2004, 06:50 AM   (permalink)
Default

Quote:
Originally Posted by alamy
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.

Quote:
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 30th September 2004, 11:22 AM   (permalink)
Default

Quote:
Originally Posted by alamy
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

Quote:
Originally Posted by alamy
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

Quote:
Originally Posted by alamy
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.
Exo is offline  
Old 1st October 2004, 07:11 AM   (permalink)
Default

thanks Nigel and exo...fixed..
alamy is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 04:20 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker