Delay 16f88 assembly language

Status
Not open for further replies.

omg, I can't thank you enough, mr eric.

I do have spare pins, but what do you mean by brake / holding solenoid? I read a bit about holding solenoid, but there's not much information.
Would you mind giving me material on it? I need more information on how it works and how to apply that in my circuit.


please disregard about what I said above. I have watched some videos on youtube about it, it is more on the mechanical device part rather than in electronic part, isn't it?
When the current is high, the brake solenoid (the protruding part) will pop out to break and when the current goes low, the brake solenoid will retract like a turtle.
Now, I need some enlightenment on how to use it to support my servo. If you have any idea, please do tell me. ^^

thank you.

Regards.
 
Last edited:
Hi, I simulated the following program using MPLAB IDE v8.30.
HTML:
list p=16f88
#include <pic16f88.inc>


OSCCON	equ	0x8F
STATUS	equ	0x03
PORTA	equ	0x05
PORTB	equ	0x06
ANSEL	equ	0x9B
TRISA	equ	0x85
TRISB	equ	0x86
d1		equ	0x20
d2		equ	0x21
d3		equ	0x22

;cblock	0x20
;d1
;d2
;d3
;endc

org 0x00

main	;main loop
;********setting the internal RC clock frequency

call 	banksel1
movlw 	0x6E ;freq = 4MHz, bit 1 and 0 are 10 because internal RC is used for the system clock
movwf	OSCCON

movlw	0x00
movwf	ANSEL ;setting all pins to digital pins
clrf	TRISA ;setting all port A into output
clrf	TRISB ;setting all port B into output

call	banksel0
clrf	PORTA;set all port A into LOW
clrf	PORTB;set all port B into LOW

main_loop

;move to neutral***
bsf		PORTA,0 ;set pin 17 HIGH
call 	delay1.5ms
bcf		PORTA,0 ;set pin 17 LOW
call	delay18.5ms

call	delay60s

goto	main_loop

goto	main

;***bank selections***

banksel0
bcf		STATUS,5
bcf		STATUS,6
return

banksel1
bsf		STATUS,5
bcf		STATUS,6
return

delay1.5ms ;total of 1,500 cycles
movlw	0x2B
movwf	d1
movlw	0x02
movwf	d2
goto	delay_m
return

delay18.5ms ;total of 18,500 cycles
movlw	0x73
movwf	d1
movlw	0x0F
movwf	d2
goto	delay_m
return

delay60s ;total of 6,000,000 cycles
movlw	0x23
movwf	d1
movlw	0xCB
movwf	d2
movlw	0x83
movwf	d3
goto	delay_big
return

;*actual delay routine
delay_m
decfsz	d1,f
goto	$+2
decfsz	d2,f
goto	delay_m
return

delay_big
decfsz	d1,f
goto	$+2
decfsz	d2,f
goto	$+2
decfsz	d3,f
goto	delay_big
goto	$+1
goto	$+1
return

I got these errors as the result

I tried changing the bank manually (without the use of routine) and it failed.
I tried removing the #include and it failed.
Is there anything wrong with my bank changing method?
I am loading the .asm file from my thumbdrive. Could it be the problem?

thank you.



Regards.
 
Last edited:
mplab is a spoiled kid, needs to be ended after subroutine. thank you for reading this. do come back time to time though, I will surely have some other questions.





regards.
 
mplab is a spoiled kid, needs to be ended after subroutine. thank you for reading this. do come back time to time though, I will surely have some other questions.


regards.

hi,
Reply your PM.

This should be at the start of the source code.

Code:
	list      p=16f88           ; list directive to define processor
	#include <p16F88.inc>        ; processor specific variable definitions
	errorlevel  -302 , -207  ; suppress messages 302 [Bank] and 207 [label in column 1]

	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

Set the WDT, BODEN, MCLR etc to suit your project


EDIT: your error msgs, look at the numbers on BOLD text and check with MPLAB Help for their meaning....
Use this line to supress Warning messages, dont suppress Error msgs.
errorlevel -302 , -207 ; suppress messages 302 [Bank] and 207 [label in column 1]



Warning[205] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 2 : Found directive in column 1. (list)
Error[105] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 3 : Cannot open file (Include File "pic16f88.inc" not found)
Warning[205] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 23 : Found directive in column 1. (org)
Warning[203] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 28 : Found opcode in column 1. (call)
Warning[203] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 29 : Found opcode in column 1. (movlw)
Warning[203] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 30 : Found opcode in column 1. (movwf)
Message[302] G:\FYP\MOTOR\TEST\PIC TESTING.ASM 30 : Register in operand not in bank 0. Ensure that bank bits are correct.
 
Last edited:
alright.... so far what I have gathered is warning[203] will always be there if the opcode has no label or space. so to eliminate this I will have to start every line with a space.
message[302] is just a reminder to check the bank correctly.
warning[105] can be eliminated with the line that you just gave me....
and warning[205] can be eliminated by giving space ?
well, I'll just try and find out in a few sec.
Thank you very much.


Regards.
 
alright, I just tried it....
my MPLAB requires any hexadecimal number to be written in 0x...
and about the #include error, I just deleted it because it caused error even with the addition lines. The addition lines showed up in the error as well.
I just hope that thing will work well without #include thingy....
Thank you.



Regards.
 

hi,
Your code should be formatted like this:
Also that include is required, try it without the '#' symbol in front.

Which version of MPLAB are you using.?

Code:
	list	p=16f88
#include <pic16f88.inc> 


OSCCON	equ	0x8F
STATUS	equ	0x03
PORTA	equ	0x05
PORTB	equ	0x06
ANSEL	equ	0x9B
TRISA	equ	0x85
TRISB	equ	0x86
d1	equ	0x20
d2	equ	0x21
d3	equ	0x22

;cblock	0x20 
;d1
;d2
;d3
;endc

	org	0x00

main				;main loop 
;********setting the internal RC clock frequency  

	call	banksel1
	movlw	0x6E		;freq = 4MHz, bit 1 and 0 are 10 because internal RC is used for the system clock
	movwf	OSCCON

	movlw	0x00
	movwf	ANSEL		;setting all pins to digital pins
	clrf	TRISA		;setting all port A into output
	clrf	TRISB		;setting all port B into output

	call	banksel0
	clrf	PORTA		;set all port A into LOW
	clrf	PORTB		;set all port B into LOW

main_loop 

;move to neutral***  
	bsf	PORTA,0		;set pin 17 HIGH
	call	delay1.5ms
	bcf	PORTA,0		;set pin 17 LOW
	call	delay18.5ms

	call	delay60s

	goto	main_loop

	goto	main

;***bank selections***  

banksel0 
	bcf	STATUS,5
	bcf	STATUS,6
	return

banksel1 
	bsf	STATUS,5
	bcf	STATUS,6
	return

delay1.5ms 			;total of 1,500 cycles 
	movlw	0x2B
	movwf	d1
	movlw	0x02
	movwf	d2
	goto	delay_m
	return

delay18.5ms 			;total of 18,500 cycles 
	movlw	0x73
	movwf	d1
	movlw	0x0F
	movwf	d2
	goto	delay_m
	return

delay60s 			;total of 6,000,000 cycles 
	movlw	0x23
	movwf	d1
	movlw	0xCB
	movwf	d2
	movlw	0x83
	movwf	d3
	goto	delay_big
	return

;*actual delay routine  
delay_m
	decfsz	d1,f
	goto	$+2
	decfsz	d2,f
	goto	delay_m
	return

delay_big 
	decfsz	d1,f
	goto	$+2
	decfsz	d2,f
	goto	$+2
	decfsz	d3,f
	goto	delay_big
	goto	$+1
	goto	$+1
	return
 

I have assembled your code in MPLAB OK.

Use your Windows file SEARCH for the 16F88.inc file, find where it is, let me know.
It maybe missing or in the wrong place so that MPLAB cannot find it.

Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Documents and Settings\Administrator\Desktop\forumx1.mcs".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F88 "forum1.asm" /l"forum1.lst" /e"forum1.err"
Loaded C:\Documents and Settings\Administrator\Desktop\forum1.cod.
BUILD SUCCEEDED: Wed Dec 01 10:03:57 2010

 
Last edited:
oh damn, you're right, the file does not exist.
I just downloaded it from melabs.com. Where should I put this file in?

Thanks/


Regards.
 
oh damn, you're right, the file does not exist.
I just downloaded it from melabs.com. Where should I put this file in?

Thanks/



Regards.

I would look under C:\Program Files\Microchip\MPASM Suite there should be all the PIC types include files in that location.
 
I think the one that I just downloaded is a different include file. damn, why didn't they just put in the installer. -.-'
Thank you for your help, mr eric.


Regards.
 
I think the one that I just downloaded is a different include file. damn, why didn't they just put in the installer. -.-'
Thank you for your help, mr eric.


Regards.

Which version of MPLAB are you using.??

Attached, change the .txt back to .inc
 

Attachments

  • P16F88.txt
    16.7 KB · Views: 212
oh right, I forgot to tell you, I'm using 8.6, just downloaded earlier.

mr eric, I just found that my wdt is still active and I want to turn it off.
However, I am a little bit confused with CONFIG1 register... It is addressed in 2007h. Can I really access that memory location?
and also, I want to use the internal oscillator and it seems that I will have to set it up again in CONFIG1, not just in OSCCON.

I got this from the datasheet...


Which one should I choose? I want it to run using internal RC oscillator at 4MHz. is it 100?

Thank you.


Regards.
 
I changed the extension into .inc, but it still is in text file. -.-
gonna bang my head on the wall.


Regards.
 
I changed the extension into .inc, but it still is in text file. -.-
gonna bang my head on the wall.
Regards.

It is a text file, with an INC extension thats all!,,,, no problem.

For the umpteenth time which MPLAB version are you using ?????????????????????

Woops, just saw your double post.

EDIT:
You use one of these options.
101 = INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin
100 = INTRC oscillator; port I/O function on both RA6/OSC2/CLKO pin and RA7/OSC1/CLKI pin
 
Last edited:
whoops, I'm using MPLAB v8.6, I've said that before my last post. sorry about it...
would you mind explaining how to access the CONFIG1 register? in which bank is it located?
Thank you.


Regards
 
whoops, I'm using MPLAB v8.6, I've said that before my last post. sorry about it...
would you mind explaining how to access the CONFIG1 register? in which bank is it located?
Thank you.
Regards

You dont access the CONFIG reg, you set the bits in the CONFIG reg
Why dont you do it this way.?? much easier to follow.

__CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
__CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

Note the BOLD type is the one for the oscillator setting, look at the datasheet for the description
 

Attachments

  • AAesp03.gif
    64 KB · Views: 144
Last edited:
oh okay, thanks a lot, mr eric, you're really really helpful.

and by the way, I wrote my include file like this:
#include <p16f88.inc>

when I wrote #include <pic16f88.inc>, it gave me an error, so I thought I could just change. After changing it, it worked fine.
Once again, thanks a lot.


Regards.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…