Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fri. Sept 29 Announcements

Similar presentations


Presentation on theme: "Fri. Sept 29 Announcements"— Presentation transcript:

1 Fri. Sept 29 Announcements
HW/Lab 6 posted yesterday Lab 6 has been up (unchanged since the class began) Quiz on Module 2 (A+B) Monday Have video lectures almost done, will edit and post today

2 General-Purpose I/O Ports
Module 2.C General-Purpose I/O Ports Tim Rogers 2017

3 Learning Outcome #2 Bus Timing Analysis
“An ability to interface a microcontroller to various devices” Bus Timing Analysis 9S12C Multiplexed Bus Expansion General-Purpose I/O Ports Interrupt Handling Buffered I/O Buffered, Interrupt-Driven Printer Design Example How?

4 Complex interfaces are useful but…
Objective “General Purpose I/O Ports” Why? 1 Complex interfaces are useful but… Sometimes, you just want to read/write 0’s and 1’s manually from software.

5 Overview Hardware Software How ports are initialize/used
Basic Port Structure PIM Block user guide: Software Write a simple driver for a printer, driven by GPIO (General-Purpose I/O)

6 Hardware Overview Ports on the 9S12 (some ports padded out to pins, some not) By default – they are used for GPIO Ports can also be used by other modules (peripherals) – we set configuration bits to make this happen. Can only be configured for either GPIO or the module (for example port E from lab 5). All this IO is digital I/O (meaning you can only read/write a 0 or a 1 on each bit).

7 Hardware Port Integration Module (PIM)
PT0 + PT1: Connected to LEDs PAD6 + PAD7: Connected to pushbuttons Port P: Not padded out on your micro Ports A and B: Not padded out on your micro For 362, use PAD0-7, PT0-7 and PE0 + PE1 for GPIO. (as long as you aren’t using them for their other purpose)

8 Read or write the actual value from here.
How to setup GPIO If DDRT (Port T’s DDR) is b. Will the CPU be able to write the value 70h to PTT (Port T’s GPIO value register)? A: Yes B: No C: Sort of… D: What? If DDRT (Port T’s DDR) is b. Will the CPU be able to write the value 70h to PTT (Port T’s GPIO value register? A: Yes B: No C: Sort of…  D: What? If DDRT (Port T’s DDR) is b. Will the CPU be able to write to PTT (Port T’s GPIO value register)? A: Yes B: No C: Sort of… D: What? If DDRT (Port T’s DDR) is b. Will the CPU be able to write to PTT (Port T’s GPIO value register)? A: Yes B: No C: Sort of… D: What? Need to tell it to be input or output “Data Direction Register” (DDR) specifies this. There is one of these for each port DDR Register (8-bits) Port Value Register (8-bits) DDR 7-0: 0 means port is an input 1 means port is an output PT 7-0: Read or write the actual value from here.

9 Also a “reduced drive” register
RDR Register (8-bits) RDR 7-0: 0 means output “full drive” 1 means output “reduced drive” Reduced drive decreases power consumption and helps cut down on electromagnetic interference.

10 Pull Enable Bit / Polarity Select
If the pin is an input, you can specify if the 9s12 pulls the pin up or down or lets it float. PE Register (8-bits) PS Register (8-bits) PE 7-0: 0 means pin float if undriven 1 means pin will be pull – look at PS to decide up or down PS 7-0: 0 means pin be pull-up device 1 means pin will be pull-down device

11 Block Diagram of Pin Functionality
port input data (read) dual-rank input synchronizer port output data (write) external pin data direction register Note: If module/peripheral is enabled, it “takes over” the associated port pin(s) module/peripheral associated with port pin

12 Port timing Port data setup time = 120 ns hold time = 0 ns
Port READ Timing Port write delay time = 40 ns Port Write Timing

13 Printer Interface Example
Algorithm: Handshaking signals and communication protocols HW: Interface circuit and register initializations SW: Program-driven I/O device driver Analysis: Examination of timing for a printer

14 Handshaking and Communication Protocol
In general, the maximum transfer rate of which an I/O device is capable does not match the maximum transfer rate of which the CPU is capable Communication (or synchronization) between an I/O device and CPU is therefore required for reliable data transfer, using handshaking signals signal from computer to I/O Device: DATA AVAILABLE or STROBE signal from I/O device to computer: BUSY or READY

15 Handshaking and Communication Protocol
The sequence in which these signals are asserted and negated with respect to the data transfer is referred to as the communication protocol Example: Handshaking signals and communication protocol for a generic (parallel port) printer STROBE: “I have the next ASCII character available for you to print” BUSY: “I’m currently printing the previous character you sent me (or something ‘bad’ has happened), so please don’t send me any more right now”

16 Handshaking and Communication Protocol
Data Printer STROBE BUSY

17 Handshaking and Communication Protocol
STROBE 1 BUSY Previous Character DATA STEP 1: Check to see if the printer is busy

18 Handshaking and Communication Protocol
STROBE 1 BUSY 2 Previous Character Next Character DATA STEP 2: Send data to printer

19 Handshaking and Communication Protocol
3 STROBE 1 BUSY 2 Previous Character Next Character DATA STEP 3: CPU asserts STROBE signal

20 Handshaking and Communication Protocol
3 4 STROBE 1 BUSY 2 Previous Character Next Character DATA STEP 4: Printer asserts BUSY while printing

21 Handshaking and Communication Protocol
3 4 STROBE 1 5 BUSY 2 Previous Character Next Character DATA STEP 5: Printer negates BUSY when print cycle is complete

22 Printer Port Timing

23 Printer-Microcontroller Interface
…where Port X and Port Y are any available port pins Port X (bits 0-7) Printer STROBE (Port Y, bit 1) BUSY (Port Y, bit 0)

24 Register Initializations

25 Register Initializations

26 Register Initializations

27 Register Initializations

28 Register Initializations

29 Program-Driven I/O

30 Program-Driven I/O read device status

31 Program-Driven I/O read device status is device ready?

32 Program-Driven I/O read device status is device ready? no

33 Program-Driven I/O read device status is device ready? no yes
transfer data

34 Program-Driven Device Driver
A device driver is a low-level routine that transfers data to/from an I/O device and generates any handshaking protocol required The printer device driver pchar functions as follows: checks printer status and waits if the printer is busy transfers the character passed in the A register to the printer strobes the printer

35 Printer Initialization Routine
bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pinit

36 Printer Initialization Routine
bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pinit movb #$FF,ddrx

37 Printer Initialization Routine
bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pinit movb #$FF,ddrx movb #$02,ddry

38 Printer Initialization Routine
bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pinit movb #$FF,ddrx movb #$02,ddry bset porty,smask rts

39 Assume character to print in (A)
Printer Device Driver bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pchar pshc pwait staa portx pulc rts Assume character to print in (A)

40 Spin loop, waits until busy is set.
Printer Device Driver bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pchar pshc pwait brset porty,bmask,pwait staa portx pulc rts Spin loop, waits until busy is set.

41 Printer Device Driver bmask equ $01 ; BUSY bit mask
smask equ $ ; STROBE mask pchar pshc pwait brset porty,bmask,pwait staa portx bclr porty,smask ; 4 cycles pulc rts Sets Strobe Low

42 Sets strobe back to high
Printer Device Driver bmask equ $ ; BUSY bit mask smask equ $ ; STROBE mask pchar pshc pwait brset porty,bmask,pwait staa portx bclr porty,smask ; 4 cycles bset porty,smask ; 4 cycles pulc rts Sets strobe back to high

43 Printer Port Timing Analysis
Assume 8 MHz Bus Clock  125 ns/cycle STROBE duration = 4 cycles X 125 ns/cycle = 500 ns STROBE asserted 4 cycles X 125 ns/cycle = 500 ns following STAA


Download ppt "Fri. Sept 29 Announcements"

Similar presentations


Ads by Google