Agora Cart SHULTZ ELECTRONICS
Electronics Info Page
     Home | Return Policy | About Us | Contact Us | Online Scanner | terms of service

Search:


Categories

Antennas (14)
   Amateur (2)
   Mounts (5)
Connectors (5)
   Adaptors (2)
   Audio (1)
   RF (2)
Electronic Parts (2)
   Capacitors (1)
   Resistors (1)
Fuse Holders (1)
Integrated Circuits (1)
Wire & Cable (1)


Search by Price

Search Between:

$ &




16F628 CODE TEMPLATE

The following code was written to help beginners migrating from the Microchip 16F84
to  the 16F628. Many people have hesitated making this move because they are 
not sure exactly what changes need to be made in order for the 628 to respond like an
F84.  As when moving to any new chip, make sure that the necessary changes are
made inside MPLAB or whatever compiler you are using. Also check your config. bits
when programming so the correct Oscillator is selected.
The following code will flash an LED once each second for a duration of 1/2 second.
I hope this supplies everyone with a takeoff point to start using the more versatile 16F628.
Cut and paste this into your compiler.
Be sure to set your configuration bits when programming the following:
***** CODE BEGINS CUT HERE *****
LIST      P=16F628     	; LIST DIRECTIVE TO DEFINE PROCESSOR
#INCLUDE <P16F628.INC> 	; PROCESSOR SPECIFIC VARIABLE DEFINITIONS
	
;__CONFIG B'11110100000010'
;__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _ER_OSC_CLKOUT
; & _MCLRE_ON & _LVP_OFF
; '__CONFIG' DIRECTIVE IS USED TO EMBED CONFIGURATION DATA WITHIN .ASM FILE.
; THE LABLES FOLLOWING THE DIRECTIVE ARE LOCATED IN THE RESPECTIVE .INC FILE.
; SEE RESPECTIVE DATA SHEET FOR ADDITIONAL INFORMATION ON CONFIGURATION WORD.
;****************************************************************************
;***** VARIABLE DEFINITIONS
W_TEMP        		EQU    		0X28       
STATUS_TEMP   		EQU    		0X29       
COUNTERA		EQU		0X2A
COUNTERB		EQU		0X2B
COUNTERC		EQU		0X27
;****************************************************************************
SETUP		
	BSF		STATUS,5  ;BANK SWITCH TO BANK 1
	MOVLW		B'00011111'  ;SETS PORTA TO INPUTS
	MOVWF		TRISA
	MOVLW		B'00000000' ;SETS PORTB TO OUTPUTS
	MOVWF		TRISB
	MOVLW		B'01000010'
	MOVWF		OPTION_REG
	
	MOVLW		B'00000111'  ;THIS HAS TO BE DONE IN ORDER TO USE 
	MOVWF		CMCON		;PORTA AS YOU WOULD AN F84
					;THIS TURNS OFF THE CAPTURE 
					;AND COMPARE
; THE FOLLOWING INSTRUCTIONS CLEAR THE CALLED REGISTERS BEFORE USING THEM. 
;I HIGHLY RECOMMEND THIS 
; ALWAYS CLEAR YOUR PORTA AND PORTB REGISTER 
;SO YOU KNOW THEY ARE CLEAR BEFORE USING THEM!!!!!!!!!
	CLRF		FLAG		
	CLRF		PORTA
	CLRF		PORTB		
	GOTO		MAIN
MAIN
	BSF		PORTB,1	;CONNECT LED TO PORTB,1
	CALL		DELAY	;WAIT 1/2 SECOND
	BCF		PORTB,1	;TURN OFF LED 
	CALL		DELAY	;CALL 1/2 DELAY TWICE
	CALL		DELAY
	GOTO		MAIN	;GO DO IT AGAIN
DELAY
;PIC Time Delay = 0.5000000 s with Osc = 4.000000 MHz
	MOVLW	D'3'
	MOVWF	COUNTERC
	MOVLW	D'140'
	MOVWF	COUNTERB
	MOVLW	D'83'
	MOVWF	COUNTERA
LOOP	DECFSZ	COUNTERA,1
	GOTO	LOOP
	DECFSZ	COUNTERB,1
	GOTO	LOOP
	DECFSZ	COUNTERC,1
	GOTO	LOOP
	RETURN	
	END		;THATS ALL FOLKS!!!!!

SHULTZ ELECTRONICS
58 SMOKEY CREST DRIVE
MORGANTOWN, WV  26508

PHONE 304-594-3020
Or Call Toll Free 1-888-474-8589
EMAIL US!!!!


Featured Product

featured product

VHF Marine Band Antenna Model 1600
No ground plane design.
$ 24.95


Copyright © 2001-2008 by K-Factor Technologies Inc.
Powered by AgoraCart Gold. Maintained by Mister Ed at AgoraCart.com