Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to start PIC16F676 ...??

Status
Not open for further replies.
hi Ian,
Sent you a PM about 1hr ago, ref this ADC setup problem on OSH.

E.
 
I want to clear this why there is double __ underscore???
__config 0x3D14
 
Last edited:
so, we are using this Oscillator:-
100 = INTOSC oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN

and
MCLRE: RA3/MCLR pin function select(5)
1 = RA3/MCLR pin function is MCLR

what does this mean?
bit 13-12 BG1:BG0: Bandgap Calibration bits for BOD and POR voltage(1)
00 = Lowest bandgap voltage
11 = Highest bandgap voltage
 
New code for you ritesh..... Put this into oshonsoft assembler it works ok now

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

Band gao voltage associated with BOD & POR Brown Out Detect and Power On Reset Read section 9.3.5 on this topic.
 
Last edited:
please explain more this part of code...

CLRF OPTION_REG??
CLRF VRCON??

I was just trying to find out why the ADC wasn't being turned off.

VRCON is for the voltage reference module (it's unused, so I disabled it)
OPTION_REG has interrupt settings so I disabled them all.

ORG 0
GOTO INIT

Try to get into the habit of including this. When you use tables and interrupts you'll need to jump over them.
 
Please clear one more doubt __config why two underscore not single is that also set in data sheet??
 
__config is a makro.. written by someone in microchip... To know why there is two underscores you'll need to find him and ask him.

Usually the underscore is used in C for assembler routines... purely for keeping identifiers apart.... If it was declared just config... It would mean no-one could use this identifier.

The datasheet may well have two, its depends on the font used.

Sorry... Its a directive for the assembler / linker, not a makro.....
 
Last edited:
Hi,

Please explain the function of bit 3, i am not getting its working.
MOVLW 0x7
MOVWF CMCON



19h CMCON — COUT — CINV CIS CM2 CM1 CM0
bit 3 CIS: Comparator Input Switch bit
When CM2:CM0 = 110 or 101:
1 = VIN- connects to CIN+
0 = VIN- connects to CIN
 
In the above code i don't understand if the decrement is not working what the need of it??
movlw 0fh
movwf 0x21
dECfsz 0x21,f
 
I have done some changes in delay for LED remain glowing for few seconds..
But the OSHON shows HARDWARE STACK OVERFLOW after running simulator.

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
again:	dECfsz 0x21,f
	call again
	clrf PORTC
	RETURN
 
end
 
hi Ritesh,
Code:
[B]again[/B]:	dECfsz 0x21,f
	[B]call again[/B]
	clrf PORTC
	RETURN

Your code is wrong, its calling itself, so it will over flow the STACK
 
The code given by IAN also is not working this part the F is decremented to E only....!!

movlw 0fh
movwf 0x21
dECfsz 0x21,f
clrf PORTC

from:->


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


delay
movlw 0xff
movwf PORTC
movlw 0fh
movwf 0x21; you are reloading 0x21 with 0Fh
dECfsz 0x21,f; DEC by 1 count
clrf PORTC ; clearing PORTC.
RETURN; now returning!!!

The decfsz is NOT being used a Conditional Instruction!!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top