Moderadores: andre_luis, 51, guest2003, Renie
bcf STATUS,RP0 ;Bank 0
clrf GPIO ;Init GPIO
movlw 07h ;Set GP<2:0> to
movwf CMCON ;digital IO
bsf STATUS,RP0 ;Bank 1
clrf ANSEL ;Digital I/O
;Abaixo, exemplo para setar portas,
;já setadas no seu código, não usar.
;movlw 0Ch ;Set GP<3:2> as inputs
;movwf TRISIO ;and set GP<5:4,1:0> ;as outputs
vanessa escreveu:A lição 6.5 do tutorial nao funcionou. Estou tentando fazer agora a 6.6 que é idêntica à 6.5 mas que possui um led a mais que fica piscando pelo interrupt Timer0 em GP0, enquanto espera que o botao do interrupt externo (que é o que eu quero aprender mas tá dificil) seja pressionado e que fará com que acenda o led em GP1.
Pois bem a 6.6 tambem nao funcionou nada. Foi aí que eu resolvi trocar a palavra de configuração. Pra minha surpresa o led que pisca pelo Timer0 interrupt funcionou.
ao invés de _MCLRE_ON eu usei _MCLRE_OFF
ao invés de _BODEN_OFF eu usei _BODEN_ON
não usei _PWRTE, nem _CP, nem _CPD (nem ON nem OFF, deixei em branco)
Era asssim (segundo o tutorial)
__CONFIG _MCLRE_ON & _CP_OFF & _CPD_OFF & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
ficou assim:
__CONFIG _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
Não vi nada entre uma palavra de configuração e outra que pudesse impedir o funcionamento do programa, mas o fato é que trocando uma palavra pela outra o programa funciona.
Obs: Já fiz o que os amigos RobL e EvandrPic sugeriram mas nao resolveu.
Abaixo segue o tutorial 6.6
;************************************************************************
; *
; Filename: MA_L6-Flash+Toggle_LED-ext-int.asm *
; Date: 23/6/09 *
; File Version: 1.1 *
; *
; Author: David Meiklejohn *
; Company: Gooligum Electronics *
; *
;************************************************************************
; *
; Architecture: Midrange PIC *
; Processor: 12F629 *
; *
;************************************************************************
; *
; Files required: none *
; *
;************************************************************************
; *
; Description: Lesson 6 example 6 *
; *
; Demonstrates handling of multiple interrupt sources *
; *
; Toggles LED on GP1 when pushbutton on INT is pressed *
; (high -> low transition triggering external interrupt) *
; while LED on GP0 flashes at 1 Hz (driven by Timer0 interrupt) *
; *
;************************************************************************
; *
; Pin assignments: *
; GP0 - flashing LED *
; GP1 - "button pressed" indicator LED *
; INT - pushbutton (active low) *
; *
;************************************************************************
list p=12F675
#include <p12F675.inc>
errorlevel -302 ; no warnings about registers not in bank 0
;***** CONFIGURATION
; ext reset, no code or data protect, no brownout detect,
; no watchdog, power-up timer, 4Mhz int clock
__CONFIG _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
;__CONFIG _MCLRE_ON & _CP_OFF & _CPD_OFF & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; pin assignments
constant nF_LED=0 ; flashing LED on GP0
constant nB_LED=1 ; "button pressed" indicator LED on GP1
;***** VARIABLE DEFINITIONS
CONTEXT UDATA_SHR ; variables used for context saving
cs_W res 1
cs_STATUS res 1
GENVAR UDATA_SHR ; general variables
sGPIO res 1 ; shadow copy of GPIO
t0_cnt res 1 ; counts timer0 interrupts
; (decremented by ISR every 250 us)
p_5ms_cnt res 1 ; counts 5 ms periods
; (decremented by ISR every 5 ms)
;************************************************************************
RESET CODE 0x0000 ; processor reset vector
pagesel Start
goto Start
;***** INTERRUPT SERVICE ROUTINE
ISR CODE 0x0004
; *** Save context
movwf cs_W ; save W
movf STATUS,w ; save STATUS
movwf cs_STATUS
; *** Identify interrupt source
btfsc INTCON,INTF ; external
goto ext_int
btfsc INTCON,T0IF ; Timer0
goto t0_int
goto isr_end ; none of the above, so exit
ext_int ; *** Service external interrupt
; Triggered on high -> low transition on INT pin
; caused by externally debounced pushbutton press
;
bcf INTCON,INTF ; clear interrupt flag
; toggle "button pressed" LED
movlw 1<<nB_LED ; toggle indicator LED
xorwf sGPIO,f ; using shadow register
goto isr_end
t0_int ; *** Service Timer0 interrupt
; TMR0 overflows every 250 clocks = 250 us
; (only Timer0 interrupts are enabled)
;
movlw .256-.250+.3 ; add value to Timer0
banksel TMR0 ; for overflow after 250 counts
addwf TMR0,f
bcf INTCON,T0IF ; clear interrupt flag
; count interrupts for 5 ms (20 interrupts x 250 us)
decfsz t0_cnt,f ; decrement interrupt count
goto isr_end ; when count = 0 (every 20 interrupts = 5 ms)
movlw .5000/.250 ; reload count
movwf t0_cnt
; toggle flashing LED every 500 ms
decfsz p_5ms_cnt,f ; decrement 5 ms period count
goto end_flash ; when count = 0 (every 100 times = 500 ms)
movlw .500/.5 ; reload count
movwf p_5ms_cnt
movf sGPIO,w ; toggle LED
xorlw 1<<nF_LED ; using shadow register
movwf sGPIO
end_flash
goto isr_end
isr_end ; *** Restore context then return
movf cs_STATUS,w ; restore STATUS
movwf STATUS
swapf cs_W,f ; restore W
swapf cs_W,w
retfie
;***** MAIN PROGRAM
MAIN CODE
Start ; calibrate internal RC oscillator
call 0x03FF ; retrieve factory calibration value
banksel OSCCAL ; then update OSCCAL
movwf OSCCAL
;***** Initialisation
; configure port
movlw ~(1<<nB_LED|1<<nF_LED) ; configure LED pins as outputs
banksel TRISIO
movwf TRISIO
; configure timer
movlw b'11001000' ; configure Timer0:
; --0----- timer mode (T0CS = 0)
; ----1--- no prescaling (PSA = 1)
; (prescaler assigned to WDT)
banksel OPTION_REG ; -> increment TMR0 every 1 us
movwf OPTION_REG
; initialise port
banksel GPIO
clrf GPIO ; start with all LEDs off
clrf sGPIO ; update shadow
; initialise variables
movlw .5000/.250 ; timer0 overflow count = 5ms/250us
movwf t0_cnt ; (-> 5ms/switch sample)
movlw .500/.5 ; 2 ms period count = 500ms/5ms
movwf p_5ms_cnt ; (-> toggle LED every 500ms)
; configure external interrupt
banksel OPTION_REG
bcf OPTION_REG,INTEDG ; trigger on falling edge (INTEDG = 0)
; enable interrupts
movlw 1<<GIE|1<<T0IE|1<<INTE ; enable external, Timer0
movwf INTCON ; and global interrupts
;***** Main loop
loop
; continually copy shadow GPIO to port
banksel GPIO
movf sGPIO,w
movwf GPIO
; repeat forever
goto loop
END
ao invés de _MCLRE_ON eu usei _MCLRE_OFF
vanessa escreveu:Graaaaaaaaaaaande dica!
Agora esta tudo funcionando, tanto com 12f629 quanto com o 12f675!
Usei CMCON em 0x7 para o 12F675 funcionar.
Valeu!!
Vou tentar avisar o autor que o tutorial dele tem esse erro, já que para um circuito como no do tutorial dele:
http://www.servidorbigua.comli.com/adicion/mclr_on.JPG
o MCLR deve ser configurado para OFF.
Valeu!! Não tenho nem palavras para agradecer, pois estou (estava) a semanas empacada nisso. Muito obrigada mesmo!
Usuários navegando neste fórum: Google [Bot] e 1 visitante