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.
I have seen that program flow with that arrow moving with code...
but i want to see LED with switch like this in MAPlab ....
 
I have loaded you code into MPLAB..... It doesn't compile

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.)
							; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT

INIT
	BSF STATUS,RP0
	MOVLW 0x5
	MOVWF CMCON
	MOVLW 0x0
	MOVWF ANSEL 	; disable ADC
	MOVWF TRISC 	; portb as output
	MOVLW 0x3f
	MOVWF TRISA 	; porta as input
	BCF STATUS,RP0

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
For starters this chip DOESN'T have a portb, and there was no inc file.
 
I have loaded you code into MPLAB..... It doesn't compile

Sorry, i was testing this code on OSHON simulator.
OK, is this possible to watch led display, switch, lcd in map lab??
__config 0x3D14 ;sets the configuration settings (oscillator type etc.)
; HERE SET TO INTERNAL OSCILLATOR 4MHZ

please tell where to learn more about this oscillator setting?
 
Last edited:
I find that as I have a copy of Oshonsoft.. I use the config generator a little too often. Its easier to select all the bits in the config screen and write down the config reg's value..

I thought you had Proteus... You can compile directly in ISIS. run and simulate..
 
Hi,

I was testing these code in OSHON but this instruction shows an error and the above initialization(list,include) were removed ...
MOVWF ANSEL
is there any method to test PIC16f676 as OSHON does not support 676 (i think)
 
Hi,

I was testing these code in OSHON but this instruction shows an error and the above initialization(list,include) were removed ...
MOVWF ANSEL
is there any method to test PIC16f676 as OSHON does not support 676 (i think)

hi Ritesh,
Oshonsoft does support F676

Post your FULL code..

E.
 
hi Ritesh,
Oshonsoft does support F676

Post your FULL code..

E.

Sorry,
I got it lying in right half.
My code are :-

START

btfsc 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
but how to use switch in simulator i have set port a to switch but working...!!
 
Last edited:
hi,

In your program PORTA 0 & 1 are set for ADC input.!

You are testing BTFSS PORTA,1 ; its set for analog inp

The PORT pins on PORTC do toggle ON/OFF but are VERY fast, you need a longer On/OFF time.

E
 
Hi again,
In your program PORTA 0 & 1 are set for ADC input.!

You are testing BTFSS PORTA,1 ; its set for analog inp

So, what i have to change in it??
The PORT pins on PORTC do toggle ON/OFF but are VERY fast, you need a longer On/OFF time.
Sorry, i don't get you?
 
hi,
I understand that you are trying to flash an LED on PORTC.???

Run this code in Oshonsoft.
NOTE, as its simulation the flash rate will be very slow.

In a PIC the PORTC should go high for 0.5Sec and low for 0.5Sec continuous



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 0x05
	MOVWF CMCON

	BSF STATUS,RP0
	clrf ANSEL 	; disable ADC

	movlw 0x0c
	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	D'3'
		movwf	CounterC
		movlw	D'138'
		movwf	CounterB
		movlw	D'85'
		movwf	CounterA
loop		decfsz	CounterA,1
		goto	loop
		decfsz	CounterB,1
		goto	loop
		decfsz	CounterC,1
		goto	loop
		retlw	0	
		
		end
 
I understand that you are trying to flash an LED on PORTC.???

No, that i can do..
but i want to flash LED with switch reading..
any way, i want to study more about this first how it work??
__config 0x3D14
 
Look at page #54 Section 9.1 of the 16F676 datasheet.

CONFIGURATION REG
 
Hi,

I am not getting this conf bits...

bit 13-12 BG1:BG0: Bandgap Calibration bits for BOD and POR voltage(1)
00 = Lowest bandgap voltage
11 = Highest bandgap voltage
bit 11-9 Unimplemented: Read as ‘0’
bit 8 CPD: Data Code Protection bit(2)
1 = Data memory code protection is disabled
0 = Data memory code protection is enabled
bit 7 CP: Code Protection bit(3)
1 = Program Memory code protection is disabled
0 = Program Memory code protection is enabled
bit 6 BODEN: Brown-out Detect Enable bit(4)
1 = BOD enabled
0 = BOD disabled
bit 5 MCLRE: RA3/MCLR pin function select(5)
1 = RA3/MCLR pin function is MCLR
0 = RA3/MCLR pin function is digital I/O, MCLR internally tied to VDD
bit 4 PWRTE: Power-up Timer Enable bit
1 = PWRT disabled
0 = PWRT enabled
bit 3 WDTE: Watchdog Timer Enable bit
1 = WDT enabled
0 = WDT disabled
bit 2-0 FOSC2:FOSC0: Oscillator Selection bits
111 = RC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
110 = RC oscillator: I/O function on RA4/OSC2/CLKOUT pin, RC on RA5/OSC1/CLKIN
101 = INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
100 = INTOSC oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
011 = EC: I/O function on RA4/OSC2/CLKOUT pin, CLKIN on RA5/OSC1/CLKIN
010 = HS oscillator: High speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
001 = XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
000 = LP oscillator: Low power crystal on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
Note 1: The Bandgap Calibration bits are factory programmed and must be read and saved prior to erasing
the device as specified in the PIC16F630/676 Programming Specification. These bits are reflected
in an export of the configuration word. Microchip Development Tools maintain all calibration bits to
factory settings.
2: The entire data EEPROM will be erased when the code protection is turned off.
3: The entire program memory will be erased, including OSCCAL value, when the code protection is
turned off.
4: Enabling Brown-out Detect does not automatically enable Power-up Timer.
5: When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled.
 
The bits are binary, convert the hexadecimal __config value to binary and you can easily see what the settings are.

This sound better now..
But here are 14 bits and how this 3D14 is set it should be like this 3DE( i think)
 
Last edited:
Ritesh!! we are going round in circles.... I have simulated the code I sent you in Oshonsoft... I can't get RA0 or RA1 into digital mode.

Eric! Any Idea why this code will not switch off the ADC completely??

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.)
							; HERE SET TO INTERNAL OSCILLATOR 4MHZ
	ORG 0
	GOTO INIT
 
INIT
	
	MOVLW 0x5
	MOVWF CMCON
	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
 
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
 
Status
Not open for further replies.

Latest threads

Back
Top