Autor Tema: pic16F628 con rs232 programa  (Leído 2045 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado monge_22

  • PIC10
  • *
  • Mensajes: 17
pic16F628 con rs232 programa
« en: 31 de Marzo de 2006, 04:20:00 »
Hola buenas estoy utilizando el pic16F628 y lo tengo que comunicar con el ordenador y ver lo que pasa en el hyperterminal.
Os queria pedir si alguno teneis un programa, muy sencillo de este pic para que me comunique con el ordenador. Con que el programa que me dejeis me ponga en la pantalla del hyperterminal un printf me vale, esque llevo unos cuantos dias intentando hacerlo y no consigo comunicar y si tengo un programa que este bien seguro que me ayuda para ver donde cometo el error.
Muchas gracias.

Desconectado ma-tec

  • Colaborador
  • PIC12
  • *****
  • Mensajes: 76
    • www.matec.es.tl
RE: pic16F628 con rs232 programa
« Respuesta #1 en: 31 de Marzo de 2006, 07:16:00 »
HOLA PRUEBA ESTO

       LIST P=16F628,R=DEC     ; Use the PIC16F628 and decimal system


        #include "P16F628.INC"  ; Include header file
        errorlevel -224         ; AVISA USO DEL TRIS
        errorlevel -302         ; AVISA CAMBIO DE BANCO
   __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_OFF & _LVP_OFF
 
STATUS equ 3h                ; status register
port_a equ 5h                ; port 5 (port a) used for LED display
port_b equ 6h                ; port 6 (port b) used for data and
;Bit Defines
Z      EQU  2H
   
 CBLOCK 0x20             ; Declare variable addresses starting at 0x20

;poner aca registros
 ENDC
   

         

        ORG    0x000            ; Program starts at 0x000
;
; --------------------------------
; SET ANALOG/DIGITAL INPUTS PORT A
; --------------------------------
;
            movlw 7
        movwf CMCON             ; CMCON=7 set comperators off
;
; ----------------
; INITIALIZE PORTS
; ----------------
;
        movlw b"11111111"       ; set up portA
        movwf PORTA

        movlw b"10000100"       ; RB2(TX)=1 others are 0
        movwf PORTB

        bsf STATUS,RP0          ; RAM PAGE 1

        movlw b"11111111"       ;Port A RA0-RA3 outputs
        tris  PORTA
 

        movlw b"01100010"       ; RB7-RB4 and RB1(RX)=input, others output
        movwf TRISB

; ------------------------------------         (0.38)
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
        movlw 0x19             ; 0x19=9600 bps (0x0C=19200 bps)
        movwf SPBRG
        movlw b"00100100"       ; brgh = high (2)
        movwf TXSTA             ; enable Async Transmission, set brgh

        bcf STATUS,RP0          ; RAM PAGE 0

        movlw b"10010000"       ; enable Async Reception
        movwf RCSTA
 

            CLRF PORTA  
    INICIO      
            MOVLW  "H"
      CALL  send

            MOVLW  "O"
      CALL  send

            MOVLW  "L"
      CALL  send

            MOVLW  "A"
      CALL  send

            MOVLW  ODH
      CALL  send

            MOVLW  OAH
      CALL  send
   
        b INICIO    

;; ------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
CAP     btfss PIR1,RCIF         ; (5) check for received data
        goto CAP
        BCF  PIR1,RCIF
        movf RCREG,W            ; save received data in W
 
       
        return
;
; -------------------------------------------------------------
; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING
; -------------------------------------------------------------
;  
       
send        
        movwf TXREG             ; send data in W

TransWt bsf STATUS,RP0          ; RAM PAGE 1
WtHere  btfss TXSTA,TRMT        ; (1) transmission is complete if hi
        goto WtHere

        bcf STATUS,RP0          ; RAM PAGE 0
        return





       END

LA CLAVE DEL EXITO ES SABER
PARA DONDE VA LA GENTE Y
LLEGAR PRIMERO.


 

anything