Quantcast
Channel: PIC24, what's wrong with my program?
Viewing all articles
Browse latest Browse all 18

Re: PIC24, what's wrong with my program? (kelvinu)

$
0
0
The forum does not like the word "dec lare" without the space !
 
This works on the simulator as is. cut from one of my projects.
 
It flashes an led at 1hz
 

 
;led-flash v1.0 (c)K.Unsworth 30-08-2014
;
;for Home use only. NOT FOR COMMERCIAL USE
;clock switch works .
;


        .equ __24f16ka102, 1
        .include "p24f16ka102.inc"
    

;*****************Configuration bits:**************************

       config __FWDT, FWDTEN_OFF              ;Turn off Watchdog Timer

;        config __CONFIG1, FNOSC_FRC & FWDTEN_OFF
;         internal rc oscilator on  and watch dog off

;        config __FOSC, FCKSM_CSECMD & IOL1WAY_OFF & OSCIOFNC_ON & POSCMD_NONE
;        clock switching on , multiple configs, i/o pins on, primary osc disabled

;        config __FOSCSEL, FNOSC_FRC & IESO_OFF
;        fast rc osc no pll ( yet), two speed osc off

;        set pll , tuning , clk div in main code then swap clocks


        config __FOSCSEL, FNOSC_FRCPLL
;        fast rc osc with pll
        config __FOSC, FCKSM_CSECMD & OSCIOFNC_ON & POSCMOD_NONE
;clock source set to 4 MHz * 4xPLL - 16 MHZ alter in code to 8MHz for 32 MHz 16 mips

; Clock Switching is disabled and Fail Safe Clock Monitor is disabled
; OSC2 Pin Function: OSC2 is Clock Output ( might need to change)
; Primary Oscillator Mode: Disabled


;********Global Dec larations: ***********************************************

        .global _wreg_init       ;Provide global scope to _wreg_init routine
                                 ;In order to call this routine from a C file,
                                 ;place "wreg_init" in an "extern" dec laration
                                 ;in the C file.

        .global __reset                ;The label for the first line of code.

        .global __T1Interrupt       ;Dec lare Timer 1 ISR name global

 ;***************Constants stored in Program space**************************

        .section .const,psv
;       .palign 2                ;Align next word stored in Program space to an
                                 ;address that is a multiple of 2

;        <0x0> =chr$(0)  put 0 at end of string to mark end
lcddata1:    
        .ascii    "UPI",<0x0>


;***************** variables in Near data memory (Lower 8Kb of RAM)*************

          .section .nbss, bss, near
;    var1:              .space 2                  ;Example of allocating 1 word of space for
                                            ;variable "var1".
    intcounter:        .space 2                ;standard counter

       

    flags:            .space 2


;********************constants for code************************

        .equ    LED,15

   

;*************Start of program**************


.text                                     ;Start of Code section
__reset:
        MOV     #__SP_init, W15          ;Initalize the Stack Pointer
        MOV     #__SPLIM_init, W0         ;Initialize the Stack Pointer Limit Register
        MOV     W0, SPLIM
        NOP                                ;Add NOP to follow SPLIM initialization      
; reset all w register  this MUST be done
        CLR     W0
        MOV     W0, W14
        REPEAT     #12
        MOV     W0, [++W14]
        CLR     W14

;************************************************
;clock setup

        bclr    CLKDIV,#RCDIV0         ;turn this bit off for 32Mhz (16mips)

;****************************************************************

;set up i/o pins
        mov        #0xff73,w0                ;b1111 1111 0111 0011
        mov        w0,TRISA                ;set trisa
        mov        #0x320f,w0                ;b0011 0000 0000 1111
        mov        w0,TRISB                ;set trisb



;Heart beat
;RB15=LED pin 26


;*************************************************************

;setup timer 1 for 1msec interrupts

        clr        TMR1                    ;clear timer 1
        mov        #200,w12                ;setup intcounter for WD LED
        mov        w12,intcounter          ;save countdown value
        mov        #16000,w7                ;16000=1000usec at 16 mips    1khz    
        mov        W7,PR1                    ;set timer 1 time out period when PR1=TMR1=T1 interupt
        bclr    IFS0,#T1IF                ;clear t1 interupt flag IFS0,#T1IF
        bset    IEC0,#T1IE                ;set interupt enable IEC0,#T1IE
        bset    T1CON,#TON                ;turn on t1 16 bit timer



;**********************************************************************


main:
   
;your main code here

        bra     main                    ; loop



;**********************************************************

__T1Interrupt:
        push.s                        ;save w0-3
        dec        intcounter            ;dec counter
        btss    SR,#Z                ;if not zero do nothing
        bra        intcnotzero                    
        btg        LATB,#LED            ;toggle LED    
        mov        #500,w0                ;reset counter    w0 has been pushed into shadow
        mov        w0,intcounter        ;

intcnotzero:
        bclr     IFS0, #T1IF         ;Clear the Timer 1 Interrupt flag Status bit.
        pop.s                        ;restore w0-3
        retfie                      ;Return from Interrupt Service routine




;************************************************************
.end


Viewing all articles
Browse latest Browse all 18

Latest Images

Trending Articles





Latest Images