Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Parallel slave port

Status
Not open for further replies.

viks_raj

New Member
Hi guys

I am sending data from 16C773 to 18f4580 using PSP.

I am posting part of code using PSP ,can you tell me what is wrong here.


Code:
   org 0x0000 
;************ initial ******************* 
    
   goto start 
    ;****************************** 
              org 0x0018 
              goto int_serv 

start 
    banksel    ADCON1 
    movlw      0x0F 
    movwf      ADCON1       
    movlw      0xff          ; All Port D pins are inputs 
    movwf         TRISD          ; 
    CLRF       PORTD 
    movlw      0x17 
    movwf      TRISE 
    movlw      0x00          ; All Port C pins are outputs 
    movwf         TRISC          ; 
    CLRF       PORTC 
   banksel      INTCON 
   clrf       INTCON 
   movlw      0x80 
   movwf      PIE1      ;enable Parallel Slave Port 
..... 
.... 
.....Do some stuff here. 

int_serv 
                banksel PIR1 
   btfss PIR1,PSPIF 
   goto nothing 
   bcf PIR1,PSPIF    
   banksel TRISE       
   btfss TRISE,IBF 
   goto nothing 
   movf PORTD,W 
   movwf PORTC 
nothing    
    
   retfie 

   end
 
I assume this code is for the PIC18F4580 chip.

To use location 0018h as interrupt vector, you have to enable the interrupt priority feature by setting bit7 of RCON. Then you also have to set bit6 of INTCON (GIEL) to enable low priority interrupts. Ensure that PSPIP bit is cleared.

BTW on the PIC18 family, banksel is not required because all the special function registers are located in the access bank.

On the interrupt service routine, you can avoid using the WREG register by using the instruction:

Code:
    MOVFF PORTD,PORTC

Then you don't have to worry about context saving during interrupts which was omitted in your code.

Lastly, this looks like code orginally coming from a PIC16 family. With the PIC18 family, the BRA is an optimum instruction over the GOTO because you aren't jumping too far.
 
motion said:
On the interrupt service routine, you can avoid using the WREG register by using the instruction:

Code:
    MOVFF PORTD,PORTC

Then you don't have to worry about context saving during interrupts which was omitted in your code.

Lastly, this looks like code orginally coming from a PIC16 family. With the PIC18 family, the BRA is an optimum instruction over the GOTO because you aren't jumping too far.
Or you can use
Code:
retfie fast

Instead of retfie itself. This will take care of saving Wreg, BSR, and STATUS registers.

I recommend you to use 0008h Interrupt vector instead, therefore you don't hava to "play" with setting interrupt priorities:
motion said:
To use location 0018h as interrupt vector, you have to enable the interrupt priority feature by setting bit7 of RCON. Then you also have to set bit6 of INTCON (GIEL) to enable low priority interrupts. Ensure that PSPIP bit is cleared.
 
Thanks alot both of you.
I will surely make changes today and post result here.
Please have a look later.

thanks once again.
 
I have tried both Low priority and High as well.
Means 0008 and 0018 both.
but no result.

Due to some reason my 16C773 is not able to give generate interrupt for 18f4580.

Although I have tested CS and WR ,these signals are OK.
and data is also there on PSP lines.
but then also interrupt is not generated.

I am giving pulse of 30 micro sec on WR and CS.
Is it OK ??
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top