// ParallelPrinter.c // Runs on LM3S811 // Use a handshaked interface to request a character print while // outputting a parallel character and wait for a rising edge signaling // completion. // Daniel Valvano // June 16, 2011 /* This example accompanies the book "Embedded Systems: Real Time Interfacing to the Arm Cortex M3", ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2011 Program 4.8, Example 4.3, Figure 4.33, Section 4.8 Copyright 2011 by Jonathan W. Valvano, valvano@mail.utexas.edu You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ // "ready" signal connected to PC4 (rising edge means print complete) // "start" signal connected to PC5 (rising edge starts printing) // print character data bit 7 connected to PD7 // print character data bit 6 connected to PD6 // print character data bit 5 connected to PD5 // print character data bit 4 connected to PD4 // print character data bit 3 connected to PD3 // print character data bit 2 connected to PD2 // print character data bit 1 connected to PD1 // print character data bit 0 connected to PD0 #define GPIO_PORTC_DATA_R (*((volatile unsigned long *)0x400063FC)) #define GPIO_PORTC_DIR_R (*((volatile unsigned long *)0x40006400)) #define GPIO_PORTC_IEV_R (*((volatile unsigned long *)0x4000640C)) #define GPIO_PORTC_RIS_R (*((volatile unsigned long *)0x40006414)) #define GPIO_PORTC_ICR_R (*((volatile unsigned long *)0x4000641C)) #define GPIO_PORTC_DEN_R (*((volatile unsigned long *)0x4000651C)) #define GPIO_PORTC5 (*((volatile unsigned long *)0x40006080)) #define GPIO_PORTD_DATA_R (*((volatile unsigned long *)0x400073FC)) #define GPIO_PORTD_DIR_R (*((volatile unsigned long *)0x40007400)) #define GPIO_PORTD_DEN_R (*((volatile unsigned long *)0x4000751C)) #define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108)) #define SYSCTL_RCGC2_GPIOD 0x00000008 // port D Clock Gating Control #define SYSCTL_RCGC2_GPIOC 0x00000004 // port C Clock Gating Control void Printer_Init(void){ volatile unsigned long delay; // activate port C and port D SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOC+SYSCTL_RCGC2_GPIOD; delay = SYSCTL_RCGC2_R; // allow time to finish activating GPIO_PORTC5 = 0x20; // Start=1 // GPIO_PORTC_DATA_R |= 0x20;// Start=1 GPIO_PORTC_DIR_R |= 0x20; // PC5=Start out GPIO_PORTC_DIR_R &= ~0x10;// PC4=Ready in GPIO_PORTC_DEN_R |= 0x30; // enable digital I/O on PC5-4 GPIO_PORTD_DIR_R |= 0xFF; // make PD7-0 out (PD7-0 data) GPIO_PORTD_DEN_R |= 0xFF; // enable digital I/O on PD7-0 GPIO_PORTC_IEV_R |= 0x10; // rise on PC4 GPIO_PORTC_ICR_R = 0x10; // clear flag4 } void Printer_Out(unsigned char data){ GPIO_PORTC_ICR_R = 0x10; // clear flag4 GPIO_PORTD_DATA_R &= ~0xFF; GPIO_PORTD_DATA_R += data&0xFF; // write data GPIO_PORTC5 = 0x00; // Start=0 // GPIO_PORTC_DATA_R &= ~0x20; // Start=0 GPIO_PORTC5 = 0x20; // Start=1 // GPIO_PORTC_DATA_R |= 0x20; // Start=1 while((GPIO_PORTC_RIS_R&0x10)==0);// wait } //debug code int main(void){ Printer_Init(); // initialize ports while(1){ Printer_Out('T'); // 'T' = 0x54 Printer_Out('e'); // 'e' = 0x65 Printer_Out('s'); // 's' = 0x73 Printer_Out('t'); // 't' = 0x74 } }