TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: angelcastrosr en 08 de Abril de 2008, 10:23:13
-
Hola Amigos,
Quisiera solicitarles el favor de mirar el siguiente código. La idea es generar el encendido y apagado constante de una serie de leds conectados a los pines 5, 6, y 7 (GP2, GP1, y GP0) de un PIC 12F629. He escrito el código en assembler utilizando el MPLAB; después de simularlo con MPLAB SIM corre bien, pero los estados de los bits del registro GPIO no cambian; sin embargo los del registro TRISIO si van desde 0x09 - 0x0A - 0x0C. ¿está bien escrito? . He estado buscando en el foro y en internet, tengo el datasheet, pero por mas cambios que he hecho no consigo ver nada a la salida.
Algunas partes del código son de las plantillas que carga el MPLAB para cada PIC:
list p=12F629 ; list directive to define processor
#include <p12F629.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
INT_VECTOR CODE 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
; these first 4 instructions are not required if the internal oscillator is not used
main call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
bcf STATUS,RP0 ;banco 0
clrf GPIO ;inicializar GPIO
movlw 08h
movwf CMCON ;salidas digitales
bsf STATUS,RP0 ;banco 1
movlw 08h
movwf TRISIO ;GP<0:2> salidas y GP<3> entrada
inicio movlw 01h
movwf GPIO
nop
nop
movlw 2h
movwf GPIO
nop
nop
movlw 4h
movwf GPIO
nop
nop
goto inicio
; initialize eeprom locations
EE CODE 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'
-
Bienvenido angelcastror,
Hay un pequenio detalle en tu codigo simplemente lo que es es que nunca te regresas al banco 0.
Un segmento de tu codigo es este:
bsf STATUS,RP0 ;banco 1
movlw 08h
movwf TRISIO ;GP<0:2> salidas y GP<3> entrada
inicio movlw 01h
movwf GPIO
Y lo que deberia ser es esto:
bsf STATUS,RP0 ;banco 1
movlw 08h
movwf TRISIO ;GP<0:2> salidas y GP<3> entrada
bcf STATUS,RP0 ;Banco0
inicio movlw 01h
movwf GPIO
Saludos y que este bien.
Elreypic.
-
Bueno, para ver el problema completo habría que tener el linker file ya que está hecho en relocatable mode, pero más allá de eso, puedo ver un par de errores que me parece son la causa de tu problema
Donde dice
movlw 08h
movwf CMCON ;salidas digitales
Cambialo por
movlw 07h
movwf CMCON ;Apaga el módulo comparador por completo
Y donde dice
movlw 08h
movwf TRISIO ;GP<0:2> salidas y GP<3> entrada
bcf STATUS,RPO
inicio
movlw 01h
Agregale lo que está en azul.
-
Muchísimas gracias Maunix y elreypic. He realizado los cambios que me han señalado y la simulación va bien. Ahora pasaré al montaje...
-
Hola, quería pedir un gran favor. Supongo quer tu montaje es para leds RGB. Una parte de mi proyecto necesita un pic 12f629 para controlar unos leds. Cada vez que se activa el pulsador cambia de color aleatoriamente. Pienso que este programa es muy similar al tuyo, sino igual, y me da muchos problemas. Te agradecería que me dejases echarle un vistazo al código fuente para ver donde fallo.
Muchas gracias