16f722 wont run

Thread Starter

Dodgydave

Joined Jun 22, 2012
11,306
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:

ErnieM

Joined Apr 24, 2011
8,377
What does it do in the simulator? While the simulator is not perfect (somethings like r-m-w don't sim as they work in the real world) the rule is "if it don't sim you can't win."

You should be able to see what register is not seats you intended... Or you can just directly set registers to try other settings that may be necessary before the port bits work digitally.
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
11,306
Give up on the 18F? :)
I cut my teeth on the 16F but find the 18f quite a bit simpler if using assembly prog. no bank switching to worry about, among other simpler commands.
I familiarized myself with PIC's after using Motorola many years ago.
Here http://www.winpicprog.co.uk/pic_tutorial.htm
Max.

Just got both pics new and would like to get
get both running, never used these before so i am lost? I normally use the 16f690 and so thought i would migrate to a more output pic, if you have one to recommend like the 16f690 with 24 I/O then please do so.
 
Last edited:

Thread Starter

Dodgydave

Joined Jun 22, 2012
11,306
Look's like the code is looping through START with all bits on ports A-C set HI continuously.

Yes its supposed to light up all led's, but nothing is happening, there must be something else set wrong in the config or what, ITS NOT THE LEDS BEFORE ANYONE JUMPS IN, its in a prototype board so it can run other other pics as well so i know its this pic that's not working.

I just cant seem to fathom it out,a simple output to the ports put the leds on and NOWT?
 
Last edited:

absf

Joined Dec 29, 2010
1,968
Rich (BB code):
        BANKSEL  PORTA        ;just add this line
	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
Allen
 

Thread Starter

Dodgydave

Joined Jun 22, 2012
11,306
Yep your both correct, i forgot to banksel porta
one of the perils of migration, new set up codes!,
Cheers guys its working.
 
Last edited:
Top