How to start PIC16F676 ...??

Status
Not open for further replies.
Ritesh!! I never paid any mind to the delay.... I though you had engineered it for a minimum time for simulation.

There was no overflow!

Code:
delay

	movlw 0xff
	movwf PORTC 
	movlw 0fh
	movwf 0x21
	dECfsz 0x21,f
        goto $-1
	clrf PORTC
	RETURN
 
end

The delay as a delay.
 
Last edited:
Ritesh!! I never paid any mind to the delay.... I though you had engineered it for a minimum time for simulation.

There was no overflow!

Cool work....

I found the meaning from here..!!( a little search)
$ means the address you're at. $-1 means one address up. You can use it when you check a bit. Example.

start
BTFSS PORTA,1
GOTO start

instead you can write:
BTFSS PORTA,1
GOTO $-1
 
Hi,

how to change the freq of pulse as in case of duty cycle we can do by adding delay...(like PWM )
 
I have seen a program which blink LED at different duty cycles simply by adding delay to its subroutine, but in case of changing the freq of blinking LED ?
like we do this in PWM we change the duty cycle and freq of that pulse also.
So, i want to know how we can change the freq not by crystal(oscillator) internally by code??
 
If you take a look at Nigel's tutorials......Study them a bit...... There are ways to implement delays... Most programmers write two delay functions... One with uS delay and one with mS delay.

This way you can call a delay ( with the amount of uS / mS in W ) and have any delay you need.... Nigel has uS delays AND mS delays.
 
Hi,


If i want to use this code than i will convert it to Hex by map lab or OSHON then program it to PIC16f676 then make a LED to corresponding pin will thi swork or more step to folows

Code:
;include "P16F676.inc"		;include the defaults for the chip
	__config 0x3114			;sets the configuration settings (oscillator type etc.)
							; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT
 
INIT
	CLRF OPTION_REG
	BSF STATUS,RP0
	CLRF VRCON
	MOVLW 0x3f
	MOVWF TRISA 	; porta as input
	MOVLW 0x0
	CLRF ANSEL 	; disable ADC
	MOVWF TRISC 	; portb as output
	BCF STATUS,RP0
	MOVLW 0x7
	MOVWF CMCON
 
START
 
	btfss PORTA,1 	; test bit 1
	call delay
 
	GOTO START
 
delay
	movlw 0xff
	movwf PORTC 
	movlw 0fh
	movwf 0x21
	dECfsz 0x21,f
	clrf PORTC
	RETURN
 
end
 
hi Ritesh,
This code fragment is STILL wrong.
Code:
delay
	movlw 0xff
	movwf PORTC 
	movlw 0fh; you are keeping the counter at 0Fh and only decrementing to 0Eh
	movwf 0x21
	dECfsz 0x21,f
	clrf PORTC
	RETURN
 
Last edited:
hi Ritesh,
This code fragment is STILL wrong.
delay
movlw 0xff
movwf PORTC
movlw 0fh; you are keeping the counter at 0Fh and only decrementing to 0Eh
movwf 0x21
dECfsz 0x21,f
clrf PORTC



RETURN

Hi again,

I have notice that before we can use it by adding this after that decrement instruction GOTO $-1.
anyway i was asking of blinking LED code and i have posted this code. sorry.
 
Last edited:

Now i want to Go with code on my PIC chip hardware..
please tell how to make its board ??
here is my HEX code please check is that fine....??
 
Last edited:
hi,
Run this in Oshonsoft.. I have set the Delay to suit simulation. It set PORTC On/Off

Code:
	LIST	p=16F676		;tell assembler what chip we are using
	include "P16F676.inc"	;include the defaults for the chip
	__config 0x3D14			;sets the configuration settings (oscillator type etc.)
							
	errorlevel -302, -207
	
CounterA  equ 0x20
CounterB  equ 0x21
CounterC  equ 0x22
CounterD  equ 0x23
	
	; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT
 
INIT
	bcf STATUS,RP0
	clrf PORTA
	MOVLW 0x07
	MOVWF CMCON

	BSF STATUS,RP0
	clrf ANSEL 	; disable ADC

	movlw 0x0f
	MOVWF TRISA 	; porta as inp
	
	clrf TRISC	 ; portc as out	
	BCF STATUS,RP0
 	 
START
	call delay
	movlw 0xff
	movwf PORTC 
	call delay
	clrf PORTC
	GOTO START
	
;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
delay:		movlw	.1
		movwf	CounterC
		movlw	.10
		movwf	CounterB
		movlw	.50
		movwf	CounterA
loop		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		decfsz	CounterC,1
		goto	loop
		retlw	0	
		
		end
 
Last edited:
Ritesh...

These are the delay routines

Code:
Del0	retlw	0x00			;delay 0mS - return immediately
Del1	movlw	d'1'			;delay 1mS
	goto	Delay
Del5	movlw	d'5'			;delay 5mS
	goto	Delay
Del10	movlw	d'10'			;delay 10mS
	goto	Delay
Del20	movlw	d'20'			;delay 20mS
	goto	Delay
Del50	movlw	d'50'			;delay 50mS
	goto	Delay
Del100	movlw	d'100'			;delay 100mS
	goto	Delay
Del250	movlw	d'250'			;delay 250 ms
Delay	movwf	count1
d1	movlw	0xC7			;delay 1mS
	movwf	counta
	movlw	0x01
	movwf	countb
Delay_0
	decfsz	counta, f
	goto	$+2
	decfsz	countb, f
	goto	Delay_0

	decfsz	count1	,f
	goto	d1
	retlw	0x00

Put this at the end of your code and you can call any of the above... (provided you use a 4mhz Xtal)
 
hi,
Run this in Oshonsoft.. I have set the Delay to suit simulation. It set PORTC On/Off

Yes, this is working...The HEX file i posted wil that work with that code given by Wp100?
 
Last edited:
Why are you confused..... Its you who needs to choose what delays you require.... you now have three sets to choose from.
 
Ok, i am using this code of Eric...

Code:
	LIST	p=16F676		;tell assembler what chip we are using
	include "P16F676.inc"	;include the defaults for the chip
	__config 0x3D14			;sets the configuration settings (oscillator type etc.)
 
	errorlevel -302, -207
 
CounterA  equ 0x20
CounterB  equ 0x21
CounterC  equ 0x22
CounterD  equ 0x23
 
	; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT
 
INIT
	bcf STATUS,RP0
	clrf PORTA
	MOVLW 0x07
	MOVWF CMCON
 
	BSF STATUS,RP0
	clrf ANSEL 	; disable ADC
 
	movlw 0x0f
	MOVWF TRISA 	; porta as inp
 
	clrf TRISC	 ; portc as out	
	BCF STATUS,RP0
 
START
	call delay
	movlw 0xff
	movwf PORTC 
	call delay
	clrf PORTC
	GOTO START
 
;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
delay:		movlw	.1
		movwf	CounterC
		movlw	.10                             ; changing its value to .30 for more delay.!!!!
		movwf	CounterB
		movlw	.50
		movwf	CounterA
loop		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		decfsz	CounterC,1
		goto	loop
		retlw	0	
 
		end

I am attaching the HEX code of it please have a look whether is right??
and i have assembled it by MAP LAB
 
Ok, i am using this code of Eric...

Code:
	LIST	p=16F676		;tell assembler what chip we are using
	include "P16F676.inc"	;include the defaults for the chip
	__config 0x3D14			;sets the configuration settings (oscillator type etc.)
 
	errorlevel -302, -207
 
CounterA  equ 0x20
CounterB  equ 0x21
CounterC  equ 0x22
CounterD  equ 0x23
 
	; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT
 
INIT
	bcf STATUS,RP0
	clrf PORTA
	MOVLW 0x07
	MOVWF CMCON
 
	BSF STATUS,RP0
	clrf ANSEL 	; disable ADC
 
	movlw 0x0f
	MOVWF TRISA 	; porta as inp
 
	clrf TRISC	 ; portc as out	
	BCF STATUS,RP0
 
START
	call delay
	movlw 0xff
	movwf PORTC 
	call delay
	clrf PORTC
	GOTO START
 
;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
delay:		movlw	.1
		movwf	CounterC
		movlw	.10                             ; changing its value to .30 for more delay.!!!!
		movwf	CounterB
		movlw	.50
		movwf	CounterA
loop		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		decfsz	CounterC,1
		goto	loop
		retlw	0	
 
		end

I am attaching the HEX code of it please have a look whether is right??
and i have assembled it by MAP LAB
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…