Example 16 Circular Queue

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Advertisements

LCS Non-Dynamic Version int function lcs (x, y, i, j) begin if (i = 0) or (j = 0) return 0; else if (x[i] = y[j]) return lcs(x, y, i-1, j-1)+1; else return.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
Queues CS 308 – Data Structures. What is a queue? It is an ordered group of homogeneous items of elements. Queues have two ends: –Elements are added at.
A Circular Queue Data Structure Lecture L4.8. A Circular Queue empty Containing 2 values.
Queues CS 3358 – Data Structures. What is a queue? It is an ordered group of homogeneous items of elements. Queues have two ends: – Elements are added.
ARRAY BASED STACK DATED: 30 TH AUG 2012 CLASS - XII.
Example 11 Analog-to-Digital Converter Lecture L5.1.
C Language Programming. C has gradually replaced assembly language in many embedded applications. Data types –C has five basic data types: void, char,
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Reference: Vinu V Das, Principles of Data Structures using C and C++
The miniDragon+ Board and CodeWarrior Lecture L2.1.
Queues Chapter 3. Objectives Introduce the queue abstract data type. – Queue methods – FIFO structures Discuss inheritance in object oriented programming.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
Serial Communication Interface Ta Kim Nicholas Earnhart Razid Ahmad ME 6405 – Fall 2008 November 6, 2008.
Example 11 Analog-to-Digital Converter Lecture L5.1.
Example 12 Pulse-Width Modulation (PWM): Motors and Servos Lecture L8.1.
Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle.
Programming Microcontrollers in C Lecture L7.1. C Data Types TypeSizeRange char1 byte-128 – 127 unsigned char1 byte0 – 255 Int2 bytes – unsigned.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Study 1 Purpose of the tool. Test architecture.. Testing Target system Test system Testing results results affecting.
Examples Lecture L2.2. // Example 1a: Turn on every other segment on 7-seg display #include /* common defines and macros */ #include /* derivative.
Vishwakarma government engineering college Prepare by. Hardik Jolapara( ) LCD Interfacing with ATmega16.
INTERFACING KEYBOARD WITH ATMEGA32 ELECTRONICS & COMMUNICATION TITLE.
Mixing C and ASM Programs
What is a Queue? Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. In a queue data structure,
Popping Items Off a Stack Using a Function Lesson xx
Computing with C# and the .NET Framework
4-Integrating Peripherals in Embedded Systems (cont.)
Example 14 Real-time Interrupts
QUEUES.
Programming the I/O Hardware
4-Integrating Peripherals in Embedded Systems
Example 19 Measuring Pulse Widths Using Interrupts
4-Integrating Peripherals in Embedded Systems
Queue data structure.
Basic Data Structures – Continued (Queues)
Stack and Queue APURBO DATTA.
Example 10 ASCII String to Binary Conversion
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Pointers and Linked Lists
Queues.
Example 5 Pushbutton Switches: S1 and S2
Lecture 22.
Programming the I/O Hardware
Example 9 Binary to ASCII String Conversion
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Example 6 Hex Keypad Lecture L3.2.
Example 15 Interrupt-Driven Controller
Popping Items Off a Stack Lesson xx
Stack and Queues Stack implementation using Array
Example 13 The Serial Peripheral Interface (SPI)
Example 17 SCI Receive Interrupts
Example 7 Liquid Crystal Display
Today’s agenda Lab 1 Module 4: Process Management
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Teknik Informatika - Universitas Muhammadiyah Malang (UMM)
Example 18 Pulse Train Using Interrupts
C Programming Lecture-8 Pointers and Memory Management
Queues.
Queue.
Queues Dr. Anwar Ghani Lecture 06: Queue Data Structures
Presentation transcript:

Example 16 Circular Queue Lecture L7.2

A Circular Queue Empty Containing 2 values

Listing 16.2 Function prototypes (queue.h) // queue.h A character queue void initq(void); // initialize the queue void qstore(char); // store character in queue int qempty(void); // return 0 if queue is not empty char getq(void); // read character from queue

Listing 16.1 A character queue (queue.c) // queue.c A character queue #include "queue.h" // prototype definitions #define QMAX 16 // size of queue static char qbuff[QMAX]; // the queue static int front; static int rear; // queue pointers static int min = 0; // start of queue static int max = QMAX-1; // end of queue void initq(void){ min = 0; front = 0; rear = 0; max = QMAX-1; }

void qstore(char c){ rear++; // inc rear if(rear > max) rear = min; if(rear == front){ rear--; // queue is full if(rear < min) // rewind rear rear = max; }else qbuff[rear] = c; // store c at rear }

int qempty(void){ int flag; if(front == rear) flag = 1; else flag = 0; return (flag); }

char getq(void){ front++; // inc front if(front > max) front = 0; return qbuff[front]; // return value at front }

// Example 16: Example of using a queue #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "queue.h" #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" void main(void) { char* blanks; char c, a; blanks = " "; PLL_init(); // set system clock frequency to 24 MHz lcd_init(); // enable lcd initq(); // initialize the queue keypad_enable(); // enable keypad set_lcd_addr(0x00); // display on 1st line while(1) { c = getkey(); // read keypad a = hex2asc(c); // convert to ascii qstore(a); // and store in queue data8(a); // display on LCD wait_keyup(); // wait to release key switch(c){

case 0xE: // if enter (*) key set_lcd_addr(0x40); // display on 2nd line while(qempty() != 0){ // empty the queue data8(getq()); // and display on lcd } set_lcd_addr(0x00); // clear 1st line type_lcd(blanks); wait_keyup(); // wait to release key set_lcd_addr(0x00); // display on 1st line break; case 0xF: // if clear (#) key clear_lcd(); // clear lcd display default: