Hola:
¿Alguien puede hechar una mano para adaptar este PIC 12F83 al 12F629/675?
Su código fuente es:
¿Alguien puede hechar una mano para adaptar este PIC 12F83 al 12F629/675?
Su código fuente es:
Código:
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_OFF & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSCIO
;***** VARIABLE DEFINITIONS******************
w_temp EQU 0x70 ; variable used for context saving
status_temp EQU 0x71 ; variable used for context saving
FLAGS EQU 0x20 ;software state register
PULSER EQU 0x21 ;pulse on counter
DWELLTIMER EQU 0x22 ;pulse off counter
STATE EQU 0x23 ;programmed state
BUTTONHOLD EQU 0x24
FREQR EQU 0x25 ;frequency value
TEMP1 EQU 0x26
TEMP2 EQU 0x27
PULSEL EQU 0x28
DWELLTIMEL EQU 0x29
TEMP5 EQU 0x2A
LEDBLINK EQU 0x2B
TEMP3 EQU 0x2C
;*******bits in FLAGS register***********
PULSEONR equ 0
PULSEONL equ 1
TRIGOUT equ 2
LEDHI equ 3
STATECHANGE equ 4
;*******bits in STATE register***********
RIGHTACTIVE equ 0
LEFTACTIVE equ 1
;*********GPIO pin names*****************
LEDL equ 5
LEDR equ 4
BUTTONR equ 2
BUTTONL equ 3
TRIGGERR equ 0
TRIGGERL equ 1
;**********Speed settings: change these to change speed (0x05-0xFF)
FIRERATE1 equ 0x2F
FIRERATE2 equ 0x16
FIRERATE3 equ 0x12
FIRERATE4 equ 0x0F
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
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
;Take a good note here. OSC is left at default 4MHz.
; We are running at 1MHz instruction cycle, or 1 micro second
;Timer 2 is prescaled 1:4 and compared (PR2) to 250.
; we now have hardware interupt that falls every 1ms exactly
;within limitation of osctune. Main code is inconsequential.
;PULSE and DWELL values control the signals precisely.
;All pulse logic is switched within the few microseconds to
;service the interupt routine. DO NOT modify the ISR
;with any kind of 'wait' or 'loop'. If you want to trigger
; timed events do so by setting an open FLAG bit and have the
;event done in the main loop.
btfss PIR1, TMR2IF ;timer 2 int happened
retfie
;**************** LED blinking *********************************************
;Our main routine will turn the flag bit
;LEDON on or off. The 10ms pulse is a duty cycle
;for the code to work with both CG and
;matrix controllers.
BlinkLed
btfss FLAGS, LEDHI
goto LedLow
decfsz LEDBLINK, f ;if pulse is active, count down 10ms
goto RightLED
movlw 0x0A
movwf LEDBLINK
bcf FLAGS, LEDHI ;10ms done, turn off LEDHI bit
goto RightLED
LedLow
decfsz LEDBLINK, f ;LEDLO time, count down 10ms
goto RightLED
movlw 0x0A
movwf LEDBLINK
bsf FLAGS, LEDHI ;10ms done, turn LEDHI bit on
RightLED
btfsc STATE, RIGHTACTIVE ;is RF on?
goto OutputRightLED
bsf STATUS, RP0 ;bank 1
bsf TRISIO, LEDR ;tristate LED
bcf STATUS, RP0 ;bank 0
goto LeftLED
OutputRightLED
btfsc FLAGS, LEDHI ;if ledhi true,
bsf GPIO, LEDR ;turn output hi
btfss FLAGS, LEDHI ;if ledhi flase,
bcf GPIO, LEDR ;turn led output lo
bsf STATUS, RP0 ;bank 1
bcf TRISIO, LEDR ;turn output on
bcf STATUS, RP0 ;bank 0
LeftLED
btfsc STATE, LEFTACTIVE ;is RF on?
goto OutputleftLED
bsf STATUS, RP0 ;bank 1
bsf TRISIO, LEDL ;tristate LED
bcf STATUS, RP0 ;bank 0
goto RightTrigger
OutputleftLED
btfsc FLAGS, LEDHI ;if ledhi true,
bsf GPIO, LEDL ;turn output hi
btfss FLAGS, LEDHI ;if ledhi flase,
bcf GPIO, LEDL ;turn led output lo
bsf STATUS, RP0 ;bank 1
bcf TRISIO, LEDL ;turn output on
bcf STATUS, RP0 ;bank 0
;**************** Right trigger logic***************************************
RightTrigger
btfsc STATE, RIGHTACTIVE ;is RF on?
goto ActiveR
bsf STATUS, RP0 ;bank 1
bsf TRISIO, TRIGGERR ;output off
bcf STATUS, RP0 ;bank 0
goto LeftTrigger
ActiveR
btfss FLAGS, TRIGOUT ;controllertype
bcf GPIO, TRIGGERR ;determines
btfsc FLAGS, TRIGOUT ;output state
bsf GPIO, TRIGGERR
btfss FLAGS, PULSEONR ;is pulse active?
goto OffstateR
decfsz PULSER, f ;if pulse is active, count down 10ms
goto LeftTrigger
bcf FLAGS, PULSEONR ;10ms is over, clear flags and
bsf STATUS, RP0 ;bank 1
bsf TRISIO, TRIGGERR ;tristate output
bcf STATUS, RP0 ;bank 0
movf FREQR, w ;and reset pulse time.
movwf PULSER
goto LeftTrigger
OffstateR
decfsz DWELLTIMER, f ;count down dwell time to next pulse
goto LeftTrigger
bsf FLAGS, PULSEONR ;if dwell is done turn on outputs
bsf STATUS, RP0 ;bank 1
bcf TRISIO, TRIGGERR ;and reset pulse time
bcf STATUS, RP0 ;bank 0
movf FREQR, w ;from frequency value
movwf DWELLTIMER
LeftTrigger
btfsc STATE, LEFTACTIVE ;is RF on?
goto ActiveL
bsf STATUS, RP0 ;bank 1
bsf TRISIO, TRIGGERL ;output off
bcf STATUS, RP0 ;bank 0
goto EndInterupt
ActiveL
btfss FLAGS, TRIGOUT ;controllertype
bcf GPIO, TRIGGERL ;determines
btfsc FLAGS, TRIGOUT ;output state
bsf GPIO, TRIGGERL
btfss FLAGS, PULSEONL ;is pulse active?
goto OffstateL
decfsz PULSEL, f ;if pulse is active, count down 10ms
goto EndInterupt
bcf FLAGS, PULSEONL ;10ms is over, clear flags and
bsf STATUS, RP0 ;bank 1
bsf TRISIO, TRIGGERL ;tristate output
bcf STATUS, RP0 ;bank 0
movf FREQR, w ;and reset pulse time.
movwf PULSEL
goto EndInterupt
OffstateL
decfsz DWELLTIMEL, f ;count down dwell time to next pulse
goto EndInterupt
bsf FLAGS, PULSEONL ;if dwell is done turn on outputs
bsf STATUS, RP0 ;bank 1
bcf TRISIO, TRIGGERL ;and reset pulse time
bcf STATUS, RP0 ;bank 0
movf FREQR, w ;from frequency value
movwf DWELLTIMEL
EndInterupt
bcf PIR1, TMR2IF
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
;*************************************SUBROUTINES**********************************
Wait10ms
clrf TEMP2
movlw 0x0D
movwf TEMP1 ;rough 10ms timer for button debounce.
Loop1
decfsz TEMP2, f ;count down 256*3=768 cycles
goto Loop1
decfsz TEMP1, f ;count down 768*13=9986 cycles
goto Loop1
return
;*************************************************************
ReadEE
bsf STATUS , RP0 ;Bank1
movlw 0x02
movwf EEADR
bsf EECON1 , RD ;start read
movf EEDAT , W
bcf STATUS , RP0 ;Bank0
return
;*************************************************************
WriteEE
bsf STATUS , RP0
movwf EEDAT
movlw 0x02
movwf EEADR
bsf EECON1,WREN ;Enable write
bcf INTCON, GIE ;Disable INTs
btfsc INTCON, GIE ;See AN576
goto $-2
movlw 0x55 ;Unlock write
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR ;Start the write
WaitForEEWrite
btfsc EECON1, WR ;wait for hardware to clear (done writing)
goto WaitForEEWrite
bcf STATUS , RP0 ;Bank0
bsf INTCON, GIE ;Enable INTS
return
;**********************************************************************************
;**********************************************************************************
;**********************************************************************************
main
clrf GPIO
clrf FLAGS ;clear outputs and code status register
movlw 0x07
movwf CMCON0 ;comparators off
bsf STATUS, RP0 ;bank 1
movlw 0x0F ;start with 0-3 inputs (ADC read)
movwf TRISIO ;pin 0 & 1 & 5 out, all other inputs
movlw 0x51 ;Fosc/16, pin 0 analog
movwf ANSEL ;Right trigger is analog input
movlw 0x04
movwf WPU ;enable week pullups
bcf OPTION_REG, 7 ;enable all week pullups
bcf STATUS, RP0 ;bank 0