C Programming Interfacing C to Hardware. 68040 LCD Interface Code /* define X and Y PIT registers on bus slot D */ #define PIT0xFFF58300 #define XPGCR(*

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

INPUT-OUTPUT ORGANIZATION
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
PROGRAMMABLE PERIPHERAL INTERFACE -8255
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
MICROPROCESSORS TWO TYPES OF MODELS ARE USED :  PROGRAMMER’S MODEL :- THIS MODEL SHOWS FEATURES, SUCH AS INTERNAL REGISTERS, ADDRESS,DATA & CONTROL BUSES.
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati.
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
CSS 372 Oct 2 nd - Lecture 2 Review of CSS 371: Simple Computer Architecture Chapter 3 – Connecting Computer Components with Buses Typical Bus Structure.
AVR Programming CS-212 Dick Steflik. ATmega328P I/O for our labs To get data into and out of our Arduino its a little trickier than using printf and.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
Computer Science 1620 C++ - Basics. #include using namespace std; int main() { return 0; } A very basic C++ Program. When writing your first programs,
C Programming for Embedded Systems. fig_06_00 Computer Layers Low-level hardware to high-level software (4GL: “domain-specific”, report-driven, e.g.)
Unit-5 CO-MPI autonomous
NS Training Hardware. System Controller Module.
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
INPUT-OUTPUT ORGANIZATION
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Introduction to Embedded Systems Buffering and DMA (Direct Memory Access) Lecture 11.
Dr. Rabie A. Ramadan Al-Azhar University Lecture 6
Machine Instruction Characteristics
Spring EE 437 Lillevik 437s06-l8 University of Portland School of Engineering Advanced Computer Architecture Lecture 8 Project 3: memory agent Programmed.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Variables and Objects, pointers and addresses: Chapter 3, Slide 1 variables and data objects are data containers with names the value of the variable is.
1-1 NET+OS Software Group Flash API Multiple flash memory bank support New Flash API introduction Detailed Flash API Function presentation Supporting.
Chapter 2: Computer-System Structures 2.1 Computer System Operation 2.5 Hardware Protection 2.6 Network Structure.
UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.
Renesas Technology America, Inc. Flash!. CPU Rewrite CPU-rewrite is a term that refers to an Renesas MCU’s ability to erase/program its own internal Flash.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Programming the I/O Hardware Reference: –textbook: Tanenbaum ch.5.1 – s.htmlwww.cs.umb.edu/ulab/UsingCforHardwareReg.
Modes of transfer in computer
Computer Hardware A computer is made of internal components Central Processor Unit Internal External and external components.
6-1 Infineon 167 Interrupts The C167CS provides 56 separate interrupt sources that may be assigned to 16 priority levels. The C167CS uses a vectored interrupt.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
LHO 22 C and the  The Silicon Labs ISE uses the Keil C51 compiler.  The code size is limiter to 2K  C has replaced PL/M (the original Intel high.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Processor Memory Processor-memory bus I/O Device Bus Adapter I/O Device I/O Device Bus Adapter I/O Device I/O Device Expansion bus I/O Bus.
UNIT 7 - INTRODUCTION TO I/O INTERFACING. TWO MAJOR TYPES OF I/O INTERFACING ISOLATED I/O - DEDICATED I/O INSTRUCTIONS ARE USED TO ACCESS I/O DEVICES.
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
Structure and Role of a Processor
8255:Programmable Peripheral Interface
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Embedded Systems Lecture 4 January 20, 2016.
ARM Embedded Programming Lecture 4 Accessing Memory Mapped Registers.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
80C51 Block Diagram ECE Overview.
CS501 Advanced Computer Architecture
8086 Microprocessor.
Register Use Policy Conventions
The Hardware Interface
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
פרטים נוספים בסילבוס של הקורס
8051 Micro Controller.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Computer Architecture Assembly Language
INSTRUCTION SET DESIGN
Presentation transcript:

C Programming Interfacing C to Hardware

68040 LCD Interface Code /* define X and Y PIT registers on bus slot D */ #define PIT0xFFF58300 #define XPGCR(* (volatile char *) (PIT+0x01)) #define XPADDR(* (volatile char *) (PIT+0x05)) #define XPBDDR(* (volatile char *) (PIT+0x07)) #define XPACR(* (volatile char *) (PIT+0x0D)) #define XPBCR(* (volatile char *) (PIT+0x0F)) #define XTCR(* (volatile char *) (PIT+0x21)) #define XTIVR(* (volatile char *) (PIT+0x23)) #define XCPRH(* (volatile char *) (PIT+0x27)) #define XCPRM(* (volatile char *) (PIT+0x29)) #define XCPRL(* (volatile char *) (PIT+0x2B)) #define XTSR(* (volatile char *) (PIT+0x35)) #define XPORTA(* (volatile char *) (PIT+0x11)) #define XPORTB(* (volatile char *) (PIT+0x13)) #define YPGCR(* (volatile char *) (PIT+0x41)) #define YPADDR(* (volatile char *) (PIT+0x45)) #define YPACR(* (volatile char *) (PIT+0x4D)) #define YPORTA(* (volatile char *) (PIT+0x51))

LCD Delay Code /* define time delay */ #define DTIME0xFF /* Time delay */ void delay(t) int t; { register int i; for (i = t; i > 0; i--) {;} }

Delay Code Analysis zTime delay y25 MHz => 40 ns clock cycle y1-2 clock cycles/instruction yLoop of 2 instructions => ns/loop y256 iterations => us delay zUse timer interrupt instead? yNot for short delays xinterrupt latency ~10 us, context switch ~1 ms yReally want handshaking, big I/O buffer

LCD Write Routines void lcd_controlwrite(c) char c; { XPORTB = c; /* c on data lines */ XPORTA = 0x01; /* Enable clock high, write control reg */ delay(DTIME); XPORTA = 0x00; /* Enable clock low */ delay(DTIME); } void lcd_datawrite(c) char c; { XPORTB = c; /* c on data lines */ XPORTA = 0x03; /* E clock high, write data reg */ delay(DTIME); XPORTA = 0x02; /* negate E clock */ delay(DTIME); }

Write Routine Analysis zMust obey setup and hold times in timing specification zConstant delay reduces performance yNot really an issue for application yBut ties up CPU cycles zAlternative yOne write routine, specify data or control in argument ylcd_write(c,reg)

LCD Write Timing Diagram

Initial PIT Port void xport_init(void) { XPGCR = 0x00; /* Mode 0, disable H12/H34, H1-4 active low */ XPADDR = 0xFF; /* XPORTA direction is output */ XPBDDR = 0xFF; /* XPORTB direction is output */ XPACR = 0xF0; /* Submode 1X, H2 negated, no interrupt */ XPBCR = 0xF0; /* Submode 1X, H2 negated, no interrupt */ }

LCD Initialization void lcd_init(void) { XPORTA = 0x00; /* Set LCD enable low */ lcd_controlwrite(0x01); /* clear display */ delay(DTIME); /* extra delay for clear */ lcd_controlwrite(0x38); /* func set, 8 bits, 1 line, 5x7 */; lcd_controlwrite(0x06); /* entry mode, inc cursor, shift */ lcd_controlwrite(0x0F); /* display on, cursor on, blink on */ }

Initialization Analysis zNicer interface ideas yDefine constants instead of bit vectors xOne for each command field xCombine together in initialization routine yPass as flags to initialization routine

Home and Write /* home display */ void lcd_home(void) { lcd_controlwrite(0x02); } /* Write text string to LCD */ void writestring(s) char *s; { while (*s != '\0') { lcd_datawrite(*s++); }

Analysis zCould have home as argument to a command write rather than separate function zChar is 8 bits, so should be able to write non-ASCII characters yLCD can do other character sets

Main Routine /* Initialize the X Port, initialize the LCD, write * "HELLO!!!!!!", home cursor */ * Note only first 6 characters print, so "HELLO!!!” * * Note main is type int as required by compiler */ int main(void) { xport_init(); lcd_init(); writestring("HELLO!!!!!!"); lcd_home(); }

Summary zCan easily write modular LCD interface yPort initialization yLCD initialization yData interface yCommand interface

Attention to Data Types zUser must specify data types zE.g. must use 8-bit data with 8-bit device zTypes yshort int, int, long int - signed 8, 16, 32 bits xlength depends on architecture and compiler ychar, unsigned it, - unsigned 8, 16 bits yfloat, double - floating point 32, 64 bits

Access Types zVolatile yTells compiler that data should not be kept in register, e.g. LCD status register zNormally not an issue if appropriate define statements are used, so variable access always causes memory access y#define STAT (volatile char *) 0xFFFF0000 yY = *STAT;

Pointers vs. Values zUse I/O register addresses as pointers y#define STAT (volatile char *) 0xFFFF0000 ySTAT points to byte at 0xFFFF0000 zRead/write by dereferencing pointer yY = *STAT; y*STAT = Y;

Indirect Addressing #define STAT (volatile char *) 0xFFFF0000 register char *sptr; /* address register */ sptr = STAT; Y = *sptr; /* indirect addressing */ Sptr++; /* increment to next byte */

I/O Device in Structure struct IO_dev { char funct; /* function code */ char *control; /* control reg addr */ char *readdata; /* data reg addr */ char input_char; /* input destination */ char error_stat; /* error destiation */ } zStructure offsets overlay I/O register locations

ACIA Example int main(void) { register char input; struct IO_dev ACIA; struct IO_dev *PA = &ACIA; PA->control = (char *) 0x8000; PA->readdata = (char *) 0x8002; PA->function = 1; Get_data(PA); input = PA->input_char; }

Analysis zStructure is allocated in memory by compiler zInitialization sets field values to point to I/O register locations zAdvantage yCan easily handle several of same type of I/O device in system