This is a multi-part message in MIME format. ------=_NextPart_000_002F_01C04CE8.596356A0 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0030_01C04CE8.596356A0" ------=_NextPart_001_0030_01C04CE8.596356A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable hi! I am using the 16F877, 4MHz processor. I have this problem with getting the recive(UART) to work. I have tried = too get both the interrupt and polling to work. It used to work so I = guess I just missed something somewhere. when I run the program it = stopps just after GET_DATA after all the INIT:s. it can't get passed the = RCIF flag. this should work without the interrupt(INTCON) set I think. = nothing happens to the interrupt as well. it never goes to the interrupt = vector. I have made macros for the BANK0 and BANK1 and they work. when I = simulate the program with mplab all the reg. works. I am just using = GET_DATA now but want to use interrupts when I get it to work. at the = moment nothing happens. there is no problem to send data(TXD) only to = recive. I have attached the hole program if anyone could be so kind to have a = look at it. thanks. this is just a part of it here in the mail.=20 /nabil ;***** VARIABLE DEFINITIONS w_temp EQU 0x70 ; variable used for context saving=20 status_temp EQU 0x71 ; variable used for context saving S_OUT EQU 0X72 TEST2 EQU 0X74 TEST3 EQU 0X75 S_IN EQU 0X76 S_IN_CHECK EQU 0X77 ORG 0x000 ; processor reset vector CLRF PCLATH ; ensure page bits are cleared 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 ; isr code can go here or be located as a call subroutine elsewhere =20 BSF PORTB,4=20 =20 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 =20 RETFIE ; return from interrupt ;****** sends 1 byte to TxD. ********* SEND_DATA =20 MOVF S_OUT,W =20 BANK0 =20 MOVWF TXREG ;txreg fylls med s_out. BANK1 =20 NOT =20 BTFSS TXSTA,TRMT ;tests to se if data sent GOTO NOT ;if not empety go back and try agsain. BANK0 =20 =20 RETURN=20 =20 ;******* recives 1 byte from RxD. ***** GET_DATA =20 BANK0 BSF PORTB,7 EMPTY BTFSS PIR1, RCIF GOTO EMPTY BSF PORTB,6=20 BANK0 MOVF RCREG,W MOVWF S_IN =20 RETURN ;********** Port setup **************** =20 INIT_PORT =20 BANK0 CLRF PORTC =20 CLRF PORTB=20 BANK1 MOVLW H'80' =20 MOVWF TRISC ;bit 7(rx), is input. all the rest is = output. MOVLW H'00' =20 MOVWF TRISB ;all id outputs. BANK0 =20 RETURN INIT_INTERRUPT =20 ;CLRF PCLATH MOVLW B'11000000' ;move h'00' to clear all the interrupts. MOVWF INTCON ;SET ALL INTERRUPTS =20 RETURN ;********** serie port init *********** =20 INIT_SERIE =20 BANK1 MOVLW 0X19 ;4MHz/9600=20 MOVWF SPBRG =20 =20 BCF TXSTA, SYNC BSF TXSTA, BRGH ;sets the high speed transmit. =20 BSF PIE1, RCIE ;sets the recive interrupt ready.=20 BSF TXSTA, CSRC ;too test the transfer BCF TXSTA, TRMT BANK0 BSF RCSTA, SPEN =20 BSF RCSTA, CREN ;needed to recive data. BANK1 =20 BSF TXSTA, TXEN ;make the txreg ready to send data BANK0 RETURN ;************************************* MAIN CALL INIT_PORT ;sets up all the i/o ports. CALL INIT_SERIE ;starts the serie connection. CALL INIT_INTERRUPT ;starts the interrupt. =20 MOVLW H'30' MOVWF S_OUT CALL SEND_DATA START=20 CALL GET_DATA GOTO START END ; directive 'end of program' ------=_NextPart_001_0030_01C04CE8.596356A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 hi!
I=20 am using the 16F877, 4MHz processor.
I have this problem with getting = the=20 recive(UART) to work. I have tried too get both the interrupt and = polling to=20 work. It used to work so I guess I just missed something somewhere. when = I run=20 the program it stopps just after GET_DATA after all the INIT:s. it can't = get=20 passed the RCIF flag. this should work without the interrupt(INTCON) set = I=20 think. nothing happens to the interrupt as well. it never goes to the = interrupt=20 vector.
I have made macros for the BANK0 and BANK1 and they work. = when I=20 simulate the program with mplab all the reg. works. I am just using = GET_DATA now=20 but want to use interrupts when I get it to work. at the moment nothing = happens.=20 there is no problem to send data(TXD) only to recive.

I have = attached the=20 hole program if anyone could be so kind to have a look at = it. thanks. this=20 is just a part of it here in the mail.

 =20 /nabil



  ;***** VARIABLE DEFINITIONS
 =20 w_temp        =20 EQU     = 0x70        ;=20 variable used for context saving
  status_temp  =20 EQU     = 0x71        ;=20 variable used for context saving
  S_OUT  EQU = 0X72
 =20 TEST2  EQU 0X74
  TEST3  EQU 0X75
  S_IN  = EQU=20 0X76
  S_IN_CHECK EQU 0X77



  =20 ORG    =20 0x000           &n= bsp; ;=20 processor reset vector
   CLRF   =20 PCLATH            = ;=20 ensure page bits are cleared
   GOTO   =20 MAIN           &nb= sp; =20 ; go to beginning of program


   = ORG    =20 0x004           &n= bsp; ;=20 interrupt vector location
   MOVWF  =20 w_temp            = ; save=20 off current W register contents
   MOVF=20 STATUS,w          ; move = status=20 register into W register
   MOVWF=20 status_temp       ; save off contents of = STATUS=20 register


  ; isr code can go here or be located as a = call=20 subroutine elsewhere
  
   BSF PORTB,4=20
  
   MOVF = status_temp,w     ;=20 retrieve copy of STATUS register
   MOVWF=20 STATUS            = ;=20 restore pre-isr STATUS register contents
   = SWAPF  =20 w_temp,f
   SWAPF  =20 w_temp,w          ; restore = pre-isr=20 W register contents
  
  =20 RETFIE           &= nbsp;       =20 ; return from interrupt


  ;****** sends 1 byte to TxD.=20 *********

  SEND_DATA    =20
         = MOVF   =20 S_OUT,W    =20
        =20 BANK0         =20
         MOVWF  =20 TXREG           ;txreg = fylls=20 med s_out.
         = BANK1 =20
  NOT       =20
        BTFSS TXSTA,TRMT ;tests = to se if=20 data sent
        GOTO NOT  = ;if not=20 empety go back and try = agsain.
       =20 BANK0 
       =20
        RETURN=20
      
  ;******* recives 1 = byte from=20 RxD. *****

  = GET_DATA
      =20
          =20 BANK0
           = BSF=20 PORTB,7
 =20 EMPTY
         =20 BTFSS   PIR1,=20 RCIF
         =20 GOTO   =20 EMPTY
          BSF = PORTB,6=20
         =20 BANK0
          MOVF=20 RCREG,W
          MOVWF=20 S_IN
      =20
         =20 RETURN


  ;********** Port setup=20 ****************    

 =20 INIT_PORT
  
        = BANK0
        CLRF=20 PORTC           &n= bsp;   =20
        CLRF    = PORTB=20
       =20 BANK1
        MOVLW  =20 H'80'           =20
        MOVWF  =20 TRISC           ;bit = 7(rx), is=20 input. all the rest is = output.
       =20 MOVLW   H'00'     =20
        MOVWF TRISB  ;all id = outputs.
        = BANK0
  =20
        RETURN

 =20 INIT_INTERRUPT
  
       = ;CLRF=20 PCLATH
       MOVLW B'11000000' ;move = h'00' to=20 clear all the interrupts.
       MOVWF=20 INTCON  ;SET ALL INTERRUPTS
  =20
       RETURN

  = ;********** serie=20 port init ***********   

 =20 INIT_SERIE
      =20
      = BANK1
     =20 MOVLW =20 0X19           =20 ;4MHz/9600
      MOVWF   =20 SPBRG         =20
     
      = BCF TXSTA,=20 SYNC
      BSF   TXSTA,=20 BRGH     ;sets the high speed=20 transmit.    
      BSF = PIE1,=20 RCIE ;sets the recive interrupt ready. =
      BSF=20 TXSTA, CSRC ;too test the transfer
      BCF = TXSTA,=20 TRMT
      = BANK0
     =20 BSF  RCSTA, SPEN     =
     =20 BSF     RCSTA, CREN     ;needed = to=20 recive data.
      = BANK1    =20
      BSF     TXSTA,=20 TXEN     ;make the txreg ready to send=20 data
     =20 BANK0

      RETURN

 =20 ;*************************************
 =20 MAIN

       CALL  INIT_PORT = ;sets up=20 all the i/o ports.
       CALL = INIT_SERIE=20 ;starts the serie connection.
       = CALL=20 INIT_INTERRUPT ;starts the interrupt.
  =20
       MOVLW=20 H'30'
       MOVWF=20 S_OUT
       CALL  = SEND_DATA
 =20 START
      CALL=20 GET_DATA
      GOTO START

 =20 END           &nbs= p;          =20 ; directive 'end of program'

------=_NextPart_001_0030_01C04CE8.596356A0-- ------=_NextPart_000_002F_01C04CE8.596356A0 Content-Type: application/octet-stream; name="robot.asm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="robot.asm" ;********************************************************************** ; This file is a basic code template for assembly code generation * ; on the PICmicro PIC16F877. This file contains the basic code * ; building blocks to build upon. * = ; * ; If interrupts are not used all code presented between the ORG * ; 0x004 directive and the label main can be removed. In addition * ; the variable assignments for 'w_temp' and 'status_temp' can * ; be removed. * = =20 ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler (Document DS33014). * ; * ; Refer to the respective PICmicro data sheet for additional * ; information on the instruction set. * ; * ; Template file assembled with MPLAB V4.00 and MPASM V2.20.00. * ; * ;********************************************************************** ; * ; Filename: robot.asm * ; Date: 2000-11-06 * ; File Version: 1.0 * ; * ; Author: Nabil Benhadj * ; Company: Malm=F6 university = * ; *=20 ; * ;********************************************************************** ; * ; Files required: * ; * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** list p=3D16f877 ; list directive to define processor #include ; processor specific variable definitions =09 __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & = _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF=20 ; '__CONFIG' directive is used to embed configuration data within .asm = file. ; The lables following the directive are located in the respective .inc = file. ;***** VARIABLE DEFINITIONS w_temp EQU 0x70 ; variable used for context saving=20 status_temp EQU 0x71 ; variable used for context saving S_OUT EQU 0X72 TEST2 EQU 0X74 TEST3 EQU 0X75 S_IN EQU 0X76 S_IN_CHECK EQU 0X77 ;******** defineing variables ******** =20 #DEFINE BAND1_RIKTNING PORTB,7 ;1=3Dfoward, 0=3Dback. #DEFINE BAND2_RIKTNING PORTB,6 ;1=3Dfoward, 0=3Dback. #DEFINE BAND1_BROMS PORTB,5 ;0=3Dbreak, 1=3Dgo. #DEFINE BAND2_BROMS PORTB,4 ;0=3Dbreak, 1=3Dgo. ;******* macron ********************** BANK0 MACRO BCF STATUS,RP0 ENDM BANK1 MACRO BSF STATUS,RP0 ENDM ;******** macro for the streering ******** BREAK1_ON MACRO BCF BAND1_BROMS ENDM BREAK2_ON MACRO BCF BAND2_BROMS ENDM BREAK1_OFF MACRO=09 BSF BAND1_BROMS ENDM =09 BREAK2_OFF MACRO BSF BAND2_BROMS=09 ENDM GO1_BACK MACRO BCF BAND1_RIKTNING ENDM GO2_BACK MACRO BCF BAND2_RIKTNING ENDM GO1_FOWARD MACRO BSF BAND1_RIKTNING ENDM GO2_FOWARD MACRO BSF BAND2_RIKTNING ENDM=09 ;********************************************************************** ORG 0x000 ; processor reset vector CLRF PCLATH ; ensure page bits are cleared 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 ; isr code can go here or be located as a call subroutine elsewhere ;test sequens{ ;MOVF S_IN,W ;MOVWF S_OUT ;CALL SEND ;} end TEST=09 ;check what command the robot is getting. ;MOVLW H'07' ;for testing. ;MOVWF S_IN =09 ;CALL GET_DATA BSF PORTB,4=09 =09 =09 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 =09 RETFIE ; return from interrupt ;****** interrupt vector ************* INTERRUPT_VECTOR MOVF S_IN,W MOVWF S_IN_CHECK ;uses this so that the value don=B4t change in the = middle =09 =09 MOVLW H'31' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO LEFT =09 MOVLW H'32' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO FOWARD =09 MOVLW H'33' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO RIGHT =09 MOVLW H'34' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO STOP =09 MOVLW H'35' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO SPIN_LEFT MOVLW H'36' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO BACK MOVLW H'37' SUBWF S_IN_CHECK,W ;checks to see if right number. SKPNZ ;skip if not right number GOTO SPIN_RIGHT RETURN_INTERRUPT=09 =09 RETURN ;****** instructions for the robot ******* FOWARD BREAK1_ON BREAK2_ON CALL DELAY BREAK1_OFF BREAK2_OFF GO1_FOWARD GO2_FOWARD GOTO RETURN_INTERRUPT LEFT BREAK1_ON BREAK2_ON CALL DELAY ;wait a while. BREAK2_OFF GO2_FOWARD GOTO RETURN_INTERRUPT =09 RIGHT BREAK1_ON BREAK2_ON CALL DELAY ;wait a while. BREAK1_OFF GO1_FOWARD GOTO RETURN_INTERRUPT STOP BREAK1_ON BREAK2_ON GOTO RETURN_INTERRUPT BACK BREAK1_ON BREAK2_ON CALL DELAY ;wait a while. BREAK2_OFF BREAK2_OFF GO1_BACK GO2_BACK GOTO RETURN_INTERRUPT SPIN_LEFT BREAK1_ON BREAK2_ON CALL DELAY ;wait a while. BREAK2_OFF BREAK1_OFF GO1_BACK GO2_FOWARD GOTO RETURN_INTERRUPT SPIN_RIGHT=09 BREAK1_ON BREAK2_ON CALL DELAY ;wait a while. BREAK2_OFF BREAK1_OFF GO1_FOWARD GO2_BACK GOTO RETURN_INTERRUPT ;****** sends 1 byte to TxD. ********* SEND_DATA =20 MOVF S_OUT,W =20 BANK0 =20 MOVWF TXREG ;txreg fylls med s_out. BANK1 =09 NOT =20 BTFSS TXSTA,TRMT ;tests to se if data sent GOTO NOT ;if not empety go back and try agsain. BANK0 =09 =20 RETURN=20 =20 ;******* recives 1 byte from RxD. ***** GET_DATA =20 BANK0 BSF PORTB,7 EMPTY BTFSS PIR1, RCIF GOTO EMPTY BSF PORTB,6=20 BANK0 MOVF RCREG,W MOVWF S_IN =20 RETURN ;********** Port setup **************** =20 INIT_PORT =09 BANK0 CLRF PORTC =20 CLRF PORTB=09 BANK1 MOVLW H'80' =20 MOVWF TRISC ;bit 7(rx), is input. all the rest is = output. MOVLW H'00' =20 MOVWF TRISB ;all id outputs. BANK0 =09 RETURN INIT_INTERRUPT =09 ;CLRF PCLATH MOVLW B'11000000' ;move h'00' to clear all the interrupts. MOVWF INTCON ;SET ALL INTERRUPTS =09 RETURN ;********** serie port init *********** =20 INIT_SERIE =20 BANK1 ;MOVLW 0x81 ;20M/9600 =20 MOVLW 0X19 ;4MHz/9600 ;MOVLW 0XCF ;4MHz/19200 =09 MOVWF SPBRG =20 ;MOVLW B'00100000' ;MOVWF PIE1 ;MOVLW B'10100100' ;MOVWF TXSTA BCF TXSTA, SYNC BSF TXSTA, BRGH ;sets the high speed transmit. =20 BSF PIE1, RCIE ;sets the recive interrupt ready.=09 BSF TXSTA, CSRC ;too test the transfer BCF TXSTA, TRMT BANK0 ;MOVLW B'10010000' ;MOVWF RCSTA ;MOVLW B'11000000' ;MOVWF INTCON BSF RCSTA, SPEN =20 BSF RCSTA, CREN ;needed to recive data. BANK1 =20 BSF TXSTA, TXEN ;make the txreg ready to send data. BANK0 RETURN ;******* A DELAY FUNCTION ************ DELAY =09 MOVLW H'FF' MOVWF TEST2 MOVWF TEST3 LOOP1 NOP DECFSZ TEST2,1 GOTO LOOP2 GOTO SLUT LOOP2 NOP DECFSZ TEST3,1 GOTO LOOP2 GOTO LOOP1 SLUT=09 RETURN=09 ;************************************* MAIN CALL INIT_PORT ;sets up all the i/o ports. CALL INIT_SERIE ;starts the serie connection. CALL INIT_INTERRUPT ;starts the interrupt. =09 ;BSF PORTB,7 ;BREAK2_OFF =09 MOVLW H'30' MOVWF S_OUT CALL SEND_DATA START=09 CALL GET_DATA ;CALL INTERRUPT_VECTOR BSF PORTB,4 GOTO START END ; directive 'end of program' ------=_NextPart_000_002F_01C04CE8.596356A0-- -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu