Aditya070390
Newbie level 6
- Joined
- Dec 12, 2012
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,384
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; Delay = 10 seconds ; Clock frequency = 4 MHz ; Actual delay = 10 seconds = 10000000 cycles ; Error = 0 % cblock d1 d2 d3 endc Delay ;9999995 cycles movlw 0x5A movwf d1 movlw 0xCD movwf d2 movlw 0x16 movwf d3 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto Delay_0 ;1 cycle nop ;4 cycles (including call) return
list p=12F508 ; list directive to define processor
#include <p12F508.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
;***** VARIABLE DEFINITIONS
temp EQU 0x07 ;example variable definition
currinput res 1
level res 1
dry res 1
;or
cblock 0x08
d1 ; delay work files
d2
d3
endc
;**********************************************************************
ORG 0x1FF ; processor reset vector
ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
start
movlw b'00000000'
movwf GPIO
movlw b'00010011' ;setting GP 0,1,4 as i/p's and remaining as o/p's
tris GPIO
mainloop
movf GPIO,w ;tis functions reads the values of sensors at gp0 and gp1
andlw b'00010011' ; and jumps to corresponding level of the tank
andlw b'00000011'
movwf currinput ; 00--tank high
btfsc STATUS,2 ; 11--tank low
goto tank_high ; 10--tank middle
BTFSC currinput,0
goto tank_low
goto tank_midd
tank_low ; in dis function the water level is low and so the output is
bcf level,0 ; turned ON.
movlw b'00000100'
movwf GPIO
nop
call Delay ;calling delay
nop
movf GPIO,w ;reading GP4 input
andlw b'00010000'
movwf dry
btfsc dry,4 ; if the bit is high, it must stop condition
goto stop ; if its loe it goes to mainloop
goto mainloop
tank_high ; tis is tank full situation and the output is turnd OFF
bsf level,0
movlw b'00000000'
movwf GPIO
nop
goto mainloop
tank_midd ;tis is tank middle condition and the output is kept on or off depending on the level register
btfsc level,0
goto tank_high
goto tank_low
stop ;tis is a stop condition.the motor is kept off forever
movlw b'00000000'
movwf GPIO
goto stop
; Delay = 10 seconds
; Clock frequency = 4 MHz
; Actual delay = 10 seconds = 10000000 cycles
; Error = 0 %
Delay
;9999995 cycles
movlw 0x5A
movwf d1
movlw 0xCD
movwf d2
movlw 0x16
movwf d3
Delay_0
decfsz d1, f
goto jump1
decfsz d2, f
jump1 goto jump2
decfsz d3, f
jump2 goto Delay_0
nop ; 1 cycle
;4 cycles (including call)
retlw 00
END ; directive 'end of program'
Delay
;9999995 cycles
movlw 0x5A
movwf reg1
movlw 0xCD
movwf reg2
movlw 0x16
movwf reg3
Delay_0
decfsz reg1, f
goto Delay_0
decfsz reg2, f
goto Delay_0
decfsz reg3, f
goto Delay_0
retlw 00
ohk i got it..so i tried the code shown below and now am getting an error. "stack overflow error"
Code:Delay ;9999995 cycles movlw 0x5A movwf reg1 movlw 0xCD movwf reg2 movlw 0x16 movwf reg3 Delay_0 decfsz reg1, f goto Delay_0 decfsz reg2, f goto Delay_0 decfsz reg3, f goto Delay_0 retlw 00
cblock 0x07
d1 ; delay work files
d2
d3
currinput
level
dry
endc
list p=12F508 ; list directive to define processor
#include <p12F508.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
;***** VARIABLE DEFINITIONS
cblock 0x07
d1 ; delay work files
d2
d3
currinput
level
dry
endc
;**********************************************************************
ORG 0x1FF ; processor reset vector
ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
start
call delay
movlw b'00000000'
movwf GPIO
movlw b'00010011' ;setting GP 0,1,4 as i/p's and remaining as o/p's
tris GPIO
mainloop
movf GPIO,w ;tis functions reads the values of sensors at gp0 and gp1
andlw b'00010011' ; and jumps to corresponding level of the tank
andlw b'00000011'
movwf currinput ; 00--tank high
btfsc STATUS,2 ; 11--tank low
goto tank_high ; 10--tank middle
BTFSC currinput,0
goto tank_low
goto tank_midd
tank_low ; in dis function the water level is low and so the output is
bcf level,0 ; turned ON.
movlw b'00000100'
movwf GPIO
nop
call Delay ;calling delay
nop
movf GPIO,w ;reading GP4 input
andlw b'00010000'
movwf dry
btfsc dry,4 ; if the bit is high, it must stop condition
goto stop ; if its loe it goes to mainloop
goto mainloop
tank_high ; tis is tank full situation and the output is turnd OFF
bsf level,0
movlw b'00000000'
movwf GPIO
nop
goto mainloop
tank_midd ;tis is tank middle condition and the output is kept on or off depending on the level register
btfsc level,0
goto tank_high
goto tank_low
stop ;tis is a stop condition.the motor is kept off forever
movlw b'00000000'
movwf GPIO
goto stop
; Delay = 10 seconds
; Clock frequency = 4 MHz
; Actual delay = 10 seconds = 10000000 cycles
; Error = 0 %
Delay
;9999995 cycles
movlw 0x5A
movwf d1
movlw 0xCD
movwf d2
movlw 0x16
movwf d3
Delay_0
decfsz d1, f
goto jump1
decfsz d2, f
jump1 goto jump2
decfsz d3, f
jump2 goto Delay_0
nop ; 1 cycle
;4 cycles (including call)
retlw 00
END ; directive 'end of program'
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?