This preview shows page 1-2-3-18-19-36-37-38 out of 38 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 38 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

General-purpose I/OThe simplest type of I/O via the PIC24 µC external pins areThe simplest type of I/O via the PIC24 µC external pins are parallel I/O (PIO) ports.A PIC24 µC can have multiple PIO ports named PORTA, µpp ,PORTB, PORTC, PORTD, etc. Each is 16-bits, and the number of PIO pins depends on the particular PIC24 µC and package.The PIC24HJ32GP202/28 pin package has:The PIC24HJ32GP202/28 pin package has:PORTA – bits RA4 through RA0PORTB–bits RB15 through RB0PORTB bits RB15 through RB0These are generically referred to as PORTx.Each pin on these ports can either be an input or output –the pp ppdata direction is controlled by the corresponding bit in the TRISxregisters (‘1’ = input, ‘0’ = output).V 0.7 1The LATx register holds the last value written to PORTx.PORTB ExamplepSet the upper 8 bits of PORTB to outputs, lower 8 bits to be inputs:TRISB = 0x00FF;Drive RB15, RB13 high; others low:others low:PORTB = 0xA000;Test returns true while RB0=0 Wait until input RB0 is high:while ((PORTB & 0x0001) == 0);so loop exited when RB0=1while ((PORTB & 0x0001) == 0);Wait until input RB3 is low:Test returns true while RB3=1 so loop exited when RB3=0V 0.7 2while ((PORTB & 0x0008) == 1);PORTB Example (cont.)I di id l PORT bi d RB0 RB1 RA0Individual PORT bits are named as _RB0, _RB1, .._RA0, _ etc. so this can be used in C code.Wait until input RB2 is high:Test returns true while RB2=0 so loop exited when RB2=1. Clbiwhile (_RB2 == 0);Can also be written as:while (!_RB2);Wait until input RB3 is low:while (_RB3 == 1) ;Test returns true while RB3=1 so loop exited when RB3=0Can also be written as:Can also be written as:while (_RB3);V 0.7 3Aside: Tri-State Buffer (TSB) ReviewA tri-state buffer (TSB) has input, output, and output-enable (OE) pins. Output can either be ‘1’, ‘0’ or ‘Z’ (high impedance).(high impedance). AYYAOEOE = 0, then switch closed OE = 1, then switch openOEV 0.7 4Bi-directional, Half-duplex CommunicationdriverdriverPIC24 µC QDTRISQDTRISPIC24 µC 01driver enableddriver disabledQDQDdata busQDQDdata bus01DQrd_portDQrd_portPIC24 CPIC24 Cdriver driver PIC24 µC QDTRISdata busQDTRISdata busPIC24 µC 10disabledenabledQDQDdata busQDQDdata bus1V 0.7 5rd_port rd_portPORTx Pin DiagramExternal pin shared withother on-chip modulesTRIS bit controls tristate control ontristate control on output driver Reading LATxreads lastReading LATxreads lastvalue written; readingPORTx reads the actualiV 0.7 6pinLATx versus PORTxWriting LATx is the same as writing PORTx, both writes go to the latch.Reading LATx reads the latch output (last value written), while reading PORTx reads the actual pin value. PIC24 µCConfigure RB3 as an open-drain output, then write a ‘1’ to it.RB3The physical pin is tied to ground, so it can never go high.Reading _RB3 returns a ‘0’, but reading _LATB3 returns a ‘1’ (the last value written).V 0.7 7sv uew e).LATx versus PORTx (cont)_LATB0 = 1;LATB0 = 0;Compilerbset LATB,#0bclr LATB,#0_LATB0 = 0;,#bitset/bitclr instructions are read/modify/write, in this case, read LATB modify contents write LATB This works as expectedLATB, modify contents, write LATB. This works as expected._RB0 = 0;Compilerbclr PORTB,#0_RB0 = 1;bset PORTB,#0bset/bclr instructions are read/modify/write –in this case, read yPORTB, modify its contents, then write PORTB. Because of pin loading and fast internal clock speeds, the second bset may not work correctly! (see datasheet explanation) For this reasonV 0.7 8not work correctly! (see datasheet explanation). For this reason, our examples use LATx when writing to a pin.Switch InputVddPIC24 µCRB310KExternal pullupWhen switch is pressed W e sw c s p essedRB3 reads as ‘0’, else reads as ‘1’.If pullup not present, then PIC24 µCdon’tdoinput would float when switch is not pressed, and input value may read as PIC24 µCRB3don t do this!py‘0’ or ‘1’ because of system noise.V 0.7 9Internal Weak PullupsEliihCNif i h ki lExternal pins with a CNypin function have a weak internal pullup that can be enabled or disabled.Change notification input; to gp;enable pullup:CN11PUE = 1;To disable pullup:To disable pullup:CN11PUE = 0;V 0.7 10Schmitt Trigger Input BufferEach PIO input has aSchmitttrigger input buffer; thisEach PIO input has a Schmitttrigger input buffer; this transforms slowly rising/falling input transitions into sharp rising/falling transitions internally.V 0.7 11PORTx Shared Pin FunctionsExternal pins are shared with other on-chip modules. Just setting _TRISx = 1 may be not be enough to configure a PORTxpin as an input depending on what other modules sharePORTxpin as an input, depending on what other modules share the pin: RB15 shared with AN9, which is an analog input to the on-chip gppAnalog-to-Digital Converter (ADC). Must disable analog functionality!functionality!_PCFG9 = 1;TRISB15 = 1;Disables analog functionConfigure as input_TRISB15 = 1;Configure as input_PCFG9 = 1;Disables analog functionV 0.7 12_TRISB15 = 0;Configure as outputAnalog/Digital Pin versus Digital-only PinPins with shared analog/digital functions have a maximum input voltage of Vdd + 0 3 V so 3 6 Vvoltage of Vdd + 0.3 V, so 3.6 VPins with no analog functions ( “digital-only” pins) are 5 V tolerant, their maximum input voltage is 5.6 V.,pgThis is handy for receiving digital inputs from 5V parts.Most PIO pins can only source or sink a maximum 4 mA YouMost PIO pins can only source or sink a maximum 4 mA. You may damage the output pin if you tie a load that tries to sink/source more than this current.V 0.7 13Open Drain OutputsSome PIO pins can be configured as anopen drainoutputSome PIO pins can be configured as an open drain output, which means the pullup transistor is disabled. ODCxy= 1 enables open drain ODCxy= 0 disables open drain_ODCxy= 1 enables open drain, _ODCxy= 0 disables open drain _ODCB15 = 1;Enables open drain on RB15V 0.7 14Recall that RB15 port used to drive heartbeat/Power LED, configured as ,gopen drainLED is off if LATB15 = 0V 0.7 15Recall that RB15 port used to drive heartbeat/Power LED, configured as ,gopen drainLED is on if LATB15 = 1V 0.7 16Driving LEDs : port configured as a normal CMOS driverRB15/open drain configuration for heartbeat LED is a special case.V 0.7 17Port Configuration MacrosFor convenience, we supply macros/inline functions that hide pin configuration details:CONFIG_RB15_AS_DIG_OUTPUT();CONFIG_RB15_AS_DIG_INPUT();These macros are supplied for each port pin. Because these functions


View Full Document

MSU ECE 3724 - General purpose IO

Documents in this Course
Timers

Timers

38 pages

TEST 4

TEST 4

9 pages

Flags

Flags

6 pages

Timers

Timers

6 pages

Timers

Timers

54 pages

TEST2

TEST2

8 pages

Load more
Download General purpose IO
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view General purpose IO and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view General purpose IO 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?