i am trying to get this 16f722 pic to work but nothing is doing, what am i doing wrong, it just puts leds on all ports..
Rich (BB code):
;******************************************************************************
; This file is a basic code template for code generation on the PIC16F722. *
; This file contains the basic code building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on features of *
; the assembler. *
; *
; Refer to the respective data sheet for additional *
; information on the instruction set. *
; *
;******************************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
;******************************************************************************
; *
; Files Required: P16F722.INC *
; *
;******************************************************************************
; *
; Features of the 16F722: *
; *
; Precision Internal Oscillator (16 MHz or 500 kHz operation) *
; On Chip 3.2 V Regulator *
; Pinout compatible to other 28/40 pin PIC16CXXX and 16FXXX micros *
; Brownout reset with selectable trip points *
; 8 bit resolution and 14 channel A/D Converter *
; Wide operating voltage range (1.8-5.5V) *
; A/D converter with selectable 1.024, 2.048, 4.096 voltage reference *
; AUSART, SPI, and IIC *
; *
;******************************************************************************
; *
; Notes: *
; *
; *
;******************************************************************************
; *
; Revision History: *
; *
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST p=16F722 ; list directive to define processor
#INCLUDE <P16F722.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _DEBUG_OFF & _PLL_EN & _BORV_1_9 & _BOR_OFF & _CP_OFF & _MCLR_DIS & _PWRT_DIS & _WDT_OFF & _INTOSCIO
__CONFIG _CONFIG2, _VCAP_DIS
errorlevel -302 ; suppress banksel warning messages during assembly
errorlevel -311 ; suppress HIGH operator warning messages during assembly
errorlevel -207 ; no messages
;------------------------------------------------------------------------------
;
; VARIABLE DEFINITIONS
;
; Available Data Memory divided into Bank 0 through Bank 3. Each Bank contains
; Special Function Registers and General Purpose Registers at the locations
; below:
;
; SFR GPR SHARED GPR's
; Bank 0 0x00-0x1F 0x20-0x6F 0x70-0x7F
; Bank 1 0x80-0x9F 0xA0-0xBF 0xF0-0xFF
; Bank 2 0x100-0x11F 0x170-0x17F
; Bank 3 0x180-0x19F 0x1F0-0x1FF
;***** VARIABLE DEFINITIONS
CBLOCK 0x20 ; user file mnames
Temp
HUNS
TENS
UNIITS
d1
d2
d3
d4
RESULTAD
ENDC
W_TEMP EQU 0x7F ; w register for context saving (shared)
STATUS_TEMP EQU 0x7E ; status used for context saving (shared)
PCLATH_TEMP EQU 0x7D ; pc used for context saving (shared)
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET ORG 0x0000 ; processor reset vector
GOTO MAIN ; go to beginning of program
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ISR ORG 0x0004 ; interrupt vector location
; Context saving for ISR
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into W register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Restore context before returning from interrupt
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
MAIN
; set up registers *************************************************** SEE PAGE 48 DATASHEET
BANKSEL OSCCON
MOVLW B'00111100' ; set 16mhz clock internal
MOVWF OSCCON
BANKSEL PORTA ; select register
CLRF PORTA ;Init PORTA as digital ( = analouge i/p)
BANKSEL ANSELA ; select register
CLRF ANSELA ;digital I/O
BANKSEL TRISA
movlw .0
movwf TRISA ; set all outputs
BANKSEL PORTB ; select register
CLRF PORTB ;Init PORTB as digital( 1 = analouge i/p)
BANKSEL ANSELB ; digital i/o
CLRF ANSELB
BANKSEL TRISB
movlw .0
movwf TRISB ; set all outputs
BANKSEL PORTC ; select register
CLRF PORTC ; init PORTC
BANKSEL TRISC
movlw .0
movwf TRISC ; SET ALL OUTPUTS
BANKSEL OSCCON ; select oscillator
MOVLW b'00111100' ; set up osc as 16Mhz clock 2% accuracy high osc mode
MOVWF OSCCON
BANKSEL OPTION_REG ; select option reg
MOVLW b'00000111' ; set up rtcc to prescale 256, pullups off
MOVWF OPTION_REG ; do it
clrf PORTA
clrf PORTB ; clear all ports
clrf PORTC
goto START ; start programme
;**********************************************************
;------------------------------------------------------------------------------
START
movlw .255
movwf PORTA ; put leds on
movwf PORTB
movwf PORTC
goto START
END
Last edited by a moderator: