Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 28th March 2007, 07:41 PM   (permalink)
Default I/O Question, best way to output a byte on two ports?

I have available some I/O on two output ports (PIC)

RA 765x321x
RB xx543xxx

I want one byte of I/O (8 bits) it may be asynchronous.

Any suggestions, ideas?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 29th March 2007 at 12:33 AM.
blueroomelectronics is offline   Reply With Quote
Old 29th March 2007, 12:44 AM   (permalink)
Default

RA looks like it's the most of a full byte,
you could read in the RA byte, use a bitmask to prevent the two x bits from being overwritten and write out your data byte, which will give you all but bits 4 and 0, which you should be able to further mask out from your data byte to the leftover bits on RB. You'd still have 3 extra bits on RB so you could use one of those as a strobe 'data ready' bit if you need it to be synchronous.

That's a bit of codeing though, you could also just bit bang a synchronous serial shift register. Many people do that to increase the number of I/O pins on non speed sensative designs.
__________________
"Because I be what I be. I would tell you what you want to know if I
could, mum, but I be a cat, and no cat anywhere ever gave anyone a
straight answer, har har."

Last edited by Sceadwian; 29th March 2007 at 12:46 AM.
Sceadwian is offline   Reply With Quote
Old 29th March 2007, 02:47 AM   (permalink)
Default

Not very elegant but does the job.
Code:
	movfw	Byte
	andlw	b'11101110'
	movwf	PORTB
	btfss	Byte,0
	bcf	PORTA,3
	btfsc	Byte,0
	bsf	PORTA,3
	btfss	Byte,3
	bcf	PORTA,4
	btfsc	Byte,3
	bsf	PORTA,4
Mike
Pommie is online now   Reply With Quote
Old 29th March 2007, 03:07 AM   (permalink)
Default

If your using mikroBasic, you could do something like this

Code:
Program Port_Mask

Dim PORTX as Byte

sub procedure Write_Byte(Dim PORTX as Byte)

    TRISA.1 = 0                   ' Change to outputs
    TRISA.2 = 0
    TRISA.3 = 0
    TRISA.5 = 0
    TRISA.6 = 0
    TRISA.7 = 0
    TRISB.3 = 0
    TRISB.4 = 0

    PORTA.1 = PORTX.0        ' Build PORTX's data on the pins
    PORTA.2 = PORTX.1
    PORTA.3 = PORTX.2
    PORTA.5 = PORTX.3
    PORTA.6 = PORTX.4
    PORTA.7 = PORTX.5
    PORTB.3 = PORTX.6
    PORTB.4 = PORTX.7

end sub

sub procedure Read_Byte(Dim PORTX as Byte)

    TRISA.1 = 1                  ' Change to inputs
    TRISA.2 = 1
    TRISA.3 = 1
    TRISA.5 = 1
    TRISA.6 = 1
    TRISA.7 = 1
    TRISB.3 = 1
    TRISB.4 = 1

    PORTX.0 = PORTA.1       ' Build PORTX's data
    PORTX.1 = PORTA.2
    PORTX.2 = PORTA.3
    PORTX.3 = PORTA.5
    PORTX.4 = PORTA.6
    PORTX.5 = PORTA.7
    PORTX.6 = PORTB.3
    PORTX.7 = PORTB.4

end sub

Main:

      PORTX = 123             ' Put the value "123" into PORTX
      Write_Byte(PORTX)     ' Update all of the pins for PORTX

      Read_Byte(PORTX)     ' Read the contents of PORTX

      Write_Byte(234)        ' Write the value "234" to PORTX

      Goto Main
End.
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Old 29th March 2007, 07:38 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
Not very elegant but does the job.
Code:
	movfw	Byte
	andlw	b'11101110'
	movwf	PORTB
	btfss	Byte,0
	bcf	PORTA,3
	btfsc	Byte,0
	bsf	PORTA,3
	btfss	Byte,3
	bcf	PORTA,4
	btfsc	Byte,3
	bsf	PORTA,4
Mike
That is exactly my method of creating a virtual port for 4-bit LCD interfacing. Write to Virtual port and call VP_Update to automatically map individual bits of a byte or bytes to corresponding i/o channels. Either full port masking with mathmatical operators or simple BTFSS, it still elegant in my book. Its elegant because its Virtual

Last edited by donniedj; 29th March 2007 at 07:40 AM.
donniedj is offline   Reply With Quote
Old 29th March 2007, 10:12 PM   (permalink)
Default

Code:
 
; W reg contains byte to output
   movwf    portA 
   andlw     0x11
   addlw     0x07
   movwf    portB    ; bit 4 -> i/o 4, bit 0 -> i/o 3
__________________
Pete
picprojects.org.uk

Last edited by geko; 29th March 2007 at 10:17 PM.
geko is offline   Reply With Quote
Old 30th March 2007, 01:01 AM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
I have available some I/O on two output ports (PIC)

RA 765x321x
RB xx543xxx

I want one byte of I/O (8 bits) it may be asynchronous.

Any suggestions, ideas?
I'm not sure I understand the question. Could you rephrase?
Mike, K8LH is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Question about HT 8870 in the TELESWITCH circuit !?! zambalik General Electronics Chat 11 6th September 2007 12:11 PM
VERY low voltage on output pins, please help! New2PIC Micro Controllers 1 18th January 2004 03:21 AM
Question about reading bits from ports. Blueteeth Micro Controllers 5 5th January 2004 01:08 PM
Op Amp Question (Need to amp DAC Output) iso9001 General Electronics Chat 1 10th December 2003 02:20 PM
How do I generate a potentiometer output? klick General Electronics Chat 3 23rd November 2003 02:26 PM



All times are GMT. The time now is 10:31 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.