![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
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? Last edited by blueroomelectronics; 29th March 2007 at 12:33 AM. |
|
|
|
|
|
|
(permalink) |
|
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. |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) |
|
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 |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Last edited by donniedj; 29th March 2007 at 07:40 AM. |
||
|
|
|
|
|
(permalink) |
|
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 Last edited by geko; 29th March 2007 at 10:17 PM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
|
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |