![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I am trying to send high and low signal using 16F84 microchip. My plan is to send 30min delay low in port B,0 Then 58second low in port B,0 then 2 second high in portB,0. The 58second low and 2second high i want it to repeat for 53 times after the delay of 30minutes. I have the codes here I am confused about calling portB,0 and setting it to low and then using loop for 53times for same instruction. Code: LIST P=PIC16F84 #INCLUDE "P16F84.INC" __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC errorlevel -302 cblock 0x0c d1,d2,d3 endc org 0 init banksel TRISA ;bank 1 clrf TRISA clrf TRISB banksel PORTB ;bank 0 clrf PORTB main bsf PORTB,0 call delay30min bcf PORTB,0 nop ;slight delay for possible RMW problem bsf PORTB,1 call delay2sec bcf PORTB,1 nop ;slight delay for possible RMW problem bsf PORTB,2 call delay5sec bcf PORTB,2 goto main delay30min ;30minutes delay movlw 0xB6 movwf d1 movlw 0x64 movwf d2 movlw 0x20 movwf d3 Delay30min_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay30min_0 nop return delay6min59sec ;6minutes 59seconds delay movlw 0x87 movwf d1 movlw 0x4F movwf d2 movlw 0x08 movwf d3 delay6min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay6min59sec_0 goto $+1 goto $+1 goto $+1 return delay9min59sec ;9minutes 59seconds delay movlw 0x1A movwf d1 movlw 0x73 movwf d2 movlw 0x0B movwf d3 delay9min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay9min59sec_0 nop return delay58sec ;58seconds delay movlw 0xED movwf d1 movlw 0x03 movwf d2 movlw 0x02 movwf d3 Delay58sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay58sec_0 return delay56sec ;56seconds delay movlw 0xFE movwf d1 movlw 0xFA movwf d2 movlw 0x01 movwf d3 Delay56sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay56sec_0 goto $+1 goto $+1 nop return delay49sec ;49seconds delay movlw 0xBE movwf d1 movlw 0xDB movwf d2 movlw 0x01 movwf d3 delay49sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay49sec_0 goto $+1 goto $+1 nop return delay11sec ;11secons delay movlw 0xBE movwf d1 movlw 0x45 movwf d2 delay11sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay11sec_0 goto $+1 nop return delay5sec ;5seconds delay movlw 0x3F movwf d1 movlw 0x20 movwf d2 Delay5sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay5sec_0 return delay4sec ;4seconds delay movlw 0xFF movwf d1 movlw 0x19 movwf d2 Delay4sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay4sec_0 goto $+1 return delay2sec ;2seconds delay movlw 0x7F movwf d1 movlw 0x0D movwf d2 Delay2sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay2sec_0 return delay1sec ;1second delay movlw 0x3E movwf d1 movlw 0x07 movwf d2 delay1sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay1sec_0 goto $+1 nop return end
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #2 |
|
I guess everyone lost lets make my question even simpler, I want to repeat 52 times these command i am using 16F84. Code: bsf PORTB,0 call delay2sec bcf PORTB,0 call delay58sec
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #3 |
|
Something simple like, Code: movlw .52 movwf RepeatCount RepeatLoop bsf PORTB,0 call delay2sec bcf PORTB,0 call delay58sec decfsz RepeatCount,F goto RepeatLoop | |
| |
| | #4 |
|
I tried using this method but it gives me several error. Here is the codes Code: LIST P=PIC16F84 #INCLUDE "P16F84.INC" __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC errorlevel -302 cblock 0x0c d1,d2,d3 endc org 0 init banksel TRISA ;bank 1 clrf TRISA clrf TRISB banksel PORTB ;bank 0 clrf PORTB main bcf PORTB,0 ;Turn off B0 call delay30min ;53 times repeating movlw .53 movwf RepeatCount RepeatLoop bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount,F goto RepeatLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay6min59sec bsf PORTB,0 call delay1sec ;51 times repeating movlw .51 movwf RepeatCount1 RepeatLoop1 bcf PORTB,0 call delay56sec bsf PORTB,0 call delay4sec decfsz RepeatCount1,F goto RepeatLoop1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay9min59sec bsf PORTB,0 call delay1sec ;59 times repeating movlw .59 movwf RepeatCount2 RepeatLoop2 bcf PORTB,0 call delay49sec bsf PORTB,0 call delay11sec decfsz RepeatCount2,F goto RepeatLoop2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay2sec call delay58sec ;59 times repeating movlw .59 movwf RepeatCount3 RepeatLoop3 bcf PORTB,0 call delay49sec bsf PORTB,0 call delay11sec decfsz RepeatCount3,F goto RepeatLoop3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay2sec call delay58sec ;51 times repeating movlw .51 movwf RepeatCount4 RepeatLoop4 bcf PORTB,0 call delay56sec bsf PORTB,0 call delay4sec decfsz RepeatCount4,F goto RepeatLoop4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay9min59sec bsf PORTB,0 call delay1sec ;53 times repeating movlw .53 movwf RepeatCount5 RepeatLoop5 bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount5,F goto RepeatLoop5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay6min59sec bsf PORTB,0 call delay1sec call delay9min59sec ;8 times repeating movlw .8 movwf RepeatCount6 RepeatLoop6 bcf PORTB,0 call delay30min decfsz RepeatCount6,F goto RepeatLoop6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; goto main delay30min ;30minutes delay movlw 0xB6 movwf d1 movlw 0x64 movwf d2 movlw 0x20 movwf d3 Delay30min_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay30min_0 nop return delay6min59sec ;6minutes 59seconds delay movlw 0x87 movwf d1 movlw 0x4F movwf d2 movlw 0x08 movwf d3 delay6min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay6min59sec_0 goto $+1 goto $+1 goto $+1 return delay9min59sec ;9minutes 59seconds delay movlw 0x1A movwf d1 movlw 0x73 movwf d2 movlw 0x0B movwf d3 delay9min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay9min59sec_0 nop return delay58sec ;58seconds delay movlw 0xED movwf d1 movlw 0x03 movwf d2 movlw 0x02 movwf d3 Delay58sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay58sec_0 return delay56sec ;56seconds delay movlw 0xFE movwf d1 movlw 0xFA movwf d2 movlw 0x01 movwf d3 Delay56sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay56sec_0 goto $+1 goto $+1 nop return delay49sec ;49seconds delay movlw 0xBE movwf d1 movlw 0xDB movwf d2 movlw 0x01 movwf d3 delay49sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay49sec_0 goto $+1 goto $+1 nop return delay11sec ;11secons delay movlw 0xBE movwf d1 movlw 0x45 movwf d2 delay11sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay11sec_0 goto $+1 nop return delay4sec ;4seconds delay movlw 0xFF movwf d1 movlw 0x19 movwf d2 Delay4sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay4sec_0 goto $+1 return delay2sec ;2seconds delay movlw 0x7F movwf d1 movlw 0x0D movwf d2 Delay2sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay2sec_0 return delay1sec ;1second delay movlw 0x3E movwf d1 movlw 0x07 movwf d2 delay1sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay1sec_0 goto $+1 nop return end
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #5 |
|
You need to add RepeatCount to the cblock area (after d3). Mike. | |
| |
| | #6 |
|
Hi, RepeatCount should be predefined before being used. Put it in Code: cblock 0x0c d1,d2,d3 RepeatCount endc
__________________ bananasiong | |
| |
| | #7 |
|
Thanks alot the error reduce from 15 till 1! still one error i am trying my best to understand this error but still can't figure a way to solve it. Code: Debug build of project `D:\Openloop\Open loop 1\april.mcp' started. Preprocessor symbol `__DEBUG' is defined. Sat Apr 26 16:12:44 2008 ---------------------------------------------------------------------- Clean: Deleting intermediary and output files. Clean: Done. Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F84 "16F84TMPO.ASM" /l"16F84TMPO.lst" /e"16F84TMPO.err" /d__DEBUG=1 Warning[205] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM 1 : Found directive in column 1. (LIST) Error[173] C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM 281 : Source file path exceeds 62 characters (C:\PROGRAM FILES\MICROCHIP\MPASM SUITE\TEMPLATE\OBJECT\16F84TMPO.ASM) Halting build on first failure as requested. ---------------------------------------------------------------------- Debug build of project `D:\Openloop\Open loop 1\april.mcp' failed. Preprocessor symbol `__DEBUG' is defined. Sat Apr 26 16:12:46 2008 FAILED Code: LIST P=PIC16F84 #INCLUDE "P16F84.INC" __CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _LP_OSC errorlevel -302 cblock 0x0c d1,d2,d3 RepeatCount RepeatCount1 RepeatCount2 RepeatCount3 RepeatCount4 RepeatCount5 RepeatCount6 endc org 0 init banksel TRISA ;bank 1 clrf TRISA clrf TRISB banksel PORTB ;bank 0 clrf PORTB main bcf PORTB,0 ;Turn off B0 call delay30min ;53 times repeating movlw .53 movwf RepeatCount RepeatLoop bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount,F goto RepeatLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay6min59sec bsf PORTB,0 call delay1sec ;51 times repeating movlw .51 movwf RepeatCount1 RepeatLoop1 bcf PORTB,0 call delay56sec bsf PORTB,0 call delay4sec decfsz RepeatCount1,F goto RepeatLoop1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay9min59sec bsf PORTB,0 call delay1sec ;59 times repeating movlw .59 movwf RepeatCount2 RepeatLoop2 bcf PORTB,0 call delay49sec bsf PORTB,0 call delay11sec decfsz RepeatCount2,F goto RepeatLoop2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay2sec call delay58sec ;59 times repeating movlw .59 movwf RepeatCount3 RepeatLoop3 bcf PORTB,0 call delay49sec bsf PORTB,0 call delay11sec decfsz RepeatCount3,F goto RepeatLoop3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay2sec call delay58sec ;51 times repeating movlw .51 movwf RepeatCount4 RepeatLoop4 bcf PORTB,0 call delay56sec bsf PORTB,0 call delay4sec decfsz RepeatCount4,F goto RepeatLoop4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay9min59sec bsf PORTB,0 call delay1sec ;53 times repeating movlw .53 movwf RepeatCount5 RepeatLoop5 bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount5,F goto RepeatLoop5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; bcf PORTB,0 call delay6min59sec bsf PORTB,0 call delay1sec call delay9min59sec ;8 times repeating movlw .8 movwf RepeatCount6 RepeatLoop6 bcf PORTB,0 call delay30min decfsz RepeatCount6,F goto RepeatLoop6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; goto main delay30min ;30minutes delay movlw 0xB6 movwf d1 movlw 0x64 movwf d2 movlw 0x20 movwf d3 Delay30min_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay30min_0 nop return delay6min59sec ;6minutes 59seconds delay movlw 0x87 movwf d1 movlw 0x4F movwf d2 movlw 0x08 movwf d3 delay6min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay6min59sec_0 goto $+1 goto $+1 goto $+1 return delay9min59sec ;9minutes 59seconds delay movlw 0x1A movwf d1 movlw 0x73 movwf d2 movlw 0x0B movwf d3 delay9min59sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay9min59sec_0 nop return delay58sec ;58seconds delay movlw 0xED movwf d1 movlw 0x03 movwf d2 movlw 0x02 movwf d3 Delay58sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay58sec_0 return delay56sec ;56seconds delay movlw 0xFE movwf d1 movlw 0xFA movwf d2 movlw 0x01 movwf d3 Delay56sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay56sec_0 goto $+1 goto $+1 nop return delay49sec ;49seconds delay movlw 0xBE movwf d1 movlw 0xDB movwf d2 movlw 0x01 movwf d3 delay49sec_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto delay49sec_0 goto $+1 goto $+1 nop return delay11sec ;11secons delay movlw 0xBE movwf d1 movlw 0x45 movwf d2 delay11sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay11sec_0 goto $+1 nop return delay4sec ;4seconds delay movlw 0xFF movwf d1 movlw 0x19 movwf d2 Delay4sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay4sec_0 goto $+1 return delay2sec ;2seconds delay movlw 0x7F movwf d1 movlw 0x0D movwf d2 Delay2sec_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay2sec_0 return delay1sec ;1second delay movlw 0x3E movwf d1 movlw 0x07 movwf d2 delay1sec_0 decfsz d1, f goto $+2 decfsz d2, f goto delay1sec_0 goto $+1 nop return end
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #8 | ||
|
Hi, The error is: Quote:
Quote:
__________________ bananasiong | |||
| |
| | #9 |
|
I recommend using standardized delays. Call Minutes Call Seconds Call MilliSeconds | |
| |
| | #10 |
|
What is the maxium number off looping i can do for one iteration. Code: ;53 times repeating movlw .53 movwf RepeatCount RepeatLoop bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount,F goto RepeatLoop I meant in this example i used 53 times to loop what is the maxium i can use can i used for example Code: ;582 times repeating movlw .582 movwf RepeatCount RepeatLoop bcf PORTB,0 call delay58sec bsf PORTB,0 call delay2sec decfsz RepeatCount,F goto RepeatLoop Thanks in advance for any reply
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #11 |
|
Hi, One register is 8-bit, which is 255 maximum. With 582, since it is 0x246. Only the lower 8-bit is taken. So you get only 0x46 or 70.
__________________ bananasiong | |
| |
| | #12 |
|
In eight bit register you can write upto 255 ( D'255').To write 582 you need more registers. You told you send 30min delay low in port B,0 but your code is setting that bit for 30 mins. Can you tell step by step? Last edited by Gayan Soyza; 29th April 2008 at 10:10 AM. | |
| |
| | #13 |
|
Hi again, Thanks Gayan Soyza and bananasiong for answering I have another question: I want to send signal in port B0,B1 at the same time Code: bsf PORTB,0
__________________ Hesham Ismail Mohammed Sharif Thank me if you want | |
| |
| | #14 |
| Code: movlw b'00000011' ;set bit 0,1 movwf PORTB | |
| |
| | #15 |
|
Would a delay subsystem that allows you to specify delays as shown below be practical in your application? Code: ;
; must specify clock in MHz
;
clock equ 8 ; 8 MHz clock
;
DelayMS(1) ; delay 1 msec
DelayUS(1000) ; delay 1 msec
DelayCy(1*msecs) ; delay 1 msec
DelayCy(1000*usecs) ; delay 1 msec
DelayCy(1*msecs-3) ; delay 1 msec minus 3 cycles
;
Enjoy. Mike Code: ;******************************************************************
; *
; DelayMS(), DelayUS(), DelayCy() Mike McLaren, K8LH, Jun'07 *
; *
; a small 16-bit delay subroutine with macro "front ends" which *
; allow you to specify delays in msecs, usecs, or cycles. *
; *
; requires the use of constant operands known at assembly time! *
; *
; each delay macro call generates 4 instructions (for delays in *
; the ranges shown below). longer delays up to several seconds *
; are possible but the macro produces 4 additional instructions *
; for every 262016 cycles in the delay. *
; *
; 4 MHz, 1 cycles/usec, 16..262144 usecs, 1..262 msecs *
; 8 MHz, 2 cycles/usec, 8..131072 usecs, 1..131 msecs *
; 12 MHz, 3 cycles/usec, 6...87381 usecs, 1...87 msecs *
; 16 MHz, 4 cycles/usec, 4...65536 usecs, 1...65 msecs *
; 20 MHz, 5 cycles/usec, 4...52428 usecs, 1...52 msecs *
; *
; here are some of the ways to generate a 1 millisecond delay; * *
; *
; DelayMS(1) ; delay 1 msec *
; DelayUS(1000) ; delay 1 msec *
; DelayCy(1*msecs-2) ; delay 1 msec minus 2 cycles *
; DelayCy(1000*usecs) ; delay 1 msec *
; *
; use the DelayCy macro with the 'msecs' or 'usecs' multipliers *
; in the operand plus or minus some number of cycles to produce *
; precise clock independent isochronous timing. *
; *
;******************************************************************
radix dec
clock equ 8 ; user clock frequency in MHz
;
; DelayCy() operand multipliers
;
usecs equ clock/4 ; cycles/microsecond multiplier
msecs equ usecs*1000 ; cycles/millisecond multiplier
; *
; DelayMS(), DelayUS(), and DelayCy() macros *
; *
DelayMS macro pDelay ; milliseconds
DelayCy(pDelay*msecs) ; convert to cycles
endm ;
DelayUS macro pDelay ; microseconds
DelayCy(pDelay*usecs) ; convert to cycles
endm
DelayCy macro pDelay ; cycles (Tcy), minimum 16
local cycles
cycles = pDelay
while cycles > 262032
movlw high((262016-16)/4)+1
movwf TMRH
movlw low((262016-16)/4)
call DelayLo-(262016%4)
cycles -= 262016
endw
movlw high((cycles-16)/4)+1
movwf TMRH
movlw low ((cycles-16)/4)
call DelayLo-(cycles%4)
endm
; *
; example code for simulation testing; *
; *
SimTest DelayCy(20*msecs) ; remember to set 'clock' equate
nop ; put simulator break point here
; *
;******************************************************************
; *
; Delay(16..262159 Tcy) subroutine Mike McLaren, K8LH, Jun'07 *
; *
; 12 words, 1 RAM variable, 14-bit core *
; *
Delay.16
nop ; entry point for delay%4 == 3 |B0
nop ; entry point for delay%4 == 2 |B0
nop ; entry point for delay%4 == 1 |B0
DelayLo addlw -1 ; subtract 4 cycle loop time |B0
skpnc ; borrow? yes, skip, else |B0
goto DelayLo ; do another loop |B0
nop ; |B0
DelayHi addlw -1 ; subtract 4 cycle loop time |B0
decfsz TMRH,F ; done? yes, skip, else |B0
goto DelayLo ; do another loop |B0
goto $+1 ; burn off 2 cycles |B0
return ;
; *
;******************************************************************
Last edited by Mike, K8LH; 6th May 2008 at 12:07 PM. | |
| |
|
| Tags |
| 16f84, calling, delay |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Atmel, assembly:displaying on lcd | Haidy | Micro Controllers | 13 | 11th February 2008 09:13 PM |
| Motor Controllers and serial comm? | RedCore | Micro Controllers | 18 | 3rd July 2007 02:27 AM |
| Randomness of 16F84 program - sometimes works somtimes doesn | FusionITR | Micro Controllers | 10 | 28th February 2006 10:06 AM |
| Delay routine not working | gregmcc | Micro Controllers | 6 | 18th September 2005 06:23 PM |
| Effects | stephenpic | Micro Controllers | 6 | 19th January 2004 12:57 PM |