/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */

Similar documents
Team 8: Robert Blake Craig Goliber Alanna Ocampo

BME 4900 Page 1 of 2. Meeting 2: Personal Progress Report 12/2/09 Team 12 with Drew Seils. Semester One Week Two

Speed Control of a DC Motor using Digital Control

Timer0..Timer3. Interrupt Description Input Conditions Enable Flag

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

LCD. Configuration and Programming

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Analog Output with a Digital to Analog Converter

Binary Outputs and Timing

ECE Homework #10

Flow Charts and Assembler Programs

Interrupts on PIC18F252 Part 2

Timer1 Capture Mode:

Embedded System Design

More Fun with Timer Interrupts

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

Q1 Q2 Q3 Q4 Q5 Q6 Total /7.5 /5 /10 /5 /7.5 /5 /40

Human Response Timer

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

Embedded Systems Programming and Architectures

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

Lecture (09) PIC16F84A LCD interface LCD. Dr. Ahmed M. ElShafee

Lecture (04) PIC 16F84A programming I

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Microcontroller Overview

LCDs. Embedded Systems Interfacing. 20 September 2011

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

EE 361L Digital Systems and Computer Design Laboratory

Input/Output Ports and Interfacing

NOTICE: 1, the timing for Start, Stop, ACK, NACK, write and read is same as I2C

Accurate Time and Interrupts

unsigned char ReadADC() { /************* start A/D, read from an A/D channel *****************/ unsigned char ADC_VALUE;

Laboratory 10. Programming a PIC Microcontroller - Part II

Chapter 11: Interrupt On Change

ELCT 912: Advanced Embedded Systems

Interrupts. Embedded Systems Interfacing. 08 September 2011

Chapter 13. PIC Family Microcontroller

Using Timers of Microchip PIC18F Microcontrollers

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Capture Mode of Pic18F252

Lecture (03) PIC16F84 (2)

Remote Controlled KitchenAid Mixer for the Clients at ADEC. Appendices. Arnaud Bacye Karina Dubé Justin Erman Matthew Martin

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

Example of Asyncronous Serial Comms on a PIC16F877

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

UNCA CSCI 255 Exam 3 Fall 2011

SquareWear Programming Reference 1.0 Oct 10, 2012

Interrupt vectors for the 68HC912B32. The interrupt vectors for the MC9S12DP256 are located in memory from 0xFF80 to 0xFFFF.

The MCU s Pulse. Internal clock or oscillator to synchronize operation. One clock cycle = 1 TOSC = 1/fOSC. t TOSC

EXPERIMENT NO. 01 CALCULATOR USING PIC16F877

Hong Kong Institute of Vocational Education Digital Electronics & Microcontroller. 8. Microcontroller

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

CREATING FIRST PROJECT in mikropascal PRO for PIC32

Tel: Fax:

ME 6405 Introduction to Mechatronics

Lab Report for Sensor Calibration using a PIC16F84 GROUP MEMBERS ALFRED MAZHINDU SIMBARASHE CHIWESHE

PIC Discussion By Eng. Tamar Jomaa

Laboratory Exercise 5 - Analog to Digital Conversion

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Appendix A: Rack Specification Sheet

Digital and Analogue Project Report

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

5. You project should be equipped with indicator (led) indicating the operating status (as possible)

Simon. Final Project Report December 11, 2009 E155. Julia Karl and Kirsten McAfee

Inverted Pendulum Microprocessor and FPGA Manual Sheldon Logan July 3, 2006

MCU: Interrupts and Timers. Ganesh Pitchiah

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

Experiment 9: Using HI-TECH C Compiler in MPLAB

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

Embedded Systems Module. 6EJ505. C Tutorial 3: using the ICD3 rev tjw

CHAPTER 1 - World of microcontrollers

BME 361 Biomeasurement Laboratory Demonstration Biomedical Engineering Program University of Rhode Island June 10, 2015

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING B.ENG (HONS) ELECTRICAL AND ELECTRONIC ENGINEERING EXAMINATION SEMESTER /2016

The University of Texas at Arlington Lecture 21_Review

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

Basic Embedded Software C Review Using MPLAB SIM. Loops. Embedded Systems Interfacing. 25 August 2011

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

dspic Interrupts The Interrupt Control and Staus Registers are :- ENG721-S2 Mixed Signal Processing : Hassan Parchizadeh Page 1

Super Awesome Multitasking Microcontroller Interface for Electromechanical Systems (S.A.M.M.I.E.S.) Pinball Table

C:\Users\cunningh\StaysOnPC\ME430 Downloads & Projects\exam2_problem1\problem1Cunningham.c

Contents. PIC Mini Data Sheets

The University of Texas at Arlington Lecture 5

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

ECE Homework #3

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

Laboratory Exercise 7 - Extended I/O & Parallel Processing

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

DRPIC166X IP Core. High Performance 8-bit RISC Microcontroller v. 2.17

Introduction to Microcontroller Apps for Amateur Radio Projects Using the HamStack Platform.

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

Transcription:

/*Algorithm: This code display a centrifuge with five variable speed RPM by increaseing */ /*the speed the cell which are less dense can float and the cell that are denser can sink*/ /*the user has five option of speed 1)100 RPM 2)200 RPM 3)300 RPM 4)500RPM 5)above 500RPM error */ /*In progress:temprature shouldn't exceed 50C if temprature exceeds it will stop it will be measured with a termostat */ /*In Progress: There is an on and off button which will allow the user to turn on and off the centrifuge*/ /*In Progress: There is an auto turn off like power saving mechanism if the user didn't use it for a certain period of time */ #include <stdlib.h> //standard include files #include <pic.h>//library files for microcontroller #include <htc.h>//detrmine which complier should be run #include<time.h>//add a time function library CONFIG(DUNPROT & PWRTDIS & XT & WDTDIS & BORDIS & LVPDIS); #ifndef_rcal_freq // Unless already defined assume 4MHz system frequency // Used to calibrate delay_us() and delay_ms() #define_rcal_freq 7372800 #endif #define PRESS_BUTTON RE2//Sets PRESS_BUTTON to the value of pin RE2 to turn on the Centrifuge #define PRESS_bUTTON RE1//Sets PRESS_BUTTON to the value of pin RE1 to leave the Centrifuge at auto control

#define TEMPERATURE RB1 //Sets TEMPERATURE to the value of RB1 to display the temprature #define BUTTON1 RB2 //Sets the BUTTON1 to the value of RB2 to set the speed #define BUTTON2 RB3 //Sets the BUTTON2 to the value of RB3 to set the speed #define BUTTON3 RB4 //Sets the BUTTON3 to the value of RB4 to set the speed #define BUTTON4 RB5 //Sets the BUTTON4 to the value of RB5 to set the speed #define BUTTON5 RB6 //Sets the BUTTON5 to the value of RB6 to set the speed void InitLCD(void); void DisplayC(unsigned char position, const char *str); void clear_display(void); int ChangeState, DispMode, resetlcd, advalue; //Declare the variablea //;;;;;;; LoopTime subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; //; //; This subroutine waits for Timer2 to complete its ten millisecond count //; sequence. void LoopTime(void) for (;;)

if ( TMR2IF ) // Check whether ten milliseconds are up TMR2IF=0; // Clear flag //;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; //; //; This subroutine performs all initializations of variables and registers. //; It is important to refer to the PIC datasheet to understand what is happening. void Initial(void) ADCON1 = 0b00000100; // Setup A/D converter and enable PORTE as digital I/O ADCS0 = 1; // Use A/D FOSC/8 TRISA = 0b00001011; // Set I/O for PORTA TRISB = 0b11100001; // Set I/O for PORTB TRISC = 0b10110111; // Set I/O for PORTC TRISD = 0b00000000; // Set I/O for PORTD TRISE = 0b00000100; // Set I/O for PORTE PR2 = 95; // Set up Timer2 for a looptime of 10 ms PORTD = 0; // Turn off LEDs T2CON = 0b01011111; // Finish set up of Timer2 DispMode = 0;

ChangeState = 0; resetlcd = 1; OPTION = 0b00000100;// Timer 0 prescale set 32:1 InitLCD(); // normally call just before setting up INTCON INTCON = 0b10000000; // Enable interrupts //;;;;;;; Mainline program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; void LCD() //This function uses the DisplayC function to write text to the LCD screen if(resetlcd) resetlcd = 0; clear_display(); //This function clears the LCD display //so it can accomodate new characters if(!dispmode) (0x80) DisplayC(0x80, "BLINK"); //This function writes "BLINK" starting at the top left of the screen DisplayC(0xC0, "PRESS ENTER"); //This writes "PRESS ENTER" starting at the bottom left of the screen (0xC0) PORTD = 0b11111111; //This line resets the LEDs for Blink

else if(dispmode==1) DisplayC(0x80, "A/D CONVERT"); DisplayC(0xC0, "TURN RP1"); void Blink() //This function blinks the 8 LEDs at half second intervals int i; PORTD ^= 0b11111111; //Toggles LEDs of PORTD on/off for(i=50;i>0;i--) //For loop calls the 10 ms LoopTime routine 50 times //this takes 500 ms to complete LoopTime(); void ShowAD() //This function displays the result of the A/D converter //by incrementing LEDs as the A/D number increases if(advalue<128) //It checks the value against a series of IF statements //chooses the appropriate level and sets the correct PORTD = 0b00000001; //number of pins high else if(advalue<128*2)

PORTD = 0b00000011; else if(advalue<128*3) PORTD = 0b00000111; else if(advalue<128*4) PORTD = 0b00001111; else if(advalue<128*5) PORTD = 0b00011111; else if(advalue<128*6) PORTD = 0b00111111; else if(advalue<128*7) PORTD = 0b01111111; else

PORTD = 0b11111111; int BUTTON1() //Choose BUTTON1 for the first speed ChangeState = 1 //ChangeStates remember that the button was pressed scanf("%d", &BUTTON1); switch case BUTTON1: DisplayC(0x80"RUNNING:SPEED 100RPM");//Displays "RUNNING SPEED 100RPM in top left corner for(i=100,i,i--) // runs the centrifuge for 100 loop LoopTime(); clear_display(); //clears the display once complete DisplayC(0x80, "Completed!!"); //inform the user the cycle is completed

if(changstate == 1) // resets the ChangeState for next Button to be Pressed ChangeState = 0; resetlcd = 1; if(dispmode == 1) //If the final state is currently in use the counter is reset to 0 DispMode = 0; else DispMode = DispMode++; break; int BUTTON2() //Choose BUTTON2 for the first speed ChangeState = 1 //ChangeStates remember that the button was pressed scanf("%d", &BUTTON2);

switch case BUTTON2: DisplayC(0x80"RUNNING:SPEED 200RPM");//Displays "RUNNING SPEED 200RPM in top left corner for(i=200,i,i--) // runs the centrifuge for 200 loop LoopTime(); clear_display(); //clears the display once complete DisplayC(0x80, "Completed!!"); //inform the user the cycle is completed if(changstate == 1) // resets the ChangeState for next Button to be Pressed ChangeState = 0; resetlcd = 1; if(dispmode == 1) //If the final state is currently in use the counter is reset to 0 DispMode = 0; else

DispMode = DispMode++; break; int BUTTON3() //Choose BUTTON3 for the first speed ChangeState = 1 //ChangeStates remember that the button was pressed scanf("%d", &BUTTON3); switch case BUTTON3: DisplayC(0x80"RUNNING:SPEED 300RPM");//Displays "RUNNING SPEED 300RPM" in top left corner for(i=300,i,i--) // runs the centrifuge for 300 loop LoopTime(); clear_display(); //clears the display once complete DisplayC(0x80, "Completed!!"); //inform the user the cycle is completed

if(changstate == 1) // resets the ChangeState for next Button to be Pressed ChangeState = 0; resetlcd = 1; if(dispmode == 1) //If the final state is currently in use the counter is reset to 0 DispMode = 0; else DispMode = DispMode++; break; int BUTTON4() //Choose BUTTON4 for the first speed ChangeState = 1 //ChangeStates remember that the button was pressed

scanf("%d", &BUTTON4); switch case BUTTON4: DisplayC(0x80"RUNNING:SPEED 500RPM");//Displays "RUNNING SPEED 500RPM" in top left corner for(i=500,i,i--) // runs the centrifuge for 500 loop LoopTime(); clear_display(); //clears the display once complete DisplayC(0x80, "COMPLETED!!"); //display "COMPLETED" and inform the user the cycle is completed if(changstate == 1) // resets the ChangeState for next Button to be Pressed ChangeState = 0; resetlcd = 1; if(dispmode == 1) //If the final state is currently in use the counter is reset to 0 DispMode = 0;

else DispMode = DispMode++; break; default: corner DisplayC(0X80"NUMBER EXCEEDS ERROR")//Displays"NUMBER EXCEEDS ERROR" in top left break; int main(void) //This is the main body of the program //All functions of the program start here and are called either by the endless FOR loop or a subsidiary. for(;;) Initial(); //This function initializes necessary registers TEMPURATURE(); //Calls a function to check the TEMPURATURE BUTTON1(); //Calls a function of BUTTON1

BUTTON2(); //Calls a function of BUTTON2 BUTTON3(); //Calls a function of BUTTON3 BUTTON4(); //Calls a function of BUTTON4 BUTTON5(); //Calls a function of BUTTON5 if(!dispmode) //If the Enter Button was in State 0 the functions //LCD and Blink will be called LCD(); Blink(); else //If the Enter Button was not in State 0 the LCD //ADConvert and ShowAD functions will be called LCD(); ADConvert(); ShowAD();